tty: Remove baudrate dead code & make ktermios params const
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 16 Aug 2022 11:57:32 +0000 (14:57 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 30 Aug 2022 12:22:34 +0000 (14:22 +0200)
With the architectures currently in-tree, either:
  1) CBAUDEX is zero
  2) The earlier BOTHER if check covers cbaud < 1 case
  3) All CBAUD bits are covered by the baud_table

Thus, the check for cbaud being out-of-range for CBAUDEX case cannot
ever be true.

The ktermios parameters can now be made const.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20220816115739.10928-2-ilpo.jarvinen@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/tty.h
drivers/tty/tty_baudrate.c
include/linux/tty.h

index f310a8274df1539a9a71c2220fbd7fe2b9067f17..1c08c9b67b16ca3f9990a8fd8b2cdefa619b3786 100644 (file)
@@ -73,7 +73,7 @@ void tty_buffer_set_lock_subclass(struct tty_port *port);
 bool tty_buffer_restart_work(struct tty_port *port);
 bool tty_buffer_cancel_work(struct tty_port *port);
 void tty_buffer_flush_work(struct tty_port *port);
-speed_t tty_termios_input_baud_rate(struct ktermios *termios);
+speed_t tty_termios_input_baud_rate(const struct ktermios *termios);
 void tty_ldisc_hangup(struct tty_struct *tty, bool reset);
 int tty_ldisc_reinit(struct tty_struct *tty, int disc);
 long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
index 3cd99ed7c7102c9e1db051e97716766a0b56bd06..4e3fd756dfc7a8b545c1b3d2716255dbe093a37e 100644 (file)
@@ -49,13 +49,13 @@ static int n_baud_table = ARRAY_SIZE(baud_table);
  *
  *     Convert termios baud rate data into a speed. This should be called
  *     with the termios lock held if this termios is a terminal termios
- *     structure. May change the termios data. Device drivers can call this
- *     function but should use ->c_[io]speed directly as they are updated.
+ *     structure. Device drivers can call this function but should use
+ *     ->c_[io]speed directly as they are updated.
  *
  *     Locking: none
  */
 
-speed_t tty_termios_baud_rate(struct ktermios *termios)
+speed_t tty_termios_baud_rate(const struct ktermios *termios)
 {
        unsigned int cbaud;
 
@@ -67,11 +67,7 @@ speed_t tty_termios_baud_rate(struct ktermios *termios)
 
        if (cbaud & CBAUDEX) {
                cbaud &= ~CBAUDEX;
-
-               if (cbaud < 1 || cbaud + 15 > n_baud_table)
-                       termios->c_cflag &= ~CBAUDEX;
-               else
-                       cbaud += 15;
+               cbaud += 15;
        }
        return cbaud >= n_baud_table ? 0 : baud_table[cbaud];
 }
@@ -83,13 +79,13 @@ EXPORT_SYMBOL(tty_termios_baud_rate);
  *
  *     Convert termios baud rate data into a speed. This should be called
  *     with the termios lock held if this termios is a terminal termios
- *     structure. May change the termios data. Device drivers can call this
- *     function but should use ->c_[io]speed directly as they are updated.
+ *     structure. Device drivers can call this function but should use
+ *     ->c_[io]speed directly as they are updated.
  *
  *     Locking: none
  */
 
-speed_t tty_termios_input_baud_rate(struct ktermios *termios)
+speed_t tty_termios_input_baud_rate(const struct ktermios *termios)
 {
        unsigned int cbaud = (termios->c_cflag >> IBSHIFT) & CBAUD;
 
@@ -102,11 +98,7 @@ speed_t tty_termios_input_baud_rate(struct ktermios *termios)
 
        if (cbaud & CBAUDEX) {
                cbaud &= ~CBAUDEX;
-
-               if (cbaud < 1 || cbaud + 15 > n_baud_table)
-                       termios->c_cflag &= ~(CBAUDEX << IBSHIFT);
-               else
-                       cbaud += 15;
+               cbaud += 15;
        }
        return cbaud >= n_baud_table ? 0 : baud_table[cbaud];
 }
index 7b0a5d478ef660e500764d7d8ba2c176bf6d2700..cf5ab26de73d030a1f5020fb6254c1b8a2323d76 100644 (file)
@@ -434,7 +434,7 @@ int tty_hung_up_p(struct file *filp);
 void do_SAK(struct tty_struct *tty);
 void __do_SAK(struct tty_struct *tty);
 void no_tty(void);
-speed_t tty_termios_baud_rate(struct ktermios *termios);
+speed_t tty_termios_baud_rate(const struct ktermios *termios);
 void tty_termios_encode_baud_rate(struct ktermios *termios, speed_t ibaud,
                speed_t obaud);
 void tty_encode_baud_rate(struct tty_struct *tty, speed_t ibaud,