]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tty: hso: simplify hso_serial_write()
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Thu, 10 Aug 2023 09:15:09 +0000 (11:15 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 11 Aug 2023 19:12:47 +0000 (21:12 +0200)
There is no need for two more variables in hso_serial_write(). Switch to
min_t() and eliminate those.

Furthermore, the 'if-goto' is superfluous as memcpy() of zero count is a
nop. So is addition of zero. So remove the 'if-goto' completely.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Link: https://lore.kernel.org/r/20230810091510.13006-36-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/usb/hso.c

index 3f424da87bf47b1604a1a9dbd68a1c6b2f6aeb25..83b8452220ec16a13ae977997b72a16fa82d6202 100644 (file)
@@ -1326,7 +1326,6 @@ static ssize_t hso_serial_write(struct tty_struct *tty, const u8 *buf,
                                size_t count)
 {
        struct hso_serial *serial = tty->driver_data;
-       int space, tx_bytes;
        unsigned long flags;
 
        /* sanity check */
@@ -1337,21 +1336,16 @@ static ssize_t hso_serial_write(struct tty_struct *tty, const u8 *buf,
 
        spin_lock_irqsave(&serial->serial_lock, flags);
 
-       space = serial->tx_data_length - serial->tx_buffer_count;
-       tx_bytes = (count < space) ? count : space;
+       count = min_t(size_t, serial->tx_data_length - serial->tx_buffer_count,
+                     count);
+       memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, count);
+       serial->tx_buffer_count += count;
 
-       if (!tx_bytes)
-               goto out;
-
-       memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, tx_bytes);
-       serial->tx_buffer_count += tx_bytes;
-
-out:
        spin_unlock_irqrestore(&serial->serial_lock, flags);
 
        hso_kick_transmit(serial);
        /* done */
-       return tx_bytes;
+       return count;
 }
 
 /* how much room is there for writing */