lkml.org 
[lkml]   [2022]   [Aug]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] fs/ext4: replace ternary operator with min() and max()
On Tue, Aug 09, 2022 at 02:10:31PM +0800, Jiangshan Yi wrote:
> From: Jiangshan Yi <yijiangshan@kylinos.cn>
>
> Fix the following coccicheck warning:
>
> fs/ext4/extents.c:2631: WARNING opportunity for max().
> fs/ext4/extents.c:2632: WARNING opportunity for min().
>
> min() and max() macro is defined in include/linux/minmax.h. It avoids
> multiple evaluations of the arguments when non-constant and performs
> strict type-checking.
>
> Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn>
> ---
> fs/ext4/extents.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index c148bb97b527..3a74d0961024 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -2628,9 +2628,8 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
> unwritten, ex_ee_len);
> path[depth].p_ext = ex;
>
> - a = ex_ee_block > start ? ex_ee_block : start;
> - b = ex_ee_block+ex_ee_len - 1 < end ?
> - ex_ee_block+ex_ee_len - 1 : end;
> + a = max(ex_ee_block, start);
> + b = min(ex_ee_block+ex_ee_len - 1, end);

You could add spaces around the + sign, but other than that the patch
looks good. Thanks!

Reviewed-by: Lukas Czerner <lczerner@redhat.com>

Also note that a quick grep on ext4 tree reveals that there are likely
many more opportunities for using min/max.

-Lukas

>
> ext_debug(inode, " border %u:%u\n", a, b);
>
> --
> 2.25.1
>
>
> No virus found
> Checked by Hillstone Network AntiVirus
>

\
 
 \ /
  Last update: 2022-08-09 09:53    [W:0.024 / U:0.044 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site