Skip to content

Commit f374a33

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
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>
1 parent dee7e10 commit f374a33

1 file changed

Lines changed: 9 additions & 26 deletions

File tree

drivers/tty/serial/serial_core.c

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,37 +1560,20 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
15601560
void __user *uarg = (void __user *)arg;
15611561
int ret = -ENOIOCTLCMD;
15621562

1563-
1564-
/*
1565-
* These ioctls don't rely on the hardware to be present.
1566-
*/
1567-
switch (cmd) {
1568-
case TIOCSERCONFIG:
1563+
/* This ioctl doesn't rely on the hardware to be present. */
1564+
if (cmd == TIOCSERCONFIG) {
15691565
down_write(&tty->termios_rwsem);
15701566
ret = uart_do_autoconfig(tty, state);
15711567
up_write(&tty->termios_rwsem);
1572-
break;
1573-
}
1574-
1575-
if (ret != -ENOIOCTLCMD)
1576-
goto out;
1577-
1578-
if (tty_io_error(tty)) {
1579-
ret = -EIO;
1580-
goto out;
1568+
return ret;
15811569
}
15821570

1583-
/*
1584-
* The following should only be used when hardware is present.
1585-
*/
1586-
switch (cmd) {
1587-
case TIOCMIWAIT:
1588-
ret = uart_wait_modem_status(state, arg);
1589-
break;
1590-
}
1571+
if (tty_io_error(tty))
1572+
return -EIO;
15911573

1592-
if (ret != -ENOIOCTLCMD)
1593-
goto out;
1574+
/* This should only be used when the hardware is present. */
1575+
if (cmd == TIOCMIWAIT)
1576+
return uart_wait_modem_status(state, arg);
15941577

15951578
/* rs485_config requires more locking than others */
15961579
if (cmd == TIOCSRS485)
@@ -1638,7 +1621,7 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
16381621
mutex_unlock(&port->mutex);
16391622
if (cmd == TIOCSRS485)
16401623
up_write(&tty->termios_rwsem);
1641-
out:
1624+
16421625
return ret;
16431626
}
16441627

0 commit comments

Comments
 (0)