Commit 559f01a0 authored by Jiri Slaby (SUSE)'s avatar Jiri Slaby (SUSE) Committed by Greg Kroah-Hartman

tty: vt: sanitize arguments of consw::con_clear()

In consw::con_clear():
* Height is always 1, so drop it.
* Offsets and width are always unsigned values, so re-type them as such.

This needs a new __fbcon_clear() in the fbcon code to still handle
height which might not be 1 when called internally.

Note that tests for negative count/width are left in place -- they are
taken care of in the next patches.

And document the hook.
Signed-off-by: default avatar"Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Cc: Helge Deller <deller@gmx.de>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: linux-fbdev@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Cc: linux-parisc@vger.kernel.org
Tested-by: Helge Deller <deller@gmx.de> # parisc STI console
Link: https://lore.kernel.org/r/20240122110401.7289-22-jirislaby@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent dae3e6b6
...@@ -1585,7 +1585,7 @@ static void csi_X(struct vc_data *vc) ...@@ -1585,7 +1585,7 @@ static void csi_X(struct vc_data *vc)
vc_uniscr_clear_line(vc, vc->state.x, count); vc_uniscr_clear_line(vc, vc->state.x, count);
scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count); scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count);
if (con_should_update(vc)) if (con_should_update(vc))
vc->vc_sw->con_clear(vc, vc->state.y, vc->state.x, 1, count); vc->vc_sw->con_clear(vc, vc->state.y, vc->state.x, count);
vc->vc_need_wrap = 0; vc->vc_need_wrap = 0;
} }
......
...@@ -109,8 +109,8 @@ static void dummycon_init(struct vc_data *vc, bool init) ...@@ -109,8 +109,8 @@ static void dummycon_init(struct vc_data *vc, bool init)
} }
static void dummycon_deinit(struct vc_data *vc) { } static void dummycon_deinit(struct vc_data *vc) { }
static void dummycon_clear(struct vc_data *vc, int sy, int sx, int height, static void dummycon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
int width) { } unsigned int width) { }
static void dummycon_cursor(struct vc_data *vc, int mode) { } static void dummycon_cursor(struct vc_data *vc, int mode) { }
static bool dummycon_scroll(struct vc_data *vc, unsigned int top, static bool dummycon_scroll(struct vc_data *vc, unsigned int top,
......
...@@ -442,23 +442,18 @@ static void mdacon_putcs(struct vc_data *c, const unsigned short *s, ...@@ -442,23 +442,18 @@ static void mdacon_putcs(struct vc_data *c, const unsigned short *s,
} }
} }
static void mdacon_clear(struct vc_data *c, int y, int x, static void mdacon_clear(struct vc_data *c, unsigned int y, unsigned int x,
int height, int width) unsigned int width)
{ {
u16 *dest = mda_addr(x, y); u16 *dest = mda_addr(x, y);
u16 eattr = mda_convert_attr(c->vc_video_erase_char); u16 eattr = mda_convert_attr(c->vc_video_erase_char);
if (width <= 0 || height <= 0) if (width <= 0)
return; return;
if (x==0 && width==mda_num_columns) { scr_memsetw(dest, eattr, width * 2);
scr_memsetw(dest, eattr, height*width*2);
} else {
for (; height > 0; height--, dest+=mda_num_columns)
scr_memsetw(dest, eattr, width*2);
}
} }
static int mdacon_switch(struct vc_data *c) static int mdacon_switch(struct vc_data *c)
{ {
return 1; /* redrawing needed */ return 1; /* redrawing needed */
......
...@@ -346,12 +346,12 @@ static void newport_deinit(struct vc_data *c) ...@@ -346,12 +346,12 @@ static void newport_deinit(struct vc_data *c)
} }
} }
static void newport_clear(struct vc_data *vc, int sy, int sx, int height, static void newport_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
int width) unsigned int width)
{ {
int xend = ((sx + width) << 3) - 1; int xend = ((sx + width) << 3) - 1;
int ystart = ((sy << 4) + topscan) & 0x3ff; int ystart = ((sy << 4) + topscan) & 0x3ff;
int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff; int yend = (((sy + 1) << 4) + topscan - 1) & 0x3ff;
if (logo_active) if (logo_active)
return; return;
......
...@@ -300,13 +300,13 @@ static void sticon_deinit(struct vc_data *c) ...@@ -300,13 +300,13 @@ static void sticon_deinit(struct vc_data *c)
sticon_set_def_font(i); sticon_set_def_font(i);
} }
static void sticon_clear(struct vc_data *conp, int sy, int sx, int height, static void sticon_clear(struct vc_data *conp, unsigned int sy, unsigned int sx,
int width) unsigned int width)
{ {
if (!height || !width) if (!width)
return; return;
sti_clear(sticon_sti, sy, sx, height, width, sti_clear(sticon_sti, sy, sx, 1, width,
conp->vc_video_erase_char, font_data[conp->vc_num]); conp->vc_video_erase_char, font_data[conp->vc_num]);
} }
......
...@@ -1191,8 +1191,8 @@ static bool vgacon_scroll(struct vc_data *c, unsigned int t, unsigned int b, ...@@ -1191,8 +1191,8 @@ static bool vgacon_scroll(struct vc_data *c, unsigned int t, unsigned int b,
* The console `switch' structure for the VGA based console * The console `switch' structure for the VGA based console
*/ */
static void vgacon_clear(struct vc_data *vc, int sy, int sx, int height, static void vgacon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
int width) { } unsigned int width) { }
static void vgacon_putc(struct vc_data *vc, int c, int ypos, int xpos) { } static void vgacon_putc(struct vc_data *vc, int c, int ypos, int xpos) { }
static void vgacon_putcs(struct vc_data *vc, const unsigned short *s, static void vgacon_putcs(struct vc_data *vc, const unsigned short *s,
int count, int ypos, int xpos) { } int count, int ypos, int xpos) { }
......
...@@ -1235,8 +1235,8 @@ static void fbcon_deinit(struct vc_data *vc) ...@@ -1235,8 +1235,8 @@ static void fbcon_deinit(struct vc_data *vc)
* restriction is simplicity & efficiency at the moment. * restriction is simplicity & efficiency at the moment.
*/ */
static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height, static void __fbcon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
int width) unsigned int height, unsigned int width)
{ {
struct fb_info *info = fbcon_info_from_console(vc->vc_num); struct fb_info *info = fbcon_info_from_console(vc->vc_num);
struct fbcon_ops *ops = info->fbcon_par; struct fbcon_ops *ops = info->fbcon_par;
...@@ -1273,6 +1273,12 @@ static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height, ...@@ -1273,6 +1273,12 @@ static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
ops->clear(vc, info, real_y(p, sy), sx, height, width); ops->clear(vc, info, real_y(p, sy), sx, height, width);
} }
static void fbcon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
unsigned int width)
{
__fbcon_clear(vc, sy, sx, 1, width);
}
static void fbcon_putcs(struct vc_data *vc, const unsigned short *s, static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
int count, int ypos, int xpos) int count, int ypos, int xpos)
{ {
...@@ -1760,7 +1766,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, ...@@ -1760,7 +1766,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
case SCROLL_MOVE: case SCROLL_MOVE:
fbcon_redraw_blit(vc, info, p, t, b - t - count, fbcon_redraw_blit(vc, info, p, t, b - t - count,
count); count);
fbcon_clear(vc, b - count, 0, count, vc->vc_cols); __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
scr_memsetw((unsigned short *) (vc->vc_origin + scr_memsetw((unsigned short *) (vc->vc_origin +
vc->vc_size_row * vc->vc_size_row *
(b - count)), (b - count)),
...@@ -1783,7 +1789,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, ...@@ -1783,7 +1789,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
b - t - count, vc->vc_cols); b - t - count, vc->vc_cols);
else else
goto redraw_up; goto redraw_up;
fbcon_clear(vc, b - count, 0, count, vc->vc_cols); __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
break; break;
case SCROLL_PAN_REDRAW: case SCROLL_PAN_REDRAW:
...@@ -1801,7 +1807,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, ...@@ -1801,7 +1807,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
vc->vc_rows - b, b); vc->vc_rows - b, b);
} else } else
fbcon_redraw_move(vc, p, t + count, b - t - count, t); fbcon_redraw_move(vc, p, t + count, b - t - count, t);
fbcon_clear(vc, b - count, 0, count, vc->vc_cols); __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
break; break;
case SCROLL_PAN_MOVE: case SCROLL_PAN_MOVE:
...@@ -1824,14 +1830,14 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, ...@@ -1824,14 +1830,14 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
b - t - count, vc->vc_cols); b - t - count, vc->vc_cols);
else else
goto redraw_up; goto redraw_up;
fbcon_clear(vc, b - count, 0, count, vc->vc_cols); __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
break; break;
case SCROLL_REDRAW: case SCROLL_REDRAW:
redraw_up: redraw_up:
fbcon_redraw(vc, t, b - t - count, fbcon_redraw(vc, t, b - t - count,
count * vc->vc_cols); count * vc->vc_cols);
fbcon_clear(vc, b - count, 0, count, vc->vc_cols); __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
scr_memsetw((unsigned short *) (vc->vc_origin + scr_memsetw((unsigned short *) (vc->vc_origin +
vc->vc_size_row * vc->vc_size_row *
(b - count)), (b - count)),
...@@ -1848,7 +1854,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, ...@@ -1848,7 +1854,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
case SCROLL_MOVE: case SCROLL_MOVE:
fbcon_redraw_blit(vc, info, p, b - 1, b - t - count, fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
-count); -count);
fbcon_clear(vc, t, 0, count, vc->vc_cols); __fbcon_clear(vc, t, 0, count, vc->vc_cols);
scr_memsetw((unsigned short *) (vc->vc_origin + scr_memsetw((unsigned short *) (vc->vc_origin +
vc->vc_size_row * vc->vc_size_row *
t), t),
...@@ -1871,7 +1877,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, ...@@ -1871,7 +1877,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
b - t - count, vc->vc_cols); b - t - count, vc->vc_cols);
else else
goto redraw_down; goto redraw_down;
fbcon_clear(vc, t, 0, count, vc->vc_cols); __fbcon_clear(vc, t, 0, count, vc->vc_cols);
break; break;
case SCROLL_PAN_MOVE: case SCROLL_PAN_MOVE:
...@@ -1893,7 +1899,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, ...@@ -1893,7 +1899,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
b - t - count, vc->vc_cols); b - t - count, vc->vc_cols);
else else
goto redraw_down; goto redraw_down;
fbcon_clear(vc, t, 0, count, vc->vc_cols); __fbcon_clear(vc, t, 0, count, vc->vc_cols);
break; break;
case SCROLL_PAN_REDRAW: case SCROLL_PAN_REDRAW:
...@@ -1910,14 +1916,14 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b, ...@@ -1910,14 +1916,14 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
fbcon_redraw_move(vc, p, count, t, 0); fbcon_redraw_move(vc, p, count, t, 0);
} else } else
fbcon_redraw_move(vc, p, t, b - t - count, t + count); fbcon_redraw_move(vc, p, t, b - t - count, t + count);
fbcon_clear(vc, t, 0, count, vc->vc_cols); __fbcon_clear(vc, t, 0, count, vc->vc_cols);
break; break;
case SCROLL_REDRAW: case SCROLL_REDRAW:
redraw_down: redraw_down:
fbcon_redraw(vc, b - 1, b - t - count, fbcon_redraw(vc, b - 1, b - t - count,
-count * vc->vc_cols); -count * vc->vc_cols);
fbcon_clear(vc, t, 0, count, vc->vc_cols); __fbcon_clear(vc, t, 0, count, vc->vc_cols);
scr_memsetw((unsigned short *) (vc->vc_origin + scr_memsetw((unsigned short *) (vc->vc_origin +
vc->vc_size_row * vc->vc_size_row *
t), t),
...@@ -2196,7 +2202,7 @@ static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info, ...@@ -2196,7 +2202,7 @@ static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
oldc = vc->vc_video_erase_char; oldc = vc->vc_video_erase_char;
vc->vc_video_erase_char &= charmask; vc->vc_video_erase_char &= charmask;
fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols); __fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
vc->vc_video_erase_char = oldc; vc->vc_video_erase_char = oldc;
} }
} }
......
...@@ -38,6 +38,7 @@ enum vc_intensity; ...@@ -38,6 +38,7 @@ enum vc_intensity;
* *
* @con_init: initialize the console on @vc. @init is true for the very first * @con_init: initialize the console on @vc. @init is true for the very first
* call on this @vc. * call on this @vc.
* @con_clear: erase @count characters at [@x, @y] on @vc. @count >= 1.
* @con_scroll: move lines from @top to @bottom in direction @dir by @lines. * @con_scroll: move lines from @top to @bottom in direction @dir by @lines.
* Return true if no generic handling should be done. * Return true if no generic handling should be done.
* Invoked by csi_M and printing to the console. * Invoked by csi_M and printing to the console.
...@@ -50,8 +51,8 @@ struct consw { ...@@ -50,8 +51,8 @@ struct consw {
const char *(*con_startup)(void); const char *(*con_startup)(void);
void (*con_init)(struct vc_data *vc, bool init); void (*con_init)(struct vc_data *vc, bool init);
void (*con_deinit)(struct vc_data *vc); void (*con_deinit)(struct vc_data *vc);
void (*con_clear)(struct vc_data *vc, int sy, int sx, int height, void (*con_clear)(struct vc_data *vc, unsigned int y,
int width); unsigned int x, unsigned int count);
void (*con_putc)(struct vc_data *vc, int c, int ypos, int xpos); void (*con_putc)(struct vc_data *vc, int c, int ypos, int xpos);
void (*con_putcs)(struct vc_data *vc, const unsigned short *s, void (*con_putcs)(struct vc_data *vc, const unsigned short *s,
int count, int ypos, int xpos); int count, int ypos, int xpos);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment