can: esd_usb: Move mislocated storage of SJA1000_ECC_SEG bits in case of a bus error
authorFrank Jungclaus <frank.jungclaus@esd.eu>
Thu, 16 Feb 2023 19:04:48 +0000 (20:04 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Mar 2023 08:39:18 +0000 (09:39 +0100)
[ Upstream commit 118469f88180438ef43dee93d71f77c00e7b425d ]

Move the supply for cf->data[3] (bit stream position of CAN error), in
case of a bus- or protocol-error, outside of the "switch (ecc &
SJA1000_ECC_MASK){}"-statement, because this bit stream position is
independent of the error type.

Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device")
Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu>
Link: https://lore.kernel.org/all/20230216190450.3901254-2-frank.jungclaus@esd.eu
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/can/usb/esd_usb2.c

index 9ed048cb07e6d5ee568f2b26906432a33cd48198..1abdf88597de0574a4a4db5bcf315ea2c1d460a3 100644 (file)
@@ -278,7 +278,6 @@ static void esd_usb2_rx_event(struct esd_usb2_net_priv *priv,
                                cf->data[2] |= CAN_ERR_PROT_STUFF;
                                break;
                        default:
-                               cf->data[3] = ecc & SJA1000_ECC_SEG;
                                break;
                        }
 
@@ -286,6 +285,9 @@ static void esd_usb2_rx_event(struct esd_usb2_net_priv *priv,
                        if (!(ecc & SJA1000_ECC_DIR))
                                cf->data[2] |= CAN_ERR_PROT_TX;
 
+                       /* Bit stream position in CAN frame as the error was detected */
+                       cf->data[3] = ecc & SJA1000_ECC_SEG;
+
                        if (priv->can.state == CAN_STATE_ERROR_WARNING ||
                            priv->can.state == CAN_STATE_ERROR_PASSIVE) {
                                cf->data[1] = (txerr > rxerr) ?