From: David Disseldorp <ddiss@suse.de>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/2] btrfs: sysfs: use kstrtoull_suffix() to replace memparse()
Date: Mon, 18 Dec 2023 18:49:17 +1100 [thread overview]
Message-ID: <20231218184917.064e105e@echidna> (raw)
In-Reply-To: <2693b00ca850b0f604e03c836e71d0ad8a93ffee.1702628925.git.wqu@suse.com>
Hi Qu,
On Fri, 15 Dec 2023 19:09:24 +1030, Qu Wenruo wrote:
> Since memparse() itself can not handle overflow at all, use
> memparse_ull() to be extra safe.
s/memparse_ull/kstrtoull_suffix/
> Now overflow values can be properly detected.
Please document how the sysfs API changes with this, in addition to
overflow handling:
- support for 'E' / 'e' suffixes dropped
- only one trailing '\n' accepted, instead of many isspace()
The latter might break a few scripts.
Cheers, David
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> fs/btrfs/sysfs.c | 20 ++++++++------------
> 1 file changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index 84c05246ffd8..089c3fc123fe 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -760,7 +760,7 @@ static ssize_t btrfs_chunk_size_store(struct kobject *kobj,
> {
> struct btrfs_space_info *space_info = to_space_info(kobj);
> struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj));
> - char *retptr;
> + int ret;
> u64 val;
>
> if (!capable(CAP_SYS_ADMIN))
> @@ -776,11 +776,9 @@ static ssize_t btrfs_chunk_size_store(struct kobject *kobj,
> if (space_info->flags & BTRFS_BLOCK_GROUP_SYSTEM)
> return -EPERM;
>
> - val = memparse(buf, &retptr);
> - /* There could be trailing '\n', also catch any typos after the value */
> - retptr = skip_spaces(retptr);
> - if (*retptr != 0 || val == 0)
> - return -EINVAL;
> + ret = kstrtoull_suffix(buf, 0, &val, KSTRTOULL_SUFFIX_DEFAULT);
> + if (ret < 0)
> + return ret;
>
> val = min(val, BTRFS_MAX_DATA_CHUNK_SIZE);
>
> @@ -1779,14 +1777,12 @@ 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;
> + int ret;
>
> - limit = memparse(buf, &endptr);
> - /* There could be trailing '\n', also catch any typos after the value. */
> - endptr = skip_spaces(endptr);
> - if (*endptr != 0)
> - return -EINVAL;
> + ret = kstrtoull_suffix(buf, 0, &limit, KSTRTOULL_SUFFIX_DEFAULT);
> + if (ret < 0)
> + return ret;
> WRITE_ONCE(device->scrub_speed_max, limit);
> return len;
> }
next prev parent reply other threads:[~2023-12-18 7:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-15 8:39 [PATCH 0/2] lib/kstrtox: introduce kstrtoull_suffix() helper Qu Wenruo
2023-12-15 8:39 ` [PATCH 1/2] lib/strtox: " Qu Wenruo
2023-12-18 12:59 ` David Disseldorp
2023-12-18 19:52 ` Qu Wenruo
2023-12-19 3:17 ` David Disseldorp
2023-12-19 16:42 ` David Laight
2023-12-19 21:17 ` Qu Wenruo
2023-12-20 8:31 ` David Laight
2023-12-20 9:32 ` Qu Wenruo
2023-12-15 8:39 ` [PATCH 2/2] btrfs: sysfs: use kstrtoull_suffix() to replace memparse() Qu Wenruo
2023-12-18 7:49 ` David Disseldorp [this message]
2023-12-18 8:11 ` Qu Wenruo
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=20231218184917.064e105e@echidna \
--to=ddiss@suse.de \
--cc=linux-btrfs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.