tty: vt: sanitize consw::con_putcs() parameters
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Mon, 22 Jan 2024 11:03:40 +0000 (12:03 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 28 Jan 2024 02:08:54 +0000 (18:08 -0800)
Similar to con_putc() in the previous patch:
* make the pointer to charattr a pointer to u16, and
* make x, y, and count unsigned as they are strictly non-negative.

And again, document that hook.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Tested-by: Helge Deller <deller@gmx.de> # parisc STI console
Link: https://lore.kernel.org/r/20240122110401.7289-27-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/video/console/dummycon.c
drivers/video/console/mdacon.c
drivers/video/console/newport_con.c
drivers/video/console/sticon.c
drivers/video/console/vgacon.c
drivers/video/fbdev/core/fbcon.c
include/linux/console.h

index 1874beed03259cce7273171402c454df60c0bfc7..188d9f3e201c45d91f7c13571ff88bb3640cd0b7 100644 (file)
@@ -59,10 +59,10 @@ static void dummycon_putc(struct vc_data *vc, u16 c, unsigned int y,
        raw_notifier_call_chain(&dummycon_output_nh, 0, NULL);
 }
 
-static void dummycon_putcs(struct vc_data *vc, const unsigned short *s,
-                          int count, int ypos, int xpos)
+static void dummycon_putcs(struct vc_data *vc, const u16 *s, unsigned int count,
+                          unsigned int ypos, unsigned int xpos)
 {
-       int i;
+       unsigned int i;
 
        if (!dummycon_putc_called) {
                /* Ignore erases */
@@ -87,8 +87,8 @@ static int dummycon_blank(struct vc_data *vc, int blank, int mode_switch)
 #else
 static void dummycon_putc(struct vc_data *vc, u16 c, unsigned int y,
                          unsigned int x) { }
-static void dummycon_putcs(struct vc_data *vc, const unsigned short *s,
-                          int count, int ypos, int xpos) { }
+static void dummycon_putcs(struct vc_data *vc, const u16 *s, unsigned int count,
+                          unsigned int ypos, unsigned int xpos) { }
 static int dummycon_blank(struct vc_data *vc, int blank, int mode_switch)
 {
        return 0;
index 01e779943c002100140c97fefb549a7660a622b4..b8822b615b2ff581092a25dc7548ce506c5793db 100644 (file)
@@ -427,8 +427,8 @@ static inline u16 *mda_addr(unsigned int x, unsigned int y)
        return mda_vram_base + y * mda_num_columns + x;
 }
 
-static void mdacon_putcs(struct vc_data *c, const unsigned short *s,
-                        int count, int y, int x)
+static void mdacon_putcs(struct vc_data *c, const u16 *s, unsigned int count,
+                        unsigned int y, unsigned int x)
 {
        u16 *dest = mda_addr(x, y);
 
index 9b5c0118873eec0d75a8d4847333c998b090a1fd..5e65ee0b7c077ede9711d5c414ea93a25d08c9eb 100644 (file)
@@ -396,12 +396,13 @@ static void newport_putc(struct vc_data *vc, u16 charattr, unsigned int ypos,
        RENDER(npregs, p);
 }
 
-static void newport_putcs(struct vc_data *vc, const unsigned short *s,
-                         int count, int ypos, int xpos)
+static void newport_putcs(struct vc_data *vc, const u16 *s,
+                         unsigned int count, unsigned int ypos,
+                         unsigned int xpos)
 {
-       int i;
-       int charattr;
        unsigned char *p;
+       unsigned int i;
+       u16 charattr;
 
        charattr = (scr_readw(s) >> 8) & 0xff;
 
index 2f87b5909d0d11b19899d42648a41571c8271860..906da1fde7c8172dc58919d66e8ae9ebf38f47c8 100644 (file)
@@ -71,8 +71,8 @@ static const char *sticon_startup(void)
     return "STI console";
 }
 
-static void sticon_putcs(struct vc_data *conp, const unsigned short *s,
-                        int count, int ypos, int xpos)
+static void sticon_putcs(struct vc_data *conp, const u16 *s, unsigned int count,
+                        unsigned int ypos, unsigned int xpos)
 {
     if (vga_is_gfx || console_blanked)
            return;
index 4beab11f87eb437b4933d5bfc5778d018976a1a2..aa0589085847a9a6c3cff9784dbac7c05138c7a7 100644 (file)
@@ -1193,8 +1193,8 @@ static bool vgacon_scroll(struct vc_data *c, unsigned int t, unsigned int b,
 
 static void vgacon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
                         unsigned int width) { }
-static void vgacon_putcs(struct vc_data *vc, const unsigned short *s,
-                        int count, int ypos, int xpos) { }
+static void vgacon_putcs(struct vc_data *vc, const u16 *s, unsigned int count,
+                        unsigned int ypos, unsigned int xpos) { }
 
 const struct consw vga_con = {
        .owner = THIS_MODULE,
index 38de0f8723aa05fe901c935e464b3eff323cdd4c..7a7b2ac0d7a9fabfb1a57626a83a26909b1c7d23 100644 (file)
@@ -1279,8 +1279,8 @@ static void fbcon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
        __fbcon_clear(vc, sy, sx, 1, width);
 }
 
-static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
-                       int count, int ypos, int xpos)
+static void fbcon_putcs(struct vc_data *vc, const u16 *s, unsigned int count,
+                       unsigned int ypos, unsigned int xpos)
 {
        struct fb_info *info = fbcon_info_from_console(vc->vc_num);
        struct fbcon_display *p = &fb_display[vc->vc_num];
index 92d57e5b30097625fe33011fd5968924d32ec039..82d55764a66f8a100d02bdb8aa9da129e67d2e17 100644 (file)
@@ -41,6 +41,7 @@ enum vc_intensity;
  * @con_clear:  erase @count characters at [@x, @y] on @vc. @count >= 1.
  * @con_putc:   emit one character with attributes @ca to [@x, @y] on @vc.
  *             (optional -- @con_putcs would be called instead)
+ * @con_putcs:  emit @count characters with attributes @s to [@x, @y] on @vc.
  * @con_scroll: move lines from @top to @bottom in direction @dir by @lines.
  *             Return true if no generic handling should be done.
  *             Invoked by csi_M and printing to the console.
@@ -57,8 +58,9 @@ struct consw {
                             unsigned int x, unsigned int count);
        void    (*con_putc)(struct vc_data *vc, u16 ca, unsigned int y,
                            unsigned int x);
-       void    (*con_putcs)(struct vc_data *vc, const unsigned short *s,
-                       int count, int ypos, int xpos);
+       void    (*con_putcs)(struct vc_data *vc, const u16 *s,
+                            unsigned int count, unsigned int ypos,
+                            unsigned int xpos);
        void    (*con_cursor)(struct vc_data *vc, int mode);
        bool    (*con_scroll)(struct vc_data *vc, unsigned int top,
                        unsigned int bottom, enum con_scroll dir,