Skip to content

Commit 73048bd

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
tty: can327, move overflow test inside can327_ldisc_rx()'s loop
The 'count' is going to be unsigned and the 'count >= 0' test would be always true then. Move the condition to the loop where this is easier to check. It looks as is easier to follow after all too. Signed-off-by: "Jiri Slaby (SUSE)" <[email protected]> Cc: Max Staudt <[email protected]> Cc: Wolfgang Grandegger <[email protected]> Cc: Marc Kleine-Budde <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Paolo Abeni <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 94b580e commit 73048bd

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

drivers/net/can/can327.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,13 @@ static void can327_ldisc_rx(struct tty_struct *tty, const unsigned char *cp,
901901
*/
902902
first_new_char_idx = elm->rxfill;
903903

904-
while (count-- && elm->rxfill < CAN327_SIZE_RXBUF) {
904+
while (count--) {
905+
if (elm->rxfill >= CAN327_SIZE_RXBUF) {
906+
netdev_err(elm->dev,
907+
"Receive buffer overflowed. Bad chip or wiring? count = %i",
908+
count);
909+
goto uart_failure;
910+
}
905911
if (fp && *fp++) {
906912
netdev_err(elm->dev,
907913
"Error in received character stream. Check your wiring.");
@@ -930,13 +936,6 @@ static void can327_ldisc_rx(struct tty_struct *tty, const unsigned char *cp,
930936
cp++;
931937
}
932938

933-
if (count >= 0) {
934-
netdev_err(elm->dev,
935-
"Receive buffer overflowed. Bad chip or wiring? count = %i",
936-
count);
937-
goto uart_failure;
938-
}
939-
940939
can327_parse_rxbuf(elm, first_new_char_idx);
941940
spin_unlock_bh(&elm->lock);
942941

0 commit comments

Comments
 (0)