]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.166/can-dev-__can_get_echo_skb-print-error-message-if-trying-to-echo-non-existing-skb.patch
drop queue-4.14/mips-make-sure-dt-memory-regions-are-valid.patch
[thirdparty/kernel/stable-queue.git] / releases / 4.4.166 / can-dev-__can_get_echo_skb-print-error-message-if-trying-to-echo-non-existing-skb.patch
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
5
6 From: Marc Kleine-Budde <mkl@pengutronix.de>
7
8 commit 7da11ba5c5066dadc2e96835a6233d56d7b7764a upstream.
9
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.
14
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.
17
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>
21
22 ---
23 drivers/net/can/dev.c | 27 ++++++++++++++-------------
24 1 file changed, 14 insertions(+), 13 deletions(-)
25
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)
30 {
31 struct can_priv *priv = netdev_priv(dev);
32 + struct sk_buff *skb = priv->echo_skb[idx];
33 + struct canfd_frame *cf;
34
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
38 return NULL;
39 }
40
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.
44 - */
45 - struct sk_buff *skb = priv->echo_skb[idx];
46 - struct canfd_frame *cf = (struct canfd_frame *)skb->data;
47 - u8 len = cf->len;
48 -
49 - *len_ptr = len;
50 - priv->echo_skb[idx] = NULL;
51 -
52 - return skb;
53 + if (!skb) {
54 + netdev_err(dev, "%s: BUG! Trying to echo non existing skb: can_priv::echo_skb[%u]\n",
55 + __func__, idx);
56 + return NULL;
57 }
58
59 - return NULL;
60 + /* Using "struct canfd_frame::len" for the frame
61 + * length is supported on both CAN and CANFD frames.
62 + */
63 + cf = (struct canfd_frame *)skb->data;
64 + *len_ptr = cf->len;
65 + priv->echo_skb[idx] = NULL;
66 +
67 + return skb;
68 }
69
70 /*