Takashi Iwai fc4670
From ed3320cec279407a86bc4c72edc4a39eb49165ec Mon Sep 17 00:00:00 2001
Takashi Iwai fc4670
From: Oliver Hartkopp <socketcan@hartkopp.net>
Takashi Iwai fc4670
Date: Tue, 20 Oct 2020 08:44:43 +0200
Takashi Iwai fc4670
Subject: [PATCH] can: dev: __can_get_echo_skb(): fix real payload length return value for RTR frames
Takashi Iwai fc4670
Git-commit: ed3320cec279407a86bc4c72edc4a39eb49165ec
Takashi Iwai fc4670
Patch-mainline: v5.10-rc3
Takashi Iwai fc4670
References: git-fixes
Takashi Iwai fc4670
Takashi Iwai fc4670
The can_get_echo_skb() function returns the number of received bytes to
Takashi Iwai fc4670
be used for netdev statistics. In the case of RTR frames we get a valid
Takashi Iwai fc4670
(potential non-zero) data length value which has to be passed for further
Takashi Iwai fc4670
operations. But on the wire RTR frames have no payload length. Therefore
Takashi Iwai fc4670
the value to be used in the statistics has to be zero for RTR frames.
Takashi Iwai fc4670
Takashi Iwai fc4670
Reported-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Takashi Iwai fc4670
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Takashi Iwai fc4670
Link: https://lore.kernel.org/r/20201020064443.80164-1-socketcan@hartkopp.net
Takashi Iwai fc4670
Fixes: cf5046b309b3 ("can: dev: let can_get_echo_skb() return dlc of CAN frame")
Takashi Iwai fc4670
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Takashi Iwai fc4670
Acked-by: Takashi Iwai <tiwai@suse.de>
Takashi Iwai fc4670
Takashi Iwai fc4670
---
Takashi Iwai fc4670
 drivers/net/can/dev.c | 8 ++++++--
Takashi Iwai fc4670
 1 file changed, 6 insertions(+), 2 deletions(-)
Takashi Iwai fc4670
Takashi Iwai fc4670
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
Takashi Iwai fc4670
index 73cfcd7e9517..6dee4f8f2024 100644
Takashi Iwai fc4670
--- a/drivers/net/can/dev.c
Takashi Iwai fc4670
+++ b/drivers/net/can/dev.c
Takashi Iwai fc4670
@@ -512,9 +512,13 @@ __can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr)
Takashi Iwai fc4670
 		 */
Takashi Iwai fc4670
 		struct sk_buff *skb = priv->echo_skb[idx];
Takashi Iwai fc4670
 		struct canfd_frame *cf = (struct canfd_frame *)skb->data;
Takashi Iwai fc4670
-		u8 len = cf->len;
Takashi Iwai fc4670
 
Takashi Iwai fc4670
-		*len_ptr = len;
Takashi Iwai fc4670
+		/* get the real payload length for netdev statistics */
Takashi Iwai fc4670
+		if (cf->can_id & CAN_RTR_FLAG)
Takashi Iwai fc4670
+			*len_ptr = 0;
Takashi Iwai fc4670
+		else
Takashi Iwai fc4670
+			*len_ptr = cf->len;
Takashi Iwai fc4670
+
Takashi Iwai fc4670
 		priv->echo_skb[idx] = NULL;
Takashi Iwai fc4670
 
Takashi Iwai fc4670
 		return skb;
Takashi Iwai fc4670
-- 
Takashi Iwai fc4670
2.16.4
Takashi Iwai fc4670