can: slcan: do not report txerr and rxerr during bus-off
authorVincent Mailhol <mailhol.vincent@wanadoo.fr>
Tue, 19 Jul 2022 14:35:42 +0000 (23:35 +0900)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 20 Jul 2022 07:26:49 +0000 (09:26 +0200)
During bus off, the error count is greater than 255 and can not fit in
a u8.

alloc_can_err_skb() already sets cf to NULL if the allocation fails [1],
so the redundant cf = NULL assignment gets removed.

[1] https://elixir.bootlin.com/linux/latest/source/drivers/net/can/dev/skb.c#L187

Fixes: 0a9cdcf098a4 ("can: slcan: extend the protocol with CAN state info")
Link: https://lore.kernel.org/all/20220719143550.3681-5-mailhol.vincent@wanadoo.fr
CC: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/slcan/slcan-core.c

index 057b211f3e7f4275747b0a78c8156368bb7ed3fa..dfd1baba41300d154443a4eb2957d8bfd831dcd4 100644 (file)
@@ -306,19 +306,17 @@ static void slc_bump_state(struct slcan *sl)
                return;
 
        skb = alloc_can_err_skb(dev, &cf);
-       if (skb) {
-               cf->data[6] = txerr;
-               cf->data[7] = rxerr;
-       } else {
-               cf = NULL;
-       }
 
        tx_state = txerr >= rxerr ? state : 0;
        rx_state = txerr <= rxerr ? state : 0;
        can_change_state(dev, cf, tx_state, rx_state);
 
-       if (state == CAN_STATE_BUS_OFF)
+       if (state == CAN_STATE_BUS_OFF) {
                can_bus_off(dev);
+       } else if (skb) {
+               cf->data[6] = txerr;
+               cf->data[7] = rxerr;
+       }
 
        if (skb)
                netif_rx(skb);