]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
b7e709fe1b1c538daa836b8b5b9390bc135914b6
[thirdparty/kernel/stable-queue.git] /
1 From b3bfe27fb90d545d3b0d20e1c01ed583d4e3589d 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
5 for RTR frames
6
7 From: Oliver Hartkopp <socketcan@hartkopp.net>
8
9 [ Upstream commit ed3320cec279407a86bc4c72edc4a39eb49165ec ]
10
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.
16
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>
23 ---
24 drivers/net/can/dev.c | 8 ++++++--
25 1 file changed, 6 insertions(+), 2 deletions(-)
26
27 diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
28 index 3c0f141262ad5..9579dae54af29 100644
29 --- a/drivers/net/can/dev.c
30 +++ b/drivers/net/can/dev.c
31 @@ -439,9 +439,13 @@ struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8
32 */
33 struct sk_buff *skb = priv->echo_skb[idx];
34 struct canfd_frame *cf = (struct canfd_frame *)skb->data;
35 - u8 len = cf->len;
36
37 - *len_ptr = len;
38 + /* get the real payload length for netdev statistics */
39 + if (cf->can_id & CAN_RTR_FLAG)
40 + *len_ptr = 0;
41 + else
42 + *len_ptr = cf->len;
43 +
44 priv->echo_skb[idx] = NULL;
45
46 return skb;
47 --
48 2.27.0
49