Skip to contentSkip to conversation

ipv6: esp6: use BUG_ON instead of if condition followed by BUG

PATCH Superseded Gustavo A. R. Silva 3 participants 6 messages Oct 24, 2017 – Oct 27, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv6: esp6: use BUG_ON instead of if condition followed by BUG

Use BUG_ON instead of if condition followed by BUG in esp_remove_trailer.

This issue was detected with the help of Coccinelle.

---
 net/ipv6/esp6.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/ipv6/esp6.c +1 -2
index 89910e2..603ff06 100644
@@ -483,8 +483,7 @@ static inline int esp_remove_trailer(struct sk_buff *skb)
 		goto out;
 	}
 
-	if (skb_copy_bits(skb, skb->len - alen - 2, nexthdr, 2))
-		BUG();
+	BUG_ON(skb_copy_bits(skb, skb->len - alen - 2, nexthdr, 2));
 
 	ret = -EINVAL;
 	padlen = nexthdr[0];
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 14 lines · Gustavo A. R. Silva

Use BUG_ON instead of if condition followed by BUG in esp_remove_trailer.

This issue was detected with the help of Coccinelle.

---
 net/ipv6/esp6.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/ipv6/esp6.c +0 -0
index 89910e2..603ff06 100644

net/ipv6/esp6.c static inline int esp_remove_trailer(struct sk_buff *skb) · line 486

Quoted 6 lines
net/ipv6/esp6.c +1 -2
@@ -483,8 +483,7 @@ static inline int esp_remove_trailer(struct sk_buff *skb)
 		goto out;
 	}
 
-	if (skb_copy_bits(skb, skb->len - alen - 2, nexthdr, 2))
-		BUG();
+	BUG_ON(skb_copy_bits(skb, skb->len - alen - 2, nexthdr, 2));

How about

	ret = skb_copy_bits(skb, skb->len - alen - 2, nexthdr, 2);
	BUG_ON(ret);

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw

PATCH v2 1/1 ipv6: esp6: use BUG_ON instead of if condition followed by BUG

Use BUG_ON instead of if condition followed by BUG in esp_remove_trailer.

This issue was detected with the help of Coccinelle.

---
Changes in v2:
Update the code as suggested by Herbert Xu:

ret = foo();
BUG_ON(ret);

 net/ipv6/esp6.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv6/esp6.c +2 -2
index 89910e2..da1f6a6 100644
@@ -483,8 +483,8 @@ static inline int esp_remove_trailer(struct sk_buff *skb)
 		goto out;
 	}
 
-	if (skb_copy_bits(skb, skb->len - alen - 2, nexthdr, 2))
-		BUG();
+	ret = skb_copy_bits(skb, skb->len - alen - 2, nexthdr, 2);
+	BUG_ON(ret);
 
 	ret = -EINVAL;
 	padlen = nexthdr[0];
Signature · 1 line
2.7.4