1 From e0be8a352fdb30df35547909136e2ce7ec21caa5 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Tue, 20 Oct 2020 08:44:43 +0200
4 Subject: can: dev: __can_get_echo_skb(): fix real payload length return value
7 From: Oliver Hartkopp <socketcan@hartkopp.net>
9 [ Upstream commit ed3320cec279407a86bc4c72edc4a39eb49165ec ]
11 The can_get_echo_skb() function returns the number of received bytes to
12 be used for netdev statistics. In the case of RTR frames we get a valid
13 (potential non-zero) data length value which has to be passed for further
14 operations. But on the wire RTR frames have no payload length. Therefore
15 the value to be used in the statistics has to be zero for RTR frames.
17 Reported-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
18 Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
19 Link: https://lore.kernel.org/r/20201020064443.80164-1-socketcan@hartkopp.net
20 Fixes: cf5046b309b3 ("can: dev: let can_get_echo_skb() return dlc of CAN frame")
21 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
22 Signed-off-by: Sasha Levin <sashal@kernel.org>
24 drivers/net/can/dev.c | 8 ++++++--
25 1 file changed, 6 insertions(+), 2 deletions(-)
27 diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
28 index aa2158fabf2ac..617eb75c7c0ce 100644
29 --- a/drivers/net/can/dev.c
30 +++ b/drivers/net/can/dev.c
31 @@ -469,9 +469,13 @@ struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8
33 struct sk_buff *skb = priv->echo_skb[idx];
34 struct canfd_frame *cf = (struct canfd_frame *)skb->data;
38 + /* get the real payload length for netdev statistics */
39 + if (cf->can_id & CAN_RTR_FLAG)
44 priv->echo_skb[idx] = NULL;