diff mbox

net-hsr: Delete unnecessary checks before the function call "kfree_skb"

Message ID 5647A77E.6040501@users.sourceforge.net
State Rejected, archived
Delegated to: David Miller
Headers show

Commit Message

SF Markus Elfring Nov. 14, 2015, 9:28 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Nov 2015 22:23:48 +0100

The kfree_skb() function tests whether its argument is NULL and then
returns immediately. Thus the test around the calls is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/hsr/hsr_forward.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Arvid Brodin Nov. 24, 2015, 1:42 p.m. UTC | #1
On 2015-11-14 22:28, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 14 Nov 2015 22:23:48 +0100
> 
> The kfree_skb() function tests whether its argument is NULL and then
> returns immediately. Thus the test around the calls is not needed.
> 

> diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
> index 7871ed6..55ba943 100644
> --- a/net/hsr/hsr_forward.c
> +++ b/net/hsr/hsr_forward.c
> @@ -355,11 +355,8 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)
>  		goto out_drop;
>  	hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
>  	hsr_forward_do(&frame);
> -
> -	if (frame.skb_hsr != NULL)
> -		kfree_skb(frame.skb_hsr);
> -	if (frame.skb_std != NULL)
> -		kfree_skb(frame.skb_std);
> +	kfree_skb(frame.skb_hsr);
> +	kfree_skb(frame.skb_std);

Thanks for doing checks on the HSR code, and I apologise for the late reply! Not sure if this has
already been applied, but:

You're right of course that these checks are not strictly necessary. However, it is likely that at 
least one of these (.skb_hsr or .skb_std) will be NULL here, so it could be considered nice form to 
check for this and not just trust kfree_skb() to do this. I'm not sure what's considered more 
correct in the kernel, so I will just say that I'm agnostic about this and let others decide.

Again, thanks!
diff mbox

Patch

diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
index 7871ed6..55ba943 100644
--- a/net/hsr/hsr_forward.c
+++ b/net/hsr/hsr_forward.c
@@ -355,11 +355,8 @@  void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)
 		goto out_drop;
 	hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
 	hsr_forward_do(&frame);
-
-	if (frame.skb_hsr != NULL)
-		kfree_skb(frame.skb_hsr);
-	if (frame.skb_std != NULL)
-		kfree_skb(frame.skb_std);
+	kfree_skb(frame.skb_hsr);
+	kfree_skb(frame.skb_std);
 	return;
 
 out_drop: