RE: [PATCH] net/rxrpc: Use BUG_ON instead of if condition followed by BUG.

From: David Laight
Date: Thu Apr 29 2021 - 04:48:24 EST


From: zhouchuangao
> Sent: 29 April 2021 09:11
>
> BUG_ON() uses unlikely in if(), which can be optimized at compile time.
>
> do { if (unlikely(condition)) BUG(); } while (0)
...
> diff --git a/net/rxrpc/call_object.c b/net/rxrpc/call_object.c
> index 4eb91d95..e5deb6f 100644
> --- a/net/rxrpc/call_object.c
> +++ b/net/rxrpc/call_object.c
> @@ -505,8 +505,7 @@ void rxrpc_release_call(struct rxrpc_sock *rx, struct rxrpc_call *call)
> ASSERTCMP(call->state, ==, RXRPC_CALL_COMPLETE);
>
> spin_lock_bh(&call->lock);
> - if (test_and_set_bit(RXRPC_CALL_RELEASED, &call->flags))
> - BUG();
> + BUG_ON(test_and_set_bit(RXRPC_CALL_RELEASED, &call->flags));

Hiding as assignment inside BUG_ON() isn't nice.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)