lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <cxiovbh5tdwvt2k33bmdaonyncrdipbt6qj3h3gjyyi5mbzf4z@ss532ksrku46>
Date: Sun, 6 Apr 2025 13:37:10 -0400
From: Kent Overstreet <kent.overstreet@...ux.dev>
To: Integral <integral@...hlinuxcn.org>
Cc: Kent Overstreet <kent.overstreet@...il.com>, 
	linux-bcachefs@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] bcachefs: refactor if statements in
 bch2_opt_compression_parse()

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 <integral@...hlinuxcn.org>
> ---
>  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
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ