Skip to content

Commit 4ff4379

Browse files
feckertlag-linaro
authored andcommitted
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 <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 793bf55 commit 4ff4379

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

drivers/tty/tty_io.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,6 +2498,24 @@ static int send_break(struct tty_struct *tty, unsigned int duration)
24982498
return retval;
24992499
}
25002500

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+
25012519
/**
25022520
* tty_tiocmget - get modem status
25032521
* @tty: tty device
@@ -2510,14 +2528,12 @@ static int send_break(struct tty_struct *tty, unsigned int duration)
25102528
*/
25112529
static int tty_tiocmget(struct tty_struct *tty, int __user *p)
25122530
{
2513-
int retval = -ENOTTY;
2531+
int retval;
25142532

2515-
if (tty->ops->tiocmget) {
2516-
retval = tty->ops->tiocmget(tty);
2533+
retval = tty_get_tiocm(tty);
2534+
if (retval >= 0)
2535+
retval = put_user(retval, p);
25172536

2518-
if (retval >= 0)
2519-
retval = put_user(retval, p);
2520-
}
25212537
return retval;
25222538
}
25232539

include/linux/tty.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ bool tty_unthrottle_safe(struct tty_struct *tty);
419419
int tty_do_resize(struct tty_struct *tty, struct winsize *ws);
420420
int tty_get_icount(struct tty_struct *tty,
421421
struct serial_icounter_struct *icount);
422+
int tty_get_tiocm(struct tty_struct *tty);
422423
int is_current_pgrp_orphaned(void);
423424
void tty_hangup(struct tty_struct *tty);
424425
void tty_vhangup(struct tty_struct *tty);

0 commit comments

Comments
 (0)