[tip: x86/cleanups] x86/tlb: Convert copy_from_user() + kstrtouint() to kstrtouint_from_user()

tip-bot2 for Fushuai Wang posted 1 patch 2 weeks ago
arch/x86/mm/tlb.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
[tip: x86/cleanups] x86/tlb: Convert copy_from_user() + kstrtouint() to kstrtouint_from_user()
Posted by tip-bot2 for Fushuai Wang 2 weeks ago
The following commit has been merged into the x86/cleanups branch of tip:

Commit-ID:     648fb97ee908b602f507e8b1f1ae98dd6342f05d
Gitweb:        https://git.kernel.org/tip/648fb97ee908b602f507e8b1f1ae98dd6342f05d
Author:        Fushuai Wang <wangfushuai@baidu.com>
AuthorDate:    Sat, 17 Jan 2026 22:56:15 +08:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Sun, 24 May 2026 16:08:38 -07:00

x86/tlb: 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.

No functional changes.

  [ bp: Align function args on opening brace, while at it. ]

Suggested-by: Yury Norov <ynorov@nvidia.com>
Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Yury Norov <ynorov@nvidia.com>
Link: https://patch.msgid.link/20260117145615.53455-3-fushuai.wang@linux.dev
---
 arch/x86/mm/tlb.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index af43d17..ce2e2c4 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -1769,7 +1769,7 @@ bool nmi_uaccess_okay(void)
 }
 
 static ssize_t tlbflush_read_file(struct file *file, char __user *user_buf,
-			     size_t count, loff_t *ppos)
+				  size_t count, loff_t *ppos)
 {
 	char buf[32];
 	unsigned int len;
@@ -1778,20 +1778,15 @@ static ssize_t tlbflush_read_file(struct file *file, char __user *user_buf,
 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
 }
 
-static ssize_t tlbflush_write_file(struct file *file,
-		 const char __user *user_buf, size_t count, loff_t *ppos)
+static ssize_t tlbflush_write_file(struct file *file, const char __user *user_buf,
+				   size_t count, loff_t *ppos)
 {
-	char buf[32];
-	ssize_t len;
 	int ceiling;
+	int err;
 
-	len = min(count, sizeof(buf) - 1);
-	if (copy_from_user(buf, user_buf, len))
-		return -EFAULT;
-
-	buf[len] = '\0';
-	if (kstrtoint(buf, 0, &ceiling))
-		return -EINVAL;
+	err = kstrtoint_from_user(user_buf, count, 0, &ceiling);
+	if (err)
+		return err;
 
 	if (ceiling < 0)
 		return -EINVAL;