linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: ext4: Fix traditional comparison using max/min method
@ 2023-06-19 13:44 Li Dong
  2023-06-20  2:22 ` Kemeng Shi
  0 siblings, 1 reply; 2+ messages in thread
From: Li Dong @ 2023-06-19 13:44 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger, open list:EXT4 FILE SYSTEM, open list
  Cc: opensource.kernel, lidong

It would be better to replace the traditional ternary conditional operator with max()/min()

Signed-off-by: Li Dong <lidong@vivo.com>
---
 fs/ext4/balloc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 1f72f977c6db..90ff655ddddb 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -111,10 +111,8 @@ static unsigned ext4_num_overhead_clusters(struct super_block *sb,
 	itbl_blk_start = ext4_inode_table(sb, gdp);
 	itbl_blk_end = itbl_blk_start + sbi->s_itb_per_group - 1;
 	if (itbl_blk_start <= end && itbl_blk_end >= start) {
-		itbl_blk_start = itbl_blk_start >= start ?
-			itbl_blk_start : start;
-		itbl_blk_end = itbl_blk_end <= end ?
-			itbl_blk_end : end;
+		itbl_blk_start = max(itbl_blk_start, start);
+		itbl_blk_end = min(itbl_blk_end, end);
 
 		itbl_cluster_start = EXT4_B2C(sbi, itbl_blk_start - start);
 		itbl_cluster_end = EXT4_B2C(sbi, itbl_blk_end - start);
-- 
2.31.1.windows.1


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

* Re: [PATCH] fs: ext4: Fix traditional comparison using max/min method
  2023-06-19 13:44 [PATCH] fs: ext4: Fix traditional comparison using max/min method Li Dong
@ 2023-06-20  2:22 ` Kemeng Shi
  0 siblings, 0 replies; 2+ messages in thread
From: Kemeng Shi @ 2023-06-20  2:22 UTC (permalink / raw)
  To: Li Dong, Theodore Ts'o, Andreas Dilger,
	open list:EXT4 FILE SYSTEM, open list
  Cc: opensource.kernel



on 6/19/2023 9:44 PM, Li Dong wrote:
> It would be better to replace the traditional ternary conditional operator with max()/min()
Hi Li, thanks for the patch, but this is a duplicate of [1] :)

[1] https://lore.kernel.org/linux-ext4/51be7b9a-726c-c232-146b-7785c50e875a@huaweicloud.com/
> Signed-off-by: Li Dong <lidong@vivo.com>
> ---
>  fs/ext4/balloc.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
> index 1f72f977c6db..90ff655ddddb 100644
> --- a/fs/ext4/balloc.c
> +++ b/fs/ext4/balloc.c
> @@ -111,10 +111,8 @@ static unsigned ext4_num_overhead_clusters(struct super_block *sb,
>  	itbl_blk_start = ext4_inode_table(sb, gdp);
>  	itbl_blk_end = itbl_blk_start + sbi->s_itb_per_group - 1;
>  	if (itbl_blk_start <= end && itbl_blk_end >= start) {
> -		itbl_blk_start = itbl_blk_start >= start ?
> -			itbl_blk_start : start;
> -		itbl_blk_end = itbl_blk_end <= end ?
> -			itbl_blk_end : end;
> +		itbl_blk_start = max(itbl_blk_start, start);
> +		itbl_blk_end = min(itbl_blk_end, end);
>  
>  		itbl_cluster_start = EXT4_B2C(sbi, itbl_blk_start - start);
>  		itbl_cluster_end = EXT4_B2C(sbi, itbl_blk_end - start);
> 

-- 
Best wishes
Kemeng Shi


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

end of thread, other threads:[~2023-06-20  2:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-19 13:44 [PATCH] fs: ext4: Fix traditional comparison using max/min method Li Dong
2023-06-20  2:22 ` Kemeng Shi

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