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

Configure Feed

Select the types of activity you want to include in your feed.

tty: vt: expect valid vc when in tty ops

At least since commits feebed6515a1 ("tty: shutdown method") and
bc1e99d93f09 ("TTY: vt, add ->install"), tty->driver_data in vc is
expected to be set since tty_operations::install() till ::cleanup().

So the checks of !tty->driver_data (aka !vc) in:
* vc_do_resize() by tty -> ioctl(TIOCSWINSZ) -> vt_resize()
* do_con_write() by tty -> tty_operations::write()/::put_char()
* con_flush_chars() by tty -> ::flush_chars()
are all superfluous. And also, holding a console lock is not needed to
fetch tty->driver_data.

Note there is even a stale comment in con_flush_chars() about a race
between that and con_close(). But con_close() does not set
tty->driver_data to NULL for years already.

Drop all these in a hope I am not terribly mistaken.

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-5-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
b3dd9bef 0e6a92f6

+3 -16
+3 -16
drivers/tty/vt/vt.c
··· 1154 1154 1155 1155 WARN_CONSOLE_UNLOCKED(); 1156 1156 1157 - if (!vc) 1158 - return -ENXIO; 1159 - 1160 1157 user = vc->vc_resize_user; 1161 1158 vc->vc_resize_user = 0; 1162 1159 ··· 2849 2852 }; 2850 2853 int c, tc, n = 0; 2851 2854 unsigned int currcons; 2852 - struct vc_data *vc; 2855 + struct vc_data *vc = tty->driver_data; 2853 2856 struct vt_notifier_param param; 2854 2857 bool rescan; 2855 2858 ··· 2857 2860 return count; 2858 2861 2859 2862 console_lock(); 2860 - vc = tty->driver_data; 2861 - if (vc == NULL) { 2862 - pr_err("vt: argh, driver_data is NULL !\n"); 2863 - console_unlock(); 2864 - return 0; 2865 - } 2866 - 2867 2863 currcons = vc->vc_num; 2868 2864 if (!vc_cons_allocated(currcons)) { 2869 2865 /* could this happen? */ ··· 3302 3312 3303 3313 static void con_flush_chars(struct tty_struct *tty) 3304 3314 { 3305 - struct vc_data *vc; 3315 + struct vc_data *vc = tty->driver_data; 3306 3316 3307 3317 if (in_interrupt()) /* from flush_to_ldisc */ 3308 3318 return; 3309 3319 3310 - /* if we race with con_close(), vt may be null */ 3311 3320 console_lock(); 3312 - vc = tty->driver_data; 3313 - if (vc) 3314 - set_cursor(vc); 3321 + set_cursor(vc); 3315 3322 console_unlock(); 3316 3323 } 3317 3324