[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aWpvtxvO-AZ1tvDE@yury>
Date: Fri, 16 Jan 2026 12:04:55 -0500
From: Yury Norov <ynorov@...dia.com>
To: Fushuai Wang <fushuai.wang@...ux.dev>
Cc: mingo@...hat.com, peterz@...radead.org, juri.lelli@...hat.com,
vincent.guittot@...aro.org, dietmar.eggemann@....com,
rostedt@...dmis.org, bsegall@...gle.com, mgorman@...e.de,
vschneid@...hat.com, dave.hansen@...ux.intel.com, luto@...nel.org,
tglx@...nel.org, bp@...en8.de, hpa@...or.com,
linux-kernel@...r.kernel.org, x86@...nel.org, wangfushuai@...du.com,
aliceryhl@...gle.com
Subject: Re: [PATCH 1/2] sched/debug: Convert copy_from_user() + kstrtouint()
to kstrtouint_from_user()
On Fri, Jan 16, 2026 at 09:17:50PM +0800, Fushuai Wang wrote:
> From: Fushuai Wang <wangfushuai@...du.com>
>
> Using kstrtouint_from_user() instead of copy_from_user() + kstrtouint()
> makes the code simpler and less error-prone.
>
> Signed-off-by: Fushuai Wang <wangfushuai@...du.com>
> ---
> kernel/sched/debug.c | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
> index 41caa22e0680..1091f9046260 100644
> --- a/kernel/sched/debug.c
> +++ b/kernel/sched/debug.c
> @@ -172,18 +172,12 @@ static const struct file_operations sched_feat_fops = {
> static ssize_t sched_scaling_write(struct file *filp, const char __user *ubuf,
> size_t cnt, loff_t *ppos)
> {
> - char buf[16];
> unsigned int scaling;
> + int ret;
>
> - if (cnt > 15)
> - cnt = 15;
> -
> - if (copy_from_user(&buf, ubuf, cnt))
> - return -EFAULT;
> - buf[cnt] = '\0';
> -
> - if (kstrtouint(buf, 10, &scaling))
> - return -EINVAL;
> + ret = kstrtouint_from_user(ubuf, cnt, 10, &scaling);
> + if (ret < 0)
> + return ret;
This thing returns 0 on success, so I think you could better do:
if (ret)
return ret;
With that, for the series:
Suggested-by: Yury Norov <ynorov@...dia.com>
Reviewed-by: Yury Norov <ynorov@...dia.com>
Thanks,
Yury
>
> if (scaling >= SCHED_TUNABLESCALING_END)
> return -EINVAL;
> --
> 2.36.1
>
Powered by blists - more mailing lists