public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Disseldorp <ddiss@suse.de>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	akpm@linux-foundation.org, christophe.jaillet@wanadoo.fr,
	andriy.shevchenko@linux.intel.com, David.Laight@ACULAB.COM
Subject: Re: [PATCH v2 4/4] btrfs: migrate to the newer memparse_safe() helper
Date: Wed, 3 Jan 2024 01:24:06 +1100	[thread overview]
Message-ID: <20240103012406.12928a36@echidna> (raw)
In-Reply-To: <04b551a30763f776303c7ca8b0d0ffc0ed665e2a.1704168510.git.wqu@suse.com>

On Tue,  2 Jan 2024 14:42:14 +1030, Qu Wenruo wrote:

> The new helper has better error report and correct overflow detection,
> furthermore the old @retptr behavior is also kept, thus there should be
> no behavior change.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  fs/btrfs/ioctl.c |  6 +++++-
>  fs/btrfs/super.c |  9 ++++++++-
>  fs/btrfs/sysfs.c | 14 +++++++++++---
>  3 files changed, 24 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 4e50b62db2a8..cb63f50a2078 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -1175,7 +1175,11 @@ static noinline int btrfs_ioctl_resize(struct file *file,
>  			mod = 1;
>  			sizestr++;
>  		}
> -		new_size = memparse(sizestr, &retptr);
> +
> +		ret = memparse_safe(sizestr, MEMPARSE_SUFFIXES_DEFAULT,
> +				    &new_size, &retptr);
> +		if (ret < 0)
> +			goto out_finish;
>  		if (*retptr != '\0' || new_size == 0) {
>  			ret = -EINVAL;
>  			goto out_finish;
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 3a677b808f0f..0f29fd692e0f 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -263,6 +263,8 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
>  {
>  	struct btrfs_fs_context *ctx = fc->fs_private;
>  	struct fs_parse_result result;
> +	/* Only for memparse_safe() caller. */
> +	int ret;
>  	int opt;
>  
>  	opt = fs_parse(fc, btrfs_fs_parameters, param, &result);
> @@ -400,7 +402,12 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
>  		ctx->thread_pool_size = result.uint_32;
>  		break;
>  	case Opt_max_inline:
> -		ctx->max_inline = memparse(param->string, NULL);
> +		ret = memparse_safe(param->string, MEMPARSE_SUFFIXES_DEFAULT,
> +				    &ctx->max_inline, NULL);
> +		if (ret < 0) {
> +			btrfs_err(NULL, "invalid string \"%s\"", param->string);
> +			return ret;
> +		}
>  		break;
>  	case Opt_acl:
>  		if (result.negated) {
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index 84c05246ffd8..6846572496a6 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -762,6 +762,7 @@ static ssize_t btrfs_chunk_size_store(struct kobject *kobj,
>  	struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj));
>  	char *retptr;
>  	u64 val;
> +	int ret;
>  
>  	if (!capable(CAP_SYS_ADMIN))
>  		return -EPERM;
> @@ -776,7 +777,10 @@ static ssize_t btrfs_chunk_size_store(struct kobject *kobj,
>  	if (space_info->flags & BTRFS_BLOCK_GROUP_SYSTEM)
>  		return -EPERM;
>  
> -	val = memparse(buf, &retptr);
> +	ret = memparse_safe(buf, MEMPARSE_SUFFIXES_DEFAULT, &val, &retptr);
> +	if (ret < 0)
> +		return ret;
> +
>  	/* There could be trailing '\n', also catch any typos after the value */
>  	retptr = skip_spaces(retptr);
>  	if (*retptr != 0 || val == 0)
> @@ -1779,10 +1783,14 @@ static ssize_t btrfs_devinfo_scrub_speed_max_store(struct kobject *kobj,
>  {
>  	struct btrfs_device *device = container_of(kobj, struct btrfs_device,
>  						   devid_kobj);
> -	char *endptr;
>  	unsigned long long limit;
> +	char *endptr;
> +	int ret;
> +
> +	ret = memparse_safe(buf, MEMPARSE_SUFFIXES_DEFAULT, &limit, &endptr);
> +	if (ret < 0)
> +		return ret;
>  
> -	limit = memparse(buf, &endptr);
>  	/* There could be trailing '\n', also catch any typos after the value. */
>  	endptr = skip_spaces(endptr);
>  	if (*endptr != 0)

Looks fine.
Reviewed-by: David Disseldorp <ddiss@suse.de>

  reply	other threads:[~2024-01-02 14:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02  4:12 [PATCH v2 0/4] kstrtox: introduce memparse_safe() Qu Wenruo
2024-01-02  4:12 ` [PATCH v2 1/4] kstrtox: always skip the leading "0x" even if no more valid chars Qu Wenruo
2024-01-02 14:16   ` David Disseldorp
2024-01-02  4:12 ` [PATCH v2 2/4] kstrtox: introduce a safer version of memparse() Qu Wenruo
2024-01-02 14:19   ` David Disseldorp
2024-01-02  4:12 ` [PATCH v2 3/4] kstrtox: add unit tests for memparse_safe() Qu Wenruo
2024-01-02 13:23   ` Geert Uytterhoeven
2024-01-02 20:55     ` Qu Wenruo
2024-01-03  9:27       ` Geert Uytterhoeven
2024-01-03  9:45         ` Qu Wenruo
2024-01-02 14:17   ` David Disseldorp
2024-01-03 22:45     ` Qu Wenruo
2024-01-02  4:12 ` [PATCH v2 4/4] btrfs: migrate to the newer memparse_safe() helper Qu Wenruo
2024-01-02 14:24   ` David Disseldorp [this message]
2024-01-02 17:10 ` [PATCH v2 0/4] kstrtox: introduce memparse_safe() David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240103012406.12928a36@echidna \
    --to=ddiss@suse.de \
    --cc=David.Laight@ACULAB.COM \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox