Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Fushuai Wang and committed by
Peter Zijlstra
4fe82cf3 5d86d542

+4 -10
+4 -10
kernel/sched/debug.c
··· 172 172 static ssize_t sched_scaling_write(struct file *filp, const char __user *ubuf, 173 173 size_t cnt, loff_t *ppos) 174 174 { 175 - char buf[16]; 176 175 unsigned int scaling; 176 + int ret; 177 177 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; 187 181 188 182 if (scaling >= SCHED_TUNABLESCALING_END) 189 183 return -EINVAL;