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

tty: hso: simplify hso_serial_write()

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>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
6fcd3b67 c3e5c706

+5 -11
+5 -11
drivers/net/usb/hso.c
··· 1326 1326 size_t count) 1327 1327 { 1328 1328 struct hso_serial *serial = tty->driver_data; 1329 - int space, tx_bytes; 1330 1329 unsigned long flags; 1331 1330 1332 1331 /* sanity check */ ··· 1336 1337 1337 1338 spin_lock_irqsave(&serial->serial_lock, flags); 1338 1339 1339 - space = serial->tx_data_length - serial->tx_buffer_count; 1340 - tx_bytes = (count < space) ? count : space; 1340 + count = min_t(size_t, serial->tx_data_length - serial->tx_buffer_count, 1341 + count); 1342 + memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, count); 1343 + serial->tx_buffer_count += count; 1341 1344 1342 - if (!tx_bytes) 1343 - goto out; 1344 - 1345 - memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, tx_bytes); 1346 - serial->tx_buffer_count += tx_bytes; 1347 - 1348 - out: 1349 1345 spin_unlock_irqrestore(&serial->serial_lock, flags); 1350 1346 1351 1347 hso_kick_transmit(serial); 1352 1348 /* done */ 1353 - return tx_bytes; 1349 + return count; 1354 1350 } 1355 1351 1356 1352 /* how much room is there for writing */