diff options
| author | Fushuai Wang <wangfushuai@baidu.com> | 2026-01-17 22:56:14 +0800 |
|---|---|---|
| committer | Peter Zijlstra <peterz@infradead.org> | 2026-01-22 11:11:16 +0100 |
| commit | 4fe82cf3024a4bdd2571d584efc25598533d5c96 (patch) | |
| tree | d3dc8fc2267001d67ba1f0380f1d6e52e7ea413d /kernel | |
| parent | 5d86d542f68fda7ef6d543ac631b741db734101a (diff) | |
sched/debug: Convert copy_from_user() + kstrtouint() to kstrtouint_from_user()
Using kstrtouint_from_user() instead of copy_from_user() + kstrtouint()
makes the code simpler and less error-prone.
Suggested-by: Yury Norov <ynorov@nvidia.com>
Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Yury Norov <ynorov@nvidia.com>
Link: https://patch.msgid.link/20260117145615.53455-2-fushuai.wang@linux.dev
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/sched/debug.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c index 5f9b77195159..929fdf09e8e9 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; |
