[PATCH net-next] xfrm: use BUG_ON instead of if condition followed by BUG

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

STALE1889d

2 messages, 2 authors, 2021-06-07 · open the first message on its own page

[PATCH net-next] xfrm: use BUG_ON instead of if condition followed by BUG

From: Zheng Yongjun <hidden>
Date: 2021-06-07 08:57:50

Use BUG_ON instead of if condition followed by BUG.

This issue was detected with the help of Coccinelle.

Signed-off-by: Zheng Yongjun <redacted>
---
 net/xfrm/xfrm_policy.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index ce500f847b99..532314578151 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -421,8 +421,7 @@ void xfrm_policy_destroy(struct xfrm_policy *policy)
 {
 	BUG_ON(!policy->walk.dead);
 
-	if (del_timer(&policy->timer) || del_timer(&policy->polq.hold_timer))
-		BUG();
+	BUG_ON(del_timer(&policy->timer) || del_timer(&policy->polq.hold_timer));
 
 	call_rcu(&policy->rcu, xfrm_policy_destroy_rcu);
 }
-- 
2.25.1

Re: [PATCH net-next] xfrm: use BUG_ON instead of if condition followed by BUG

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: 2021-06-07 09:04:52

On Mon, Jun 07, 2021 at 05:11:21PM +0800, Zheng Yongjun wrote:
quoted hunk
Use BUG_ON instead of if condition followed by BUG.

This issue was detected with the help of Coccinelle.

Signed-off-by: Zheng Yongjun <redacted>
---
 net/xfrm/xfrm_policy.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index ce500f847b99..532314578151 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -421,8 +421,7 @@ void xfrm_policy_destroy(struct xfrm_policy *policy)
 {
 	BUG_ON(!policy->walk.dead);
 
-	if (del_timer(&policy->timer) || del_timer(&policy->polq.hold_timer))
-		BUG();
+	BUG_ON(del_timer(&policy->timer) || del_timer(&policy->polq.hold_timer));
Nack.  Do not put statements with side effects within BUG_ON.
-- 
Email: Herbert Xu [off-list ref]
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help