* [PATCH v2] x86/mtrr: Use kstrtoul() in parse_mtrr_spare_reg()
@ 2026-03-02 13:53 Thorsten Blum
2026-03-02 16:38 ` [tip: x86/misc] " tip-bot2 for Thorsten Blum
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-03-02 13:53 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Thomas Huth
Cc: Thorsten Blum, linux-kernel
Replace the deprecated simple_strtoul() [1] with kstrtoul() for parsing
the early boot parameter 'mtrr_spare_reg_nr'. simple_strtoul() silently
sets 'nr_mtrr_spare_reg = 0' for invalid input instead of rejecting it
and keeping the default value.
Return kstrtoul() directly to propagate parsing failures instead of
treating them as success. Also return -EINVAL when '=' is missing from
the boot parameter and 'arg' is NULL.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull [1]
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Changes in v2:
- Return -EINVAL when 'arg' is NULL
- Update patch subject and description after feedback from Boris
- Link to v1: https://lore.kernel.org/lkml/20251218101026.225019-1-thorsten.blum@linux.dev/
---
arch/x86/kernel/cpu/mtrr/cleanup.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c
index 763534d77f59..81fc5f109f8e 100644
--- a/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -437,9 +437,9 @@ static unsigned long nr_mtrr_spare_reg __initdata =
static int __init parse_mtrr_spare_reg(char *arg)
{
- if (arg)
- nr_mtrr_spare_reg = simple_strtoul(arg, NULL, 0);
- return 0;
+ if (!arg)
+ return -EINVAL;
+ return kstrtoul(arg, 0, &nr_mtrr_spare_reg);
}
early_param("mtrr_spare_reg_nr", parse_mtrr_spare_reg);
--
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
^ permalink raw reply related [flat|nested] 2+ messages in thread* [tip: x86/misc] x86/mtrr: Use kstrtoul() in parse_mtrr_spare_reg()
2026-03-02 13:53 [PATCH v2] x86/mtrr: Use kstrtoul() in parse_mtrr_spare_reg() Thorsten Blum
@ 2026-03-02 16:38 ` tip-bot2 for Thorsten Blum
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Thorsten Blum @ 2026-03-02 16:38 UTC (permalink / raw)
To: linux-tip-commits; +Cc: Thorsten Blum, Borislav Petkov (AMD), x86, linux-kernel
The following commit has been merged into the x86/misc branch of tip:
Commit-ID: 9a4af5a00a8bff84d8d499e43d3424173835173c
Gitweb: https://git.kernel.org/tip/9a4af5a00a8bff84d8d499e43d3424173835173c
Author: Thorsten Blum <thorsten.blum@linux.dev>
AuthorDate: Mon, 02 Mar 2026 14:53:40 +01:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Mon, 02 Mar 2026 17:25:31 +01:00
x86/mtrr: Use kstrtoul() in parse_mtrr_spare_reg()
Replace the deprecated simple_strtoul()¹ with kstrtoul() for parsing the early
boot parameter mtrr_spare_reg_nr. simple_strtoul() silently sets
nr_mtrr_spare_reg to 0 for invalid input instead of rejecting it and keeping
the default value.
Return kstrtoul()'s retval directly to propagate parsing failures instead of
treating them as success. Also return -EINVAL when '=' is missing from the
boot parameter and 'arg' is NULL.
¹ https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull
[ bp: Massage commit message. ]
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://patch.msgid.link/20260302135341.3473-2-thorsten.blum@linux.dev
---
arch/x86/kernel/cpu/mtrr/cleanup.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c
index 763534d..e3eee9a 100644
--- a/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -437,9 +437,10 @@ static unsigned long nr_mtrr_spare_reg __initdata =
static int __init parse_mtrr_spare_reg(char *arg)
{
- if (arg)
- nr_mtrr_spare_reg = simple_strtoul(arg, NULL, 0);
- return 0;
+ if (!arg)
+ return -EINVAL;
+
+ return kstrtoul(arg, 0, &nr_mtrr_spare_reg);
}
early_param("mtrr_spare_reg_nr", parse_mtrr_spare_reg);
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-02 16:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-02 13:53 [PATCH v2] x86/mtrr: Use kstrtoul() in parse_mtrr_spare_reg() Thorsten Blum
2026-03-02 16:38 ` [tip: x86/misc] " tip-bot2 for Thorsten Blum
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.