mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Fushuai Wang <fushuai.wang@linux.dev>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	vschneid@redhat.com, dave.hansen@linux.intel.com,
	luto@kernel.org, tglx@kernel.org, bp@alien8.de, hpa@zytor.com
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
	wangfushuai@baidu.com, aliceryhl@google.com, ynorov@nvidia.com
Subject: [PATCH 1/2] sched/debug: Convert copy_from_user() + kstrtouint() to kstrtouint_from_user()
Date: Fri, 16 Jan 2026 21:17:50 +0800	[thread overview]
Message-ID: <20260116131751.45768-2-fushuai.wang@linux.dev> (raw)
In-Reply-To: <20260116131751.45768-1-fushuai.wang@linux.dev>

From: Fushuai Wang <wangfushuai@baidu.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@baidu.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


  reply	other threads:[~2026-01-16 13:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16 13:17 [PATCH 0/2] " Fushuai Wang
2026-01-16 13:17 ` Fushuai Wang [this message]
2026-01-16 17:04   ` [PATCH 1/2] sched/debug: " Yury Norov
2026-01-16 13:17 ` [PATCH 2/2] x86/tlb: " Fushuai Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260116131751.45768-2-fushuai.wang@linux.dev \
    --to=fushuai.wang@linux.dev \
    --cc=aliceryhl@google.com \
    --cc=bp@alien8.de \
    --cc=bsegall@google.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=hpa@zytor.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=wangfushuai@baidu.com \
    --cc=x86@kernel.org \
    --cc=ynorov@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®