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

Subsystems: networking [general], networking [ipsec], the rest

STALE3216d

6 messages, 3 authors, 2017-10-27 · open the first message on its own page

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

From: Gustavo A. R. Silva <hidden>
Date: 2017-10-24 16:28:34

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

This issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <redacted>
---
 net/ipv6/esp6.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index 89910e2..603ff06 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -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];
-- 
2.7.4

Re: [PATCH] ipv6: esp6: use BUG_ON instead of if condition followed by BUG

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: 2017-10-25 04:08:40

On Tue, Oct 24, 2017 at 11:28:26AM -0500, Gustavo A. R. Silva wrote:
quoted hunk
Use BUG_ON instead of if condition followed by BUG in esp_remove_trailer.

This issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <redacted>
---
 net/ipv6/esp6.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index 89910e2..603ff06 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -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,
-- 
Email: Herbert Xu [off-list ref]
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

[PATCH v2] ipv6: esp6: use BUG_ON instead of if condition followed by BUG

From: Gustavo A. R. Silva <hidden>
Date: 2017-10-26 12:51:14

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

This issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <redacted>
---
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(-)
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index 89910e2..da1f6a6 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -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];
-- 
2.7.4

Re: [PATCH v2] ipv6: esp6: use BUG_ON instead of if condition followed by BUG

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: 2017-10-26 22:39:25

On Thu, Oct 26, 2017 at 07:51:06AM -0500, Gustavo A. R. Silva wrote:
Use BUG_ON instead of if condition followed by BUG in esp_remove_trailer.

This issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <redacted>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
-- 
Email: Herbert Xu [off-list ref]
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Re: [PATCH v2] ipv6: esp6: use BUG_ON instead of if condition followed by BUG

From: Gustavo A. R. Silva <hidden>
Date: 2017-10-27 04:12:56

Quoting Herbert Xu [off-list ref]:
On Thu, Oct 26, 2017 at 07:51:06AM -0500, Gustavo A. R. Silva wrote:
quoted
Use BUG_ON instead of if condition followed by BUG in esp_remove_trailer.

This issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <redacted>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Thanks!

--
Gustavo A. R. Silva

Re: [PATCH v2] ipv6: esp6: use BUG_ON instead of if condition followed by BUG

From: Steffen Klassert <steffen.klassert@secunet.com>
Date: 2017-10-27 10:46:59

On Fri, Oct 27, 2017 at 06:38:36AM +0800, Herbert Xu wrote:
On Thu, Oct 26, 2017 at 07:51:06AM -0500, Gustavo A. R. Silva wrote:
quoted
Use BUG_ON instead of if condition followed by BUG in esp_remove_trailer.

This issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <redacted>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Applied to ipsec-next, thanks everyone!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help