Skip to contentSkip to conversation

ipv6: Remove some pointless conditionals before kfree_skb()

PATCH Applied Wei Yongjun 4 participants 6 messages Feb 24, 2009 – Feb 25, 2009

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv6: Remove some pointless conditionals before kfree_skb()

Remove some pointless conditionals before kfree_skb().

The semantic match that finds the problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
expression E;
@@
- if (E)
- kfree_skb(E);
+ kfree_skb(E);
// </smpl>

---
 net/ipv6/ipv6_sockglue.c |    3 +--
 net/ipv6/tcp_ipv6.c      |    6 ++----
 2 files changed, 3 insertions(+), 6 deletions(-)
net/ipv6/ipv6_sockglue.c +1 -2
index 40f3246..d31df0f 100644
@@ -218,8 +218,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
 			if (opt)
 				sock_kfree_s(sk, opt, opt->tot_len);
 			pktopt = xchg(&np->pktoptions, NULL);
-			if (pktopt)
-				kfree_skb(pktopt);
+			kfree_skb(pktopt);
 
 			sk->sk_destruct = inet_sock_destruct;
 			/*
net/ipv6/tcp_ipv6.c +2 -4
index e5b85d4..273a5dd 100644
@@ -533,8 +533,7 @@ static inline void syn_flood_warning(struct sk_buff *skb)
 
 static void tcp_v6_reqsk_destructor(struct request_sock *req)
 {
-	if (inet6_rsk(req)->pktopts)
-		kfree_skb(inet6_rsk(req)->pktopts);
+	kfree_skb(inet6_rsk(req)->pktopts);
 }
 
 #ifdef CONFIG_TCP_MD5SIG
@@ -1611,8 +1610,7 @@ ipv6_pktoptions:
 		}
 	}
 
-	if (opt_skb)
-		kfree_skb(opt_skb);
+	kfree_skb(opt_skb);
 	return 0;
 }
 
Signature · 1 line
1.5.3.8
#1 lore raw
Quoted 12 lines · Wei Yongjun

Remove some pointless conditionals before kfree_skb().

The semantic match that finds the problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
expression E;
@@
- if (E)

(quoted diff) +1 -1
- 	kfree_skb(E);
+ kfree_skb(E);
Quoted 1 line

// </smpl>

I think kfree_skb() suppose that you have handled NULL pointer because it uses unlikely to check the pointer.
So I don't think these conditions are pointless...
437 void kfree_skb(struct sk_buff *skb)
438 {
439 if (unlikely(!skb))
440 return;

Quoted 45 lines
---
 net/ipv6/ipv6_sockglue.c |    3 +--
 net/ipv6/tcp_ipv6.c      |    6 ++----
 2 files changed, 3 insertions(+), 6 deletions(-)
net/ipv6/ipv6_sockglue.c +1 -2
index 40f3246..d31df0f 100644
@@ -218,8 +218,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
 			if (opt)
 				sock_kfree_s(sk, opt, opt->tot_len);
 			pktopt = xchg(&np->pktoptions, NULL);
-			if (pktopt)
-				kfree_skb(pktopt);
+			kfree_skb(pktopt);
 
 			sk->sk_destruct = inet_sock_destruct;
 			/*
net/ipv6/tcp_ipv6.c +2 -4
index e5b85d4..273a5dd 100644
@@ -533,8 +533,7 @@ static inline void syn_flood_warning(struct sk_buff *skb)
 
 static void tcp_v6_reqsk_destructor(struct request_sock *req)
 {
-	if (inet6_rsk(req)->pktopts)
-		kfree_skb(inet6_rsk(req)->pktopts);
+	kfree_skb(inet6_rsk(req)->pktopts);
 }
 
 #ifdef CONFIG_TCP_MD5SIG
@@ -1611,8 +1610,7 @@ ipv6_pktoptions:
 		}
 	}
 
-	if (opt_skb)
-		kfree_skb(opt_skb);
+	kfree_skb(opt_skb);
 	return 0;
 }
 
Signature · 2 lines
Regards
Yang Hongyang
#2 lore raw
Quoted 8 lines · Yang Hongyang

I think kfree_skb() suppose that you have handled NULL pointer because it uses unlikely to check the pointer.
So I don't think these conditions are pointless... 437 void kfree_skb(struct sk_buff *skb)
438 {
439 if (unlikely(!skb))
440 return;

These checks were specifically added so that callers didn't have to check for NULL.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#3 lore raw
Quoted 11 lines · Herbert Xu
Quoted 7 lines · Yang Hongyang

I think kfree_skb() suppose that you have handled NULL pointer because it uses unlikely to check the pointer.
So I don't think these conditions are pointless... 437 void kfree_skb(struct sk_buff *skb)
438 {
439 if (unlikely(!skb))
440 return;

These checks were specifically added so that callers didn't have to check for NULL.

Yes,but if the the callers checked for NULL,it's OK right?

Quoted 2 lines

Cheers,

Signature · 2 lines
Regards
Yang Hongyang
#4 lore raw
Quoted 5 lines · Yang Hongyang
Quoted 3 lines

These checks were specifically added so that callers didn't have to check for NULL.

Yes,but if the the callers checked for NULL,it's OK right?

Well people will continue to send patches to remove them until they're all gone :)

Really this isn't even worth discussing.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt