linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] blk-mq: Use BUG_ON() instead of BUG()
@ 2020-04-29  2:10 Zou Wei
  2020-04-29  7:26 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Zou Wei @ 2020-04-29  2:10 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, linux-kernel, Zou Wei

Fixes coccicheck warning:

 block/blk-mq.c:546:2-5: WARNING: Use BUG_ON instead of if condition followed by BUG.

Fixes: 63151a449eba ("blk-mq: allow drivers to hook into I/O completion")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
---
 block/blk-mq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index bcc3a23..49a227e 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -542,8 +542,7 @@ EXPORT_SYMBOL(__blk_mq_end_request);
 
 void blk_mq_end_request(struct request *rq, blk_status_t error)
 {
-	if (blk_update_request(rq, error, blk_rq_bytes(rq)))
-		BUG();
+	BUG_ON(blk_update_request(rq, error, blk_rq_bytes(rq)));
 	__blk_mq_end_request(rq, error);
 }
 EXPORT_SYMBOL(blk_mq_end_request);
-- 
2.6.2


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

* Re: [PATCH -next] blk-mq: Use BUG_ON() instead of BUG()
  2020-04-29  2:10 [PATCH -next] blk-mq: Use BUG_ON() instead of BUG() Zou Wei
@ 2020-04-29  7:26 ` Christoph Hellwig
  2020-04-29 15:15   ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2020-04-29  7:26 UTC (permalink / raw)
  To: Zou Wei; +Cc: axboe, linux-block, linux-kernel

On Wed, Apr 29, 2020 at 10:10:24AM +0800, Zou Wei wrote:
> Fixes coccicheck warning:
> 
>  block/blk-mq.c:546:2-5: WARNING: Use BUG_ON instead of if condition followed by BUG.
> 
> Fixes: 63151a449eba ("blk-mq: allow drivers to hook into I/O completion")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zou Wei <zou_wei@huawei.com>
> ---
>  block/blk-mq.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index bcc3a23..49a227e 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -542,8 +542,7 @@ EXPORT_SYMBOL(__blk_mq_end_request);
>  
>  void blk_mq_end_request(struct request *rq, blk_status_t error)
>  {
> -	if (blk_update_request(rq, error, blk_rq_bytes(rq)))
> -		BUG();
> +	BUG_ON(blk_update_request(rq, error, blk_rq_bytes(rq)));

I don't think hiding something that actually does do the work in a
BUG_ON ever is a good style.

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

* Re: [PATCH -next] blk-mq: Use BUG_ON() instead of BUG()
  2020-04-29  7:26 ` Christoph Hellwig
@ 2020-04-29 15:15   ` Jens Axboe
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-04-29 15:15 UTC (permalink / raw)
  To: Christoph Hellwig, Zou Wei; +Cc: linux-block, linux-kernel

On 4/29/20 1:26 AM, Christoph Hellwig wrote:
> On Wed, Apr 29, 2020 at 10:10:24AM +0800, Zou Wei wrote:
>> Fixes coccicheck warning:
>>
>>  block/blk-mq.c:546:2-5: WARNING: Use BUG_ON instead of if condition followed by BUG.
>>
>> Fixes: 63151a449eba ("blk-mq: allow drivers to hook into I/O completion")
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Zou Wei <zou_wei@huawei.com>
>> ---
>>  block/blk-mq.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/block/blk-mq.c b/block/blk-mq.c
>> index bcc3a23..49a227e 100644
>> --- a/block/blk-mq.c
>> +++ b/block/blk-mq.c
>> @@ -542,8 +542,7 @@ EXPORT_SYMBOL(__blk_mq_end_request);
>>  
>>  void blk_mq_end_request(struct request *rq, blk_status_t error)
>>  {
>> -	if (blk_update_request(rq, error, blk_rq_bytes(rq)))
>> -		BUG();
>> +	BUG_ON(blk_update_request(rq, error, blk_rq_bytes(rq)));
> 
> I don't think hiding something that actually does do the work in a
> BUG_ON ever is a good style.

Agree, it's a lot less readable. And, not that we've ever done that, but
also fragile in a lot of code bases where a non-debug build would turn
off the BUG_ON() equivalent, and hence never call blk_update_request().
So not a good practice anywhere for statements that have side effects.

-- 
Jens Axboe


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

end of thread, other threads:[~2020-04-29 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-29  2:10 [PATCH -next] blk-mq: Use BUG_ON() instead of BUG() Zou Wei
2020-04-29  7:26 ` Christoph Hellwig
2020-04-29 15:15   ` Jens Axboe

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).