2019-08-21 19:35:10

by Markus Elfring

[permalink] [raw]
Subject: [PATCH] can: Delete unnecessary checks before the m acro call “dev_kfree_skb”

From: Markus Elfring <[email protected]>
Date: Wed, 21 Aug 2019 21:16:15 +0200

The dev_kfree_skb() function performs also input parameter validation.
Thus the test around the shown calls is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/net/can/spi/hi311x.c | 3 +--
drivers/net/can/spi/mcp251x.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
index 03a711c3221b..7c7c7e78214c 100644
--- a/drivers/net/can/spi/hi311x.c
+++ b/drivers/net/can/spi/hi311x.c
@@ -184,8 +184,7 @@ static void hi3110_clean(struct net_device *net)

if (priv->tx_skb || priv->tx_len)
net->stats.tx_errors++;
- if (priv->tx_skb)
- dev_kfree_skb(priv->tx_skb);
+ dev_kfree_skb(priv->tx_skb);
if (priv->tx_len)
can_free_echo_skb(priv->net, 0);
priv->tx_skb = NULL;
diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
index 12358f06d194..1c496d2adb45 100644
--- a/drivers/net/can/spi/mcp251x.c
+++ b/drivers/net/can/spi/mcp251x.c
@@ -274,8 +274,7 @@ static void mcp251x_clean(struct net_device *net)

if (priv->tx_skb || priv->tx_len)
net->stats.tx_errors++;
- if (priv->tx_skb)
- dev_kfree_skb(priv->tx_skb);
+ dev_kfree_skb(priv->tx_skb);
if (priv->tx_len)
can_free_echo_skb(priv->net, 0);
priv->tx_skb = NULL;
--
2.23.0


2019-08-22 11:58:39

by Sean Nyekjaer

[permalink] [raw]
Subject: Re: [PATCH] can: Delete unnecessary checks before the macro call “dev_kfree_skb”



On 21/08/2019 21.30, Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Wed, 21 Aug 2019 21:16:15 +0200
>
> The dev_kfree_skb() function performs also input parameter validation.
> Thus the test around the shown calls is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>
Acked-by: Sean Nyekjaer <[email protected]>
> ---
> drivers/net/can/spi/hi311x.c | 3 +--
> drivers/net/can/spi/mcp251x.c | 3 +--
> 2 files changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
> index 03a711c3221b..7c7c7e78214c 100644
> --- a/drivers/net/can/spi/hi311x.c
> +++ b/drivers/net/can/spi/hi311x.c
> @@ -184,8 +184,7 @@ static void hi3110_clean(struct net_device *net)
>
> if (priv->tx_skb || priv->tx_len)
> net->stats.tx_errors++;
> - if (priv->tx_skb)
> - dev_kfree_skb(priv->tx_skb);
> + dev_kfree_skb(priv->tx_skb);
> if (priv->tx_len)
> can_free_echo_skb(priv->net, 0);
> priv->tx_skb = NULL;
> diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
> index 12358f06d194..1c496d2adb45 100644
> --- a/drivers/net/can/spi/mcp251x.c
> +++ b/drivers/net/can/spi/mcp251x.c
> @@ -274,8 +274,7 @@ static void mcp251x_clean(struct net_device *net)
>
> if (priv->tx_skb || priv->tx_len)
> net->stats.tx_errors++;
> - if (priv->tx_skb)
> - dev_kfree_skb(priv->tx_skb);
> + dev_kfree_skb(priv->tx_skb);
> if (priv->tx_len)
> can_free_echo_skb(priv->net, 0);
> priv->tx_skb = NULL;
> --
> 2.23.0
>

Good catch Markus :-)

/Sean

2019-08-23 08:59:16

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] can: Delete unnecessary checks before the macro call “dev_kfree_skb”

From: Markus Elfring <[email protected]>
Date: Wed, 21 Aug 2019 21:30:11 +0200

> From: Markus Elfring <[email protected]>
> Date: Wed, 21 Aug 2019 21:16:15 +0200
>
> The dev_kfree_skb() function performs also input parameter validation.
> Thus the test around the shown calls is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>

Applied.