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

tty: add new helper function tty_get_tiocm

There is no in-kernel function to get the status register of a tty device
like the TIOCMGET ioctl returns to userspace. Create a new function,
tty_get_tiocm(), to obtain the status register that other portions of the
kernel can call if they need this information, and move the existing
internal tty_tiocmget() function to use this interface.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20231127110311.3583957-2-fe@dev.tdt.de
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Florian Eckert and committed by
Lee Jones
4ff4379c 793bf551

+23 -6
+22 -6
drivers/tty/tty_io.c
··· 2499 2499 } 2500 2500 2501 2501 /** 2502 + * tty_get_tiocm - get tiocm status register 2503 + * @tty: tty device 2504 + * 2505 + * Obtain the modem status bits from the tty driver if the feature 2506 + * is supported. 2507 + */ 2508 + int tty_get_tiocm(struct tty_struct *tty) 2509 + { 2510 + int retval = -ENOTTY; 2511 + 2512 + if (tty->ops->tiocmget) 2513 + retval = tty->ops->tiocmget(tty); 2514 + 2515 + return retval; 2516 + } 2517 + EXPORT_SYMBOL_GPL(tty_get_tiocm); 2518 + 2519 + /** 2502 2520 * tty_tiocmget - get modem status 2503 2521 * @tty: tty device 2504 2522 * @p: pointer to result ··· 2528 2510 */ 2529 2511 static int tty_tiocmget(struct tty_struct *tty, int __user *p) 2530 2512 { 2531 - int retval = -ENOTTY; 2513 + int retval; 2532 2514 2533 - if (tty->ops->tiocmget) { 2534 - retval = tty->ops->tiocmget(tty); 2515 + retval = tty_get_tiocm(tty); 2516 + if (retval >= 0) 2517 + retval = put_user(retval, p); 2535 2518 2536 - if (retval >= 0) 2537 - retval = put_user(retval, p); 2538 - } 2539 2519 return retval; 2540 2520 } 2541 2521
+1
include/linux/tty.h
··· 419 419 int tty_do_resize(struct tty_struct *tty, struct winsize *ws); 420 420 int tty_get_icount(struct tty_struct *tty, 421 421 struct serial_icounter_struct *icount); 422 + int tty_get_tiocm(struct tty_struct *tty); 422 423 int is_current_pgrp_orphaned(void); 423 424 void tty_hangup(struct tty_struct *tty); 424 425 void tty_vhangup(struct tty_struct *tty);