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

tty: Remove dead termiox code

set_termiox() and the TCGETX handler bail out with -EINVAL immediately
if ->termiox is NULL, but there are no code paths that can set
->termiox to a non-NULL pointer; and no such code paths seem to have
existed since the termiox mechanism was introduced back in
commit 1d65b4a088de ("tty: Add termiox") in v2.6.28.
Similarly, no driver actually implements .set_termiox; and it looks like
no driver ever has.

Delete this dead code; but leave the definition of struct termiox in the
UAPI headers intact.

Signed-off-by: Jann Horn <jannh@google.com>
Link: https://lore.kernel.org/r/20201203020331.2394754-1-jannh@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jann Horn and committed by
Greg Kroah-Hartman
e0efb316 aef1b6a2

+2 -69
+2 -59
drivers/tty/tty_ioctl.c
··· 443 443 return 0; 444 444 } 445 445 446 - 447 - #ifdef TCGETX 448 - 449 - /** 450 - * set_termiox - set termiox fields if possible 451 - * @tty: terminal 452 - * @arg: termiox structure from user 453 - * @opt: option flags for ioctl type 454 - * 455 - * Implement the device calling points for the SYS5 termiox ioctl 456 - * interface in Linux 457 - */ 458 - 459 - static int set_termiox(struct tty_struct *tty, void __user *arg, int opt) 460 - { 461 - struct termiox tnew; 462 - struct tty_ldisc *ld; 463 - 464 - if (tty->termiox == NULL) 465 - return -EINVAL; 466 - if (copy_from_user(&tnew, arg, sizeof(struct termiox))) 467 - return -EFAULT; 468 - 469 - ld = tty_ldisc_ref(tty); 470 - if (ld != NULL) { 471 - if ((opt & TERMIOS_FLUSH) && ld->ops->flush_buffer) 472 - ld->ops->flush_buffer(tty); 473 - tty_ldisc_deref(ld); 474 - } 475 - if (opt & TERMIOS_WAIT) { 476 - tty_wait_until_sent(tty, 0); 477 - if (signal_pending(current)) 478 - return -ERESTARTSYS; 479 - } 480 - 481 - down_write(&tty->termios_rwsem); 482 - if (tty->ops->set_termiox) 483 - tty->ops->set_termiox(tty, &tnew); 484 - up_write(&tty->termios_rwsem); 485 - return 0; 486 - } 487 - 488 - #endif 489 - 490 - 491 446 #ifdef TIOCGETP 492 447 /* 493 448 * These are deprecated, but there is limited support.. ··· 770 815 return ret; 771 816 #endif 772 817 #ifdef TCGETX 773 - case TCGETX: { 774 - struct termiox ktermx; 775 - if (real_tty->termiox == NULL) 776 - return -EINVAL; 777 - down_read(&real_tty->termios_rwsem); 778 - memcpy(&ktermx, real_tty->termiox, sizeof(struct termiox)); 779 - up_read(&real_tty->termios_rwsem); 780 - if (copy_to_user(p, &ktermx, sizeof(struct termiox))) 781 - ret = -EFAULT; 782 - return ret; 783 - } 818 + case TCGETX: 784 819 case TCSETX: 785 - return set_termiox(real_tty, p, 0); 786 820 case TCSETXW: 787 - return set_termiox(real_tty, p, TERMIOS_WAIT); 788 821 case TCSETXF: 789 - return set_termiox(real_tty, p, TERMIOS_FLUSH); 822 + return -EINVAL; 790 823 #endif 791 824 case TIOCGSOFTCAR: 792 825 copy_termios(real_tty, &kterm);
-1
include/linux/tty.h
··· 303 303 spinlock_t flow_lock; 304 304 /* Termios values are protected by the termios rwsem */ 305 305 struct ktermios termios, termios_locked; 306 - struct termiox *termiox; /* May be NULL for unsupported */ 307 306 char name[64]; 308 307 struct pid *pgrp; /* Protected by ctrl lock */ 309 308 struct pid *session;
-9
include/linux/tty_driver.h
··· 224 224 * line). See tty_do_resize() if you need to wrap the standard method 225 225 * in your own logic - the usual case. 226 226 * 227 - * void (*set_termiox)(struct tty_struct *tty, struct termiox *new); 228 - * 229 - * Called when the device receives a termiox based ioctl. Passes down 230 - * the requested data from user space. This method will not be invoked 231 - * unless the tty also has a valid tty->termiox pointer. 232 - * 233 - * Optional: Called under the termios lock 234 - * 235 227 * int (*get_icount)(struct tty_struct *tty, struct serial_icounter *icount); 236 228 * 237 229 * Called when the device receives a TIOCGICOUNT ioctl. Passed a kernel ··· 277 285 int (*tiocmset)(struct tty_struct *tty, 278 286 unsigned int set, unsigned int clear); 279 287 int (*resize)(struct tty_struct *tty, struct winsize *ws); 280 - int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew); 281 288 int (*get_icount)(struct tty_struct *tty, 282 289 struct serial_icounter_struct *icount); 283 290 int (*get_serial)(struct tty_struct *tty, struct serial_struct *p);