[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260116131751.45768-2-fushuai.wang@linux.dev>
Date: Fri, 16 Jan 2026 21:17:50 +0800
From: Fushuai Wang <fushuai.wang@...ux.dev>
To: 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
Cc: linux-kernel@...r.kernel.org,
x86@...nel.org,
wangfushuai@...du.com,
aliceryhl@...gle.com,
ynorov@...dia.com
Subject: [PATCH 1/2] sched/debug: Convert copy_from_user() + kstrtouint() to kstrtouint_from_user()
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;
if (scaling >= SCHED_TUNABLESCALING_END)
return -EINVAL;
--
2.36.1
Powered by blists - more mailing lists