[PATCH v2] x86/mtrr: Use kstrtoul() in parse_mtrr_spare_reg()
From: Thorsten Blum
Date: Mon Mar 02 2026 - 08:54:49 EST
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@xxxxxxxxx>
---
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@xxxxxxxxx/
---
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@xxxxxxxxx>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4