public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [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

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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox