serial: move WARN_ON() in uart_write() to the condition
authorJiri Slaby <jirislaby@kernel.org>
Mon, 31 Jul 2023 08:02:35 +0000 (10:02 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 31 Jul 2023 15:16:04 +0000 (17:16 +0200)
uart code currently does the following in uart_write() and
uart_flush_buffer():
  if (cond) {
    WARN_ON(1);
    return;
  }

It can be rewritten to more obvious and more readable:
  if (WARN_ON(cond))
    return;

Do so.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20230731080244.2698-2-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/serial_core.c

index 306ea1a560e652f1cda3e75f313f1dd3654d1d5d..e31c9b6bd8ab8f5d5bfb9aa53891f889758b12b4 100644 (file)
@@ -593,10 +593,8 @@ static int uart_write(struct tty_struct *tty,
         * This means you called this function _after_ the port was
         * closed.  No cookie for you.
         */
-       if (!state) {
-               WARN_ON(1);
+       if (WARN_ON(!state))
                return -EL3HLT;
-       }
 
        port = uart_port_lock(state, flags);
        circ = &state->xmit;
@@ -659,10 +657,8 @@ static void uart_flush_buffer(struct tty_struct *tty)
         * This means you called this function _after_ the port was
         * closed.  No cookie for you.
         */
-       if (!state) {
-               WARN_ON(1);
+       if (WARN_ON(!state))
                return;
-       }
 
        pr_debug("uart_flush_buffer(%d) called\n", tty->index);