public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] elevator: avoid redundant conditions
@ 2025-09-03 12:14 Liao Yuanhong
  2025-09-04  2:33 ` Damien Le Moal
  2025-09-04  6:05 ` Markus Elfring
  0 siblings, 2 replies; 4+ messages in thread
From: Liao Yuanhong @ 2025-09-03 12:14 UTC (permalink / raw)
  To: Jens Axboe, open list:BLOCK LAYER, open list; +Cc: Liao Yuanhong

While 'if (i < 0) ... else if (i >= 0) ...' is technically equivalent to
'if (i < 0) ... else ...', the latter is vastly easier to read because
it avoids writing out a condition that is unnecessary. Let's drop such
unnecessary conditions.

Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
 block/elevator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/elevator.c b/block/elevator.c
index fe96c6f4753c..3828c35f5753 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -240,7 +240,7 @@ void elv_rb_add(struct rb_root *root, struct request *rq)
 
 		if (blk_rq_pos(rq) < blk_rq_pos(__rq))
 			p = &(*p)->rb_left;
-		else if (blk_rq_pos(rq) >= blk_rq_pos(__rq))
+		else
 			p = &(*p)->rb_right;
 	}
 
-- 
2.34.1


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

* Re: [PATCH] elevator: avoid redundant conditions
  2025-09-03 12:14 [PATCH] elevator: avoid redundant conditions Liao Yuanhong
@ 2025-09-04  2:33 ` Damien Le Moal
  2025-09-04  6:05 ` Markus Elfring
  1 sibling, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2025-09-04  2:33 UTC (permalink / raw)
  To: Liao Yuanhong, Jens Axboe, open list:BLOCK LAYER, open list

On 9/3/25 9:14 PM, Liao Yuanhong wrote:
> While 'if (i < 0) ... else if (i >= 0) ...' is technically equivalent to
> 'if (i < 0) ... else ...', the latter is vastly easier to read because
> it avoids writing out a condition that is unnecessary. Let's drop such
> unnecessary conditions.
> 
> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research

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

* Re: [PATCH] elevator: avoid redundant conditions
  2025-09-04  6:05 ` Markus Elfring
@ 2025-09-04  6:05   ` Damien Le Moal
  0 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2025-09-04  6:05 UTC (permalink / raw)
  To: Markus Elfring, Liao Yuanhong, linux-block, Jens Axboe; +Cc: LKML

On 9/4/25 3:05 PM, Markus Elfring wrote:
> …
>> it avoids writing out a condition that is unnecessary. Let's drop such
> 
>                                                          Thus?
> 
> 
>> unnecessary conditions.
> 
>   an unnecessary condition?
> 
> 
> Would a summary phrase like “Avoid redundant condition in elv_rb_add()”
> be nicer?
> 
> 
> …
>> +++ b/block/elevator.c
>> @@ -240,7 +240,7 @@ void elv_rb_add(struct rb_root *root, struct request *rq)
>>  
>>  		if (blk_rq_pos(rq) < blk_rq_pos(__rq))
>>  			p = &(*p)->rb_left;
>> -		else if (blk_rq_pos(rq) >= blk_rq_pos(__rq))
>> +		else
>>  			p = &(*p)->rb_right;
> 
> 
> Would you dare to apply a conditional expression here?
> 
> 		p = (blk_rq_pos(rq) < blk_rq_pos(__rq)) ? &(*p)->rb_left : &(*p)->rb_right;

This is far less readable.

> 
> 
> Regards,
> Markus


-- 
Damien Le Moal
Western Digital Research

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

* Re: [PATCH] elevator: avoid redundant conditions
  2025-09-03 12:14 [PATCH] elevator: avoid redundant conditions Liao Yuanhong
  2025-09-04  2:33 ` Damien Le Moal
@ 2025-09-04  6:05 ` Markus Elfring
  2025-09-04  6:05   ` Damien Le Moal
  1 sibling, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2025-09-04  6:05 UTC (permalink / raw)
  To: Liao Yuanhong, linux-block, Jens Axboe, Damien Le Moal; +Cc: LKML

…
> it avoids writing out a condition that is unnecessary. Let's drop such

                                                         Thus?


> unnecessary conditions.

  an unnecessary condition?


Would a summary phrase like “Avoid redundant condition in elv_rb_add()”
be nicer?


…
> +++ b/block/elevator.c
> @@ -240,7 +240,7 @@ void elv_rb_add(struct rb_root *root, struct request *rq)
>  
>  		if (blk_rq_pos(rq) < blk_rq_pos(__rq))
>  			p = &(*p)->rb_left;
> -		else if (blk_rq_pos(rq) >= blk_rq_pos(__rq))
> +		else
>  			p = &(*p)->rb_right;


Would you dare to apply a conditional expression here?

		p = (blk_rq_pos(rq) < blk_rq_pos(__rq)) ? &(*p)->rb_left : &(*p)->rb_right;


Regards,
Markus

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

end of thread, other threads:[~2025-09-04  6:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-03 12:14 [PATCH] elevator: avoid redundant conditions Liao Yuanhong
2025-09-04  2:33 ` Damien Le Moal
2025-09-04  6:05 ` Markus Elfring
2025-09-04  6:05   ` Damien Le Moal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox