[PATCH] ubifs: prefer kstrtobool_from_user() over custom helper
Zhihao Cheng
chengzhihao1 at huawei.com
Thu Apr 2 04:18:05 PDT 2026
在 2026/4/2 16:13, Dmitry Antipov 写道:
> Adjust 'dfs_file_write()' and 'dfs_global_file_write()' to prefer generic
> 'kstrtobool_from_user()' over an ad-hoc 'interpret_user_input()' helper,
> thus making the latter not needed anymore.
>
> Signed-off-by: Dmitry Antipov <dmantipov at yandex.ru>
> ---
> fs/ubifs/debug.c | 44 ++++++++++----------------------------------
> 1 file changed, 10 insertions(+), 34 deletions(-)
>
Reviewed-by: Zhihao Cheng <chengzhihao1 at huawei.com>
> diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
> index 160c16aa7b6e..252cf82012cf 100644
> --- a/fs/ubifs/debug.c
> +++ b/fs/ubifs/debug.c
> @@ -2732,39 +2732,14 @@ static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count,
> return provide_user_output(val, u, count, ppos);
> }
>
> -/**
> - * interpret_user_input - interpret user debugfs file input.
> - * @u: user-provided buffer with the input
> - * @count: buffer size
> - *
> - * This is a helper function which interpret user input to a boolean UBIFS
> - * debugfs file. Returns %0 or %1 in case of success and a negative error code
> - * in case of failure.
> - */
> -static int interpret_user_input(const char __user *u, size_t count)
> -{
> - size_t buf_size;
> - char buf[8];
> -
> - buf_size = min_t(size_t, count, (sizeof(buf) - 1));
> - if (copy_from_user(buf, u, buf_size))
> - return -EFAULT;
> -
> - if (buf[0] == '1')
> - return 1;
> - else if (buf[0] == '0')
> - return 0;
> -
> - return -EINVAL;
> -}
> -
> static ssize_t dfs_file_write(struct file *file, const char __user *u,
> size_t count, loff_t *ppos)
> {
> struct ubifs_info *c = file->private_data;
> struct ubifs_debug_info *d = c->dbg;
> struct dentry *dent = file->f_path.dentry;
> - int val;
> + bool val;
> + int ret;
>
> if (file->f_path.dentry == d->dfs_dump_lprops) {
> ubifs_dump_lprops(c);
> @@ -2781,9 +2756,9 @@ static ssize_t dfs_file_write(struct file *file, const char __user *u,
> return count;
> }
>
> - val = interpret_user_input(u, count);
> - if (val < 0)
> - return val;
> + ret = kstrtobool_from_user(u, count, &val);
> + if (unlikely(ret))
> + return ret;
>
> if (dent == d->dfs_chk_gen)
> d->chk_gen = val;
> @@ -2926,11 +2901,12 @@ static ssize_t dfs_global_file_write(struct file *file, const char __user *u,
> size_t count, loff_t *ppos)
> {
> struct dentry *dent = file->f_path.dentry;
> - int val;
> + bool val;
> + int ret;
>
> - val = interpret_user_input(u, count);
> - if (val < 0)
> - return val;
> + ret = kstrtobool_from_user(u, count, &val);
> + if (unlikely(ret))
> + return ret;
>
> if (dent == dfs_chk_gen)
> ubifs_dbg.chk_gen = val;
>
More information about the linux-mtd
mailing list