diff options
author | Marc Kleine-Budde <mkl@pengutronix.de> | 2018-10-31 14:15:13 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-12-01 09:44:20 +0100 |
commit | c4c2c2870a8c0ba25b7871ec2f3d573031e8429a (patch) | |
tree | 67784d0fea1d8d595d4d8a1071bf9bdb01e580c3 | |
parent | 8aa60a6d605d1598fc3a3a36c37d9f568db5b0fc (diff) | |
download | linux-stable-c4c2c2870a8c0ba25b7871ec2f3d573031e8429a.tar.gz linux-stable-c4c2c2870a8c0ba25b7871ec2f3d573031e8429a.tar.bz2 linux-stable-c4c2c2870a8c0ba25b7871ec2f3d573031e8429a.zip |
can: dev: __can_get_echo_skb(): print error message, if trying to echo non existing skb
commit 7da11ba5c5066dadc2e96835a6233d56d7b7764a upstream.
Prior to echoing a successfully transmitted CAN frame (by calling
can_get_echo_skb()), CAN drivers have to put the CAN frame (by calling
can_put_echo_skb() in the transmit function). These put and get function
take an index as parameter, which is used to identify the CAN frame.
A driver calling can_get_echo_skb() with a index not pointing to a skb
is a BUG, so add an appropriate error message.
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/net/can/dev.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c index 214a48703a4e..ff3d9fc0f1b3 100644 --- a/drivers/net/can/dev.c +++ b/drivers/net/can/dev.c @@ -456,6 +456,8 @@ EXPORT_SYMBOL_GPL(can_put_echo_skb); struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr) { struct can_priv *priv = netdev_priv(dev); + struct sk_buff *skb = priv->echo_skb[idx]; + struct canfd_frame *cf; if (idx >= priv->echo_skb_max) { netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n", @@ -463,21 +465,20 @@ struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 return NULL; } - if (priv->echo_skb[idx]) { - /* Using "struct canfd_frame::len" for the frame - * length is supported on both CAN and CANFD frames. - */ - struct sk_buff *skb = priv->echo_skb[idx]; - struct canfd_frame *cf = (struct canfd_frame *)skb->data; - u8 len = cf->len; - - *len_ptr = len; - priv->echo_skb[idx] = NULL; - - return skb; + if (!skb) { + netdev_err(dev, "%s: BUG! Trying to echo non existing skb: can_priv::echo_skb[%u]\n", + __func__, idx); + return NULL; } - return NULL; + /* Using "struct canfd_frame::len" for the frame + * length is supported on both CAN and CANFD frames. + */ + cf = (struct canfd_frame *)skb->data; + *len_ptr = cf->len; + priv->echo_skb[idx] = NULL; + + return skb; } /* |