x86/mtrr: Use kstrtoul() in parse_mtrr_spare_reg()
PATCH v2 1/1 x86/mtrr: Use kstrtoul() in parse_mtrr_spare_reg()
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.
---
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/[email protected]/
--- arch/x86/kernel/cpu/mtrr/cleanup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/mtrr/cleanup.c +3 -3
@@ -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);
Signature · 2 lines
Thorsten Blum <[email protected]> GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
The following commit has been merged into the x86/misc branch of tip:
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 <[email protected]> AuthorDate: Mon, 02 Mar 2026 14:53:40 +01:00 Committer: Borislav Petkov (AMD) <[email protected]> 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.
[ bp: Massage commit message. ]
--- arch/x86/kernel/cpu/mtrr/cleanup.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/mtrr/cleanup.c +4 -3
@@ -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);