[PATCH v2 1/2] sched/debug: Convert copy_from_user() + kstrtouint() to kstrtouint_from_user()

From: Fushuai Wang

Date: Sat Jan 17 2026 - 09:57:09 EST


From: Fushuai Wang <wangfushuai@xxxxxxxxx>

Using kstrtouint_from_user() instead of copy_from_user() + kstrtouint()
makes the code simpler and less error-prone.

Suggested-by: Yury Norov <ynorov@xxxxxxxxxx>
Signed-off-by: Fushuai Wang <wangfushuai@xxxxxxxxx>
Reviewed-by: Yury Norov <ynorov@xxxxxxxxxx>
---
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..b27229a1922b 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)
+ return ret;

if (scaling >= SCHED_TUNABLESCALING_END)
return -EINVAL;
--
2.36.1