linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2] net: ipv4: Use BUG_ON directly instead of a if condition followed by BUG
@ 2018-09-11 13:13 zhong jiang
  2018-09-13 10:28 ` Simon Horman
  2018-09-13 17:42 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: zhong jiang @ 2018-09-11 13:13 UTC (permalink / raw)
  To: davem, edumazet; +Cc: kuznet, netdev, linux-kernel

The if condition can be removed if we use BUG_ON directly.
The issule is detected with the help of Coccinelle.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 net/ipv4/tcp_input.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 62508a2..526c05e 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4934,8 +4934,8 @@ void tcp_rbtree_insert(struct rb_root *root, struct sk_buff *skb)
 			BUG_ON(offset < 0);
 			if (size > 0) {
 				size = min(copy, size);
-				if (skb_copy_bits(skb, offset, skb_put(nskb, size), size))
-					BUG();
+				BUG_ON(skb_copy_bits(skb, offset,
+						     skb_put(nskb, size), size));
 				TCP_SKB_CB(nskb)->end_seq += size;
 				copy -= size;
 				start += size;
@@ -5327,8 +5327,8 @@ static void tcp_urg(struct sock *sk, struct sk_buff *skb, const struct tcphdr *t
 		/* Is the urgent pointer pointing into this packet? */
 		if (ptr < skb->len) {
 			u8 tmp;
-			if (skb_copy_bits(skb, ptr, &tmp, 1))
-				BUG();
+
+			BUG_ON(skb_copy_bits(skb, ptr, &tmp, 1));
 			tp->urg_data = TCP_URG_VALID | tmp;
 			if (!sock_flag(sk, SOCK_DEAD))
 				sk->sk_data_ready(sk);
-- 
1.7.12.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCHv2] net: ipv4: Use BUG_ON directly instead of a if condition followed by BUG
  2018-09-11 13:13 [PATCHv2] net: ipv4: Use BUG_ON directly instead of a if condition followed by BUG zhong jiang
@ 2018-09-13 10:28 ` Simon Horman
  2018-09-13 17:42 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: Simon Horman @ 2018-09-13 10:28 UTC (permalink / raw)
  To: zhong jiang; +Cc: davem, edumazet, kuznet, netdev, linux-kernel

On Tue, Sep 11, 2018 at 09:13:13PM +0800, zhong jiang wrote:
> The if condition can be removed if we use BUG_ON directly.
> The issule is detected with the help of Coccinelle.
> 
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>  net/ipv4/tcp_input.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 62508a2..526c05e 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -4934,8 +4934,8 @@ void tcp_rbtree_insert(struct rb_root *root, struct sk_buff *skb)
>  			BUG_ON(offset < 0);
>  			if (size > 0) {
>  				size = min(copy, size);
> -				if (skb_copy_bits(skb, offset, skb_put(nskb, size), size))
> -					BUG();
> +				BUG_ON(skb_copy_bits(skb, offset,
> +						     skb_put(nskb, size), size));

Perhaps things have changed but it doesn't seem desirable to me to use
BUG_ON with statements that have side-effects in case at some point BUG_ON
gets compiled out.

>  				TCP_SKB_CB(nskb)->end_seq += size;
>  				copy -= size;
>  				start += size;
> @@ -5327,8 +5327,8 @@ static void tcp_urg(struct sock *sk, struct sk_buff *skb, const struct tcphdr *t
>  		/* Is the urgent pointer pointing into this packet? */
>  		if (ptr < skb->len) {
>  			u8 tmp;
> -			if (skb_copy_bits(skb, ptr, &tmp, 1))
> -				BUG();
> +
> +			BUG_ON(skb_copy_bits(skb, ptr, &tmp, 1));
>  			tp->urg_data = TCP_URG_VALID | tmp;
>  			if (!sock_flag(sk, SOCK_DEAD))
>  				sk->sk_data_ready(sk);
> -- 
> 1.7.12.4
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv2] net: ipv4: Use BUG_ON directly instead of a if condition followed by BUG
  2018-09-11 13:13 [PATCHv2] net: ipv4: Use BUG_ON directly instead of a if condition followed by BUG zhong jiang
  2018-09-13 10:28 ` Simon Horman
@ 2018-09-13 17:42 ` David Miller
  2018-09-14  5:13   ` zhong jiang
  1 sibling, 1 reply; 4+ messages in thread
From: David Miller @ 2018-09-13 17:42 UTC (permalink / raw)
  To: zhongjiang; +Cc: edumazet, kuznet, netdev, linux-kernel

From: zhong jiang <zhongjiang@huawei.com>
Date: Tue, 11 Sep 2018 21:13:13 +0800

> The if condition can be removed if we use BUG_ON directly.
> The issule is detected with the help of Coccinelle.
> 
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>

Taking Simon's feedback into consideration...

I very often see changes like this and have to check the implementation
of BUG_ON() et al. to make sure it evaluates it's arguments even when
debugging is disabled.

Even if it is always guaranteed to do so, like me people will be unsure
forever and have to check.

That makes auditing code and validating things more time consuming and
hard.

I also think the code as written now looks a lot nicer.

So I'm not applying this, sorry.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv2] net: ipv4: Use BUG_ON directly instead of a if condition followed by BUG
  2018-09-13 17:42 ` David Miller
@ 2018-09-14  5:13   ` zhong jiang
  0 siblings, 0 replies; 4+ messages in thread
From: zhong jiang @ 2018-09-14  5:13 UTC (permalink / raw)
  To: David Miller; +Cc: edumazet, kuznet, netdev, linux-kernel

On 2018/9/14 1:42, David Miller wrote:
> From: zhong jiang <zhongjiang@huawei.com>
> Date: Tue, 11 Sep 2018 21:13:13 +0800
>
>> The if condition can be removed if we use BUG_ON directly.
>> The issule is detected with the help of Coccinelle.
>>
>> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> Taking Simon's feedback into consideration...
>
> I very often see changes like this and have to check the implementation
> of BUG_ON() et al. to make sure it evaluates it's arguments even when
> debugging is disabled.
>
> Even if it is always guaranteed to do so, like me people will be unsure
> forever and have to check.
>
> That makes auditing code and validating things more time consuming and
> hard.
>
> I also think the code as written now looks a lot nicer.
>
> So I'm not applying this, sorry.
>
> .
>
Get it.  Thank you for your explanation.

Sincerely,
zhong jiang


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-09-14  5:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-11 13:13 [PATCHv2] net: ipv4: Use BUG_ON directly instead of a if condition followed by BUG zhong jiang
2018-09-13 10:28 ` Simon Horman
2018-09-13 17:42 ` David Miller
2018-09-14  5:13   ` zhong jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).