1 From 7b12c8189a3dc50638e7d53714c88007268d47ef Mon Sep 17 00:00:00 2001
2 From: Manfred Schlaegl <manfred.schlaegl@ginzinger.com>
3 Date: Wed, 19 Dec 2018 19:39:58 +0100
4 Subject: can: dev: __can_get_echo_skb(): fix bogous check for non-existing skb by removing it
6 From: Manfred Schlaegl <manfred.schlaegl@ginzinger.com>
8 commit 7b12c8189a3dc50638e7d53714c88007268d47ef upstream.
10 This patch revert commit 7da11ba5c506
11 ("can: dev: __can_get_echo_skb(): print error message, if trying to echo non existing skb")
13 After introduction of this change we encountered following new error
14 message on various i.MX plattforms (flexcan):
16 | flexcan 53fc8000.can can0: __can_get_echo_skb: BUG! Trying to echo non
17 | existing skb: can_priv::echo_skb[0]
19 The introduction of the message was a mistake because
20 priv->echo_skb[idx] = NULL is a perfectly valid in following case: If
21 CAN_RAW_LOOPBACK is disabled (setsockopt) in applications, the pkt_type
22 of the tx skb's given to can_put_echo_skb is set to PACKET_LOOPBACK. In
23 this case can_put_echo_skb will not set priv->echo_skb[idx]. It is
26 As additional argument for revert: The order of check and usage of idx
27 was changed. idx is used to access an array element before checking it's
30 Signed-off-by: Manfred Schlaegl <manfred.schlaegl@ginzinger.com>
31 Fixes: 7da11ba5c506 ("can: dev: __can_get_echo_skb(): print error message, if trying to echo non existing skb")
32 Cc: linux-stable <stable@vger.kernel.org>
33 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
34 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
37 drivers/net/can/dev.c | 27 +++++++++++++--------------
38 1 file changed, 13 insertions(+), 14 deletions(-)
40 --- a/drivers/net/can/dev.c
41 +++ b/drivers/net/can/dev.c
42 @@ -479,8 +479,6 @@ EXPORT_SYMBOL_GPL(can_put_echo_skb);
43 struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr)
45 struct can_priv *priv = netdev_priv(dev);
46 - struct sk_buff *skb = priv->echo_skb[idx];
47 - struct canfd_frame *cf;
49 if (idx >= priv->echo_skb_max) {
50 netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n",
51 @@ -488,20 +486,21 @@ struct sk_buff *__can_get_echo_skb(struc
56 - netdev_err(dev, "%s: BUG! Trying to echo non existing skb: can_priv::echo_skb[%u]\n",
60 + if (priv->echo_skb[idx]) {
61 + /* Using "struct canfd_frame::len" for the frame
62 + * length is supported on both CAN and CANFD frames.
64 + struct sk_buff *skb = priv->echo_skb[idx];
65 + struct canfd_frame *cf = (struct canfd_frame *)skb->data;
68 - /* Using "struct canfd_frame::len" for the frame
69 - * length is supported on both CAN and CANFD frames.
71 - cf = (struct canfd_frame *)skb->data;
73 - priv->echo_skb[idx] = NULL;
75 + priv->echo_skb[idx] = NULL;