On Sun, Apr 06, 2025 at 11:27:00PM +0800, Integral wrote:
> Refactor if statements in bch2_opt_compression_parse() to make it
> simpler & clearer.
> 
> Signed-off-by: Integral <[email protected]>
> ---
>  fs/bcachefs/compress.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c
> index d68c3c7896a3..adf939b47107 100644
> --- a/fs/bcachefs/compress.c
> +++ b/fs/bcachefs/compress.c
> @@ -713,10 +713,11 @@ int bch2_opt_compression_parse(struct bch_fs *c, const 
> char *_val, u64 *res,
>       level_str = p;
>  
>       ret = match_string(bch2_compression_opts, -1, type_str);
> -     if (ret < 0 && err)
> -             prt_str(err, "invalid compression type\n");
> -     if (ret < 0)
> +     if (ret < 0) {
> +             if (err)
> +                     prt_str(err, "invalid compression type\n");
>               goto err;
> +     }

I prefer the old code for this one

>  
>       opt.type = ret;
>  
> @@ -724,14 +725,13 @@ int bch2_opt_compression_parse(struct bch_fs *c, const 
> char *_val, u64 *res,
>               unsigned level;
>  
>               ret = kstrtouint(level_str, 10, &level);
> -             if (!ret && !opt.type && level)
> -                     ret = -EINVAL;
> -             if (!ret && level > 15)
> +             if (!ret && ((!opt.type && level) || level > 15))
>                       ret = -EINVAL;

This part does look better, though.

> -             if (ret < 0 && err)
> -                     prt_str(err, "invalid compression level\n");
> -             if (ret < 0)
> +             if (ret < 0) {
> +                     if (err)
> +                             prt_str(err, "invalid compression level\n");
>                       goto err;
> +             }
>  
>               opt.level = level;
>       }
> -- 
> 2.49.0
> 

Reply via email to