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

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
f374a33e dee7e104

+9 -26
+9 -26
drivers/tty/serial/serial_core.c
··· 1560 1560 void __user *uarg = (void __user *)arg; 1561 1561 int ret = -ENOIOCTLCMD; 1562 1562 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) { 1569 1565 down_write(&tty->termios_rwsem); 1570 1566 ret = uart_do_autoconfig(tty, state); 1571 1567 up_write(&tty->termios_rwsem); 1572 - break; 1568 + return ret; 1573 1569 } 1574 1570 1575 - if (ret != -ENOIOCTLCMD) 1576 - goto out; 1571 + if (tty_io_error(tty)) 1572 + return -EIO; 1577 1573 1578 - if (tty_io_error(tty)) { 1579 - ret = -EIO; 1580 - goto out; 1581 - } 1582 - 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 - } 1591 - 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); 1594 1577 1595 1578 /* rs485_config requires more locking than others */ 1596 1579 if (cmd == TIOCSRS485) ··· 1621 1638 mutex_unlock(&port->mutex); 1622 1639 if (cmd == TIOCSRS485) 1623 1640 up_write(&tty->termios_rwsem); 1624 - out: 1641 + 1625 1642 return ret; 1626 1643 } 1627 1644