1 From 7da11ba5c5066dadc2e96835a6233d56d7b7764a Mon Sep 17 00:00:00 2001
2 From: Marc Kleine-Budde <mkl@pengutronix.de>
3 Date: Wed, 31 Oct 2018 14:15:13 +0100
4 Subject: can: dev: __can_get_echo_skb(): print error message, if trying to echo non existing skb
6 From: Marc Kleine-Budde <mkl@pengutronix.de>
8 commit 7da11ba5c5066dadc2e96835a6233d56d7b7764a upstream.
10 Prior to echoing a successfully transmitted CAN frame (by calling
11 can_get_echo_skb()), CAN drivers have to put the CAN frame (by calling
12 can_put_echo_skb() in the transmit function). These put and get function
13 take an index as parameter, which is used to identify the CAN frame.
15 A driver calling can_get_echo_skb() with a index not pointing to a skb
16 is a BUG, so add an appropriate error message.
18 Cc: linux-stable <stable@vger.kernel.org>
19 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
20 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23 drivers/net/can/dev.c | 27 ++++++++++++++-------------
24 1 file changed, 14 insertions(+), 13 deletions(-)
26 --- a/drivers/net/can/dev.c
27 +++ b/drivers/net/can/dev.c
28 @@ -426,6 +426,8 @@ EXPORT_SYMBOL_GPL(can_put_echo_skb);
29 struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr)
31 struct can_priv *priv = netdev_priv(dev);
32 + struct sk_buff *skb = priv->echo_skb[idx];
33 + struct canfd_frame *cf;
35 if (idx >= priv->echo_skb_max) {
36 netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n",
37 @@ -433,21 +435,20 @@ struct sk_buff *__can_get_echo_skb(struc
41 - if (priv->echo_skb[idx]) {
42 - /* Using "struct canfd_frame::len" for the frame
43 - * length is supported on both CAN and CANFD frames.
45 - struct sk_buff *skb = priv->echo_skb[idx];
46 - struct canfd_frame *cf = (struct canfd_frame *)skb->data;
50 - priv->echo_skb[idx] = NULL;
54 + netdev_err(dev, "%s: BUG! Trying to echo non existing skb: can_priv::echo_skb[%u]\n",
60 + /* Using "struct canfd_frame::len" for the frame
61 + * length is supported on both CAN and CANFD frames.
63 + cf = (struct canfd_frame *)skb->data;
65 + priv->echo_skb[idx] = NULL;