Skip to content

Commit 4fe82cf

Browse files
Fushuai WangPeter Zijlstra
authored andcommitted
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
1 parent 5d86d54 commit 4fe82cf

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

kernel/sched/debug.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,12 @@ static const struct file_operations sched_feat_fops = {
172172
static ssize_t sched_scaling_write(struct file *filp, const char __user *ubuf,
173173
size_t cnt, loff_t *ppos)
174174
{
175-
char buf[16];
176175
unsigned int scaling;
176+
int ret;
177177

178-
if (cnt > 15)
179-
cnt = 15;
180-
181-
if (copy_from_user(&buf, ubuf, cnt))
182-
return -EFAULT;
183-
buf[cnt] = '\0';
184-
185-
if (kstrtouint(buf, 10, &scaling))
186-
return -EINVAL;
178+
ret = kstrtouint_from_user(ubuf, cnt, 10, &scaling);
179+
if (ret)
180+
return ret;
187181

188182
if (scaling >= SCHED_TUNABLESCALING_END)
189183
return -EINVAL;

0 commit comments

Comments
 (0)