Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: vt: pass vc_resize_user as a parameter

It is pretty unfortunate to set vc_data::vc_resize_user in two callers
of vc_do_resize(). vc_resize_user is immediately reset there (while
remembering it). So instead of this back and forth, pass 'from_user' as
a parameter.

Notes on 'int user':
* The name changes from 'user' to 'from_user' on some places to be
consistent.
* The type is bool now as 'int user' might evoke user's uid or whatever.

Provided vc_resize() is called on many places and they need not to care
about this parameter, its prototype is kept unchanged. Instead, it is
now an inline calling a new __vc_resize() which implements the above.

This patch makes the situation much more obvious.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Cc: Helge Deller <deller@gmx.de>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: linux-fbdev@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Tested-by: Helge Deller <deller@gmx.de> # parisc STI console
Link: https://lore.kernel.org/r/20240122110401.7289-8-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
beccdcfa d321cd13

+27 -25
+13 -15
drivers/tty/vt/vt.c
··· 1115 1115 } 1116 1116 1117 1117 static inline int resize_screen(struct vc_data *vc, int width, int height, 1118 - int user) 1118 + bool from_user) 1119 1119 { 1120 1120 /* Resizes the resolution of the display adapater */ 1121 1121 int err = 0; 1122 1122 1123 1123 if (vc->vc_sw->con_resize) 1124 - err = vc->vc_sw->con_resize(vc, width, height, user); 1124 + err = vc->vc_sw->con_resize(vc, width, height, from_user); 1125 1125 1126 1126 return err; 1127 1127 } ··· 1132 1132 * @vc: virtual console private data 1133 1133 * @cols: columns 1134 1134 * @lines: lines 1135 + * @from_user: invoked by a user? 1135 1136 * 1136 1137 * Resize a virtual console, clipping according to the actual constraints. 1137 1138 * If the caller passes a tty structure then update the termios winsize ··· 1143 1142 */ 1144 1143 1145 1144 static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc, 1146 - unsigned int cols, unsigned int lines) 1145 + unsigned int cols, unsigned int lines, bool from_user) 1147 1146 { 1148 1147 unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0; 1149 1148 unsigned long end; 1150 1149 unsigned int old_rows, old_row_size, first_copied_row; 1151 1150 unsigned int new_cols, new_rows, new_row_size, new_screen_size; 1152 - unsigned int user; 1153 1151 unsigned short *oldscreen, *newscreen; 1154 1152 u32 **new_uniscr = NULL; 1155 1153 1156 1154 WARN_CONSOLE_UNLOCKED(); 1157 - 1158 - user = vc->vc_resize_user; 1159 - vc->vc_resize_user = 0; 1160 1155 1161 1156 if (cols > VC_MAXCOL || lines > VC_MAXROW) 1162 1157 return -EINVAL; ··· 1179 1182 * to deal with possible errors from the code below, we call 1180 1183 * the resize_screen here as well. 1181 1184 */ 1182 - return resize_screen(vc, new_cols, new_rows, user); 1185 + return resize_screen(vc, new_cols, new_rows, from_user); 1183 1186 } 1184 1187 1185 1188 if (new_screen_size > KMALLOC_MAX_SIZE || !new_screen_size) ··· 1202 1205 old_rows = vc->vc_rows; 1203 1206 old_row_size = vc->vc_size_row; 1204 1207 1205 - err = resize_screen(vc, new_cols, new_rows, user); 1208 + err = resize_screen(vc, new_cols, new_rows, from_user); 1206 1209 if (err) { 1207 1210 kfree(newscreen); 1208 1211 vc_uniscr_free(new_uniscr); ··· 1289 1292 } 1290 1293 1291 1294 /** 1292 - * vc_resize - resize a VT 1295 + * __vc_resize - resize a VT 1293 1296 * @vc: virtual console 1294 1297 * @cols: columns 1295 1298 * @rows: rows 1299 + * @from_user: invoked by a user? 1296 1300 * 1297 1301 * Resize a virtual console as seen from the console end of things. We 1298 1302 * use the common vc_do_resize methods to update the structures. The 1299 1303 * caller must hold the console sem to protect console internals and 1300 1304 * vc->port.tty 1301 1305 */ 1302 - 1303 - int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows) 1306 + int __vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows, 1307 + bool from_user) 1304 1308 { 1305 - return vc_do_resize(vc->port.tty, vc, cols, rows); 1309 + return vc_do_resize(vc->port.tty, vc, cols, rows, from_user); 1306 1310 } 1307 - EXPORT_SYMBOL(vc_resize); 1311 + EXPORT_SYMBOL(__vc_resize); 1308 1312 1309 1313 /** 1310 1314 * vt_resize - resize a VT ··· 1325 1327 int ret; 1326 1328 1327 1329 console_lock(); 1328 - ret = vc_do_resize(tty, vc, ws->ws_col, ws->ws_row); 1330 + ret = vc_do_resize(tty, vc, ws->ws_col, ws->ws_row, false); 1329 1331 console_unlock(); 1330 1332 return ret; 1331 1333 }
+2 -4
drivers/tty/vt/vt_ioctl.c
··· 714 714 vcp->vc_scan_lines = v.v_vlin; 715 715 if (v.v_clin) 716 716 vcp->vc_cell_height = v.v_clin; 717 - vcp->vc_resize_user = 1; 718 - ret = vc_resize(vcp, v.v_cols, v.v_rows); 717 + ret = __vc_resize(vcp, v.v_cols, v.v_rows, true); 719 718 if (ret) { 720 719 vcp->vc_scan_lines = save_scan_lines; 721 720 vcp->vc_cell_height = save_cell_height; ··· 922 923 vc = vc_cons[i].d; 923 924 924 925 if (vc) { 925 - vc->vc_resize_user = 1; 926 926 /* FIXME: review v tty lock */ 927 - vc_resize(vc_cons[i].d, cc, ll); 927 + __vc_resize(vc_cons[i].d, cc, ll, true); 928 928 } 929 929 } 930 930 console_unlock();
+2 -2
drivers/video/console/vgacon.c
··· 1081 1081 } 1082 1082 1083 1083 static int vgacon_resize(struct vc_data *c, unsigned int width, 1084 - unsigned int height, unsigned int user) 1084 + unsigned int height, bool from_user) 1085 1085 { 1086 1086 if ((width << 1) * height > vga_vram_size) 1087 1087 return -EINVAL; 1088 1088 1089 - if (user) { 1089 + if (from_user) { 1090 1090 /* 1091 1091 * Ho ho! Someone (svgatextmode, eh?) may have reprogrammed 1092 1092 * the video mode! Set the new defaults then and go away.
+1 -1
drivers/video/fbdev/core/fbcon.c
··· 1996 1996 #define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */ 1997 1997 1998 1998 static int fbcon_resize(struct vc_data *vc, unsigned int width, 1999 - unsigned int height, unsigned int user) 1999 + unsigned int height, bool from_user) 2000 2000 { 2001 2001 struct fb_info *info = fbcon_info_from_console(vc->vc_num); 2002 2002 struct fbcon_ops *ops = info->fbcon_par;
+1 -1
include/linux/console.h
··· 66 66 int (*con_font_default)(struct vc_data *vc, 67 67 struct console_font *font, char *name); 68 68 int (*con_resize)(struct vc_data *vc, unsigned int width, 69 - unsigned int height, unsigned int user); 69 + unsigned int height, bool from_user); 70 70 void (*con_set_palette)(struct vc_data *vc, 71 71 const unsigned char *table); 72 72 void (*con_scrolldelta)(struct vc_data *vc, int lines);
-1
include/linux/console_struct.h
··· 151 151 DECLARE_BITMAP(vc_tab_stop, VC_TABSTOPS_COUNT); /* Tab stops. 256 columns. */ 152 152 unsigned char vc_palette[16*3]; /* Colour palette for VGA+ */ 153 153 unsigned short * vc_translate; 154 - unsigned int vc_resize_user; /* resize request from user */ 155 154 unsigned int vc_bell_pitch; /* Console bell pitch */ 156 155 unsigned int vc_bell_duration; /* Console bell duration */ 157 156 unsigned short vc_cur_blink_ms; /* Cursor blink duration */
+8 -1
include/linux/vt_kern.h
··· 25 25 26 26 int vc_allocate(unsigned int console); 27 27 int vc_cons_allocated(unsigned int console); 28 - int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines); 28 + int __vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines, 29 + bool from_user); 29 30 struct vc_data *vc_deallocate(unsigned int console); 30 31 void reset_palette(struct vc_data *vc); 31 32 void do_blank_screen(int entering_gfx); ··· 42 41 void redraw_screen(struct vc_data *vc, int is_switch); 43 42 #define update_screen(x) redraw_screen(x, 0) 44 43 #define switch_screen(x) redraw_screen(x, 1) 44 + 45 + static inline int vc_resize(struct vc_data *vc, unsigned int cols, 46 + unsigned int lines) 47 + { 48 + return __vc_resize(vc, cols, lines, false); 49 + } 45 50 46 51 struct tty_struct; 47 52 int tioclinux(struct tty_struct *tty, unsigned long arg);