diff options
| author | Jiri Slaby (SUSE) <jirislaby@kernel.org> | 2025-11-19 13:01:39 +0300 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-11-21 20:30:40 +0300 |
| commit | f374a33e90e6cc17b05629636e68a012dc8347ed (patch) | |
| tree | e064787e1e8faa1af8c6a43029b9bcd1a7ff002b | |
| parent | dee7e10498c76490bb3bd5039c7c12d54585c26d (diff) | |
| download | linux-f374a33e90e6cc17b05629636e68a012dc8347ed.tar.xz | |
serial: serial_core: simplify uart_ioctl() returns
Neither uart_do_autoconfig(), nor uart_wait_modem_status() can return
-ENOIOCTLCMD. The ENOIOCTLCMD checks are there to check if 'cmd' matched
against TIOCSERCONFIG, and TIOCMIWAIT respectively. (With 0 or error in
'ret', it does not matter.)
Therefore, the code can simply return from the TIOCSERCONFIG and
TIOCMIWAIT spots immediately.
To be more explicit, use 'if' instead of switch-case for those single
values.
And return without jumping to the 'out' label -- it can be removed too.
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Link: https://patch.msgid.link/20251119100140.830761-10-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
| -rw-r--r-- | drivers/tty/serial/serial_core.c | 35 |
1 files changed, 9 insertions, 26 deletions
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 4757293ece8c..74018fb8a4e7 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1560,37 +1560,20 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) void __user *uarg = (void __user *)arg; int ret = -ENOIOCTLCMD; - - /* - * These ioctls don't rely on the hardware to be present. - */ - switch (cmd) { - case TIOCSERCONFIG: + /* This ioctl doesn't rely on the hardware to be present. */ + if (cmd == TIOCSERCONFIG) { down_write(&tty->termios_rwsem); ret = uart_do_autoconfig(tty, state); up_write(&tty->termios_rwsem); - break; - } - - if (ret != -ENOIOCTLCMD) - goto out; - - if (tty_io_error(tty)) { - ret = -EIO; - goto out; + return ret; } - /* - * The following should only be used when hardware is present. - */ - switch (cmd) { - case TIOCMIWAIT: - ret = uart_wait_modem_status(state, arg); - break; - } + if (tty_io_error(tty)) + return -EIO; - if (ret != -ENOIOCTLCMD) - goto out; + /* This should only be used when the hardware is present. */ + if (cmd == TIOCMIWAIT) + return uart_wait_modem_status(state, arg); /* rs485_config requires more locking than others */ if (cmd == TIOCSRS485) @@ -1638,7 +1621,7 @@ out_up: mutex_unlock(&port->mutex); if (cmd == TIOCSRS485) up_write(&tty->termios_rwsem); -out: + return ret; } |
