* [PATCH RESEND] x86/mtrr: Replace simple_strtoul with kstrtoul in parse_mtrr_spare_reg
@ 2026-01-27 21:58 Thorsten Blum
2026-02-28 14:58 ` Borislav Petkov
0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2026-01-27 21:58 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Thomas Huth
Cc: Thorsten Blum, linux-kernel
Replace simple_strtoul() with the recommended kstrtoul() for parsing the
'mtrr_spare_reg_nr' boot parameter.
Check the return value of kstrtoul() and reject invalid values. This
adds error handling while preserving behavior for existing values, and
removes use of the deprecated simple_strtoul() helper. The current code
silently sets 'nr_mtrr_spare_reg = 0' if parsing fails, instead of
leaving the default value (CONFIG_MTRR_SANITIZER_SPARE_REG_NR_DEFAULT)
unchanged.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/x86/kernel/cpu/mtrr/cleanup.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c
index 763534d77f59..1de5134b1916 100644
--- a/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -437,9 +437,7 @@ 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;
+ 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 [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND] x86/mtrr: Replace simple_strtoul with kstrtoul in parse_mtrr_spare_reg
2026-01-27 21:58 [PATCH RESEND] x86/mtrr: Replace simple_strtoul with kstrtoul in parse_mtrr_spare_reg Thorsten Blum
@ 2026-02-28 14:58 ` Borislav Petkov
2026-03-01 16:23 ` Thorsten Blum
0 siblings, 1 reply; 3+ messages in thread
From: Borislav Petkov @ 2026-02-28 14:58 UTC (permalink / raw)
To: Thorsten Blum
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Thomas Huth, linux-kernel
On Tue, Jan 27, 2026 at 10:58:23PM +0100, Thorsten Blum wrote:
> Replace simple_strtoul() with the recommended kstrtoul() for parsing the
> 'mtrr_spare_reg_nr' boot parameter.
>
> Check the return value of kstrtoul() and reject invalid values.
Where?
> This adds error handling while preserving behavior for existing values, and
s/This adds/Add/
Describe your changes in imperative mood.
Also, pls read section "2) Describe your changes" in
Documentation/process/submitting-patches.rst for more details.
Also, see section "Changelog" in
Documentation/process/maintainer-tip.rst
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND] x86/mtrr: Replace simple_strtoul with kstrtoul in parse_mtrr_spare_reg
2026-02-28 14:58 ` Borislav Petkov
@ 2026-03-01 16:23 ` Thorsten Blum
0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Blum @ 2026-03-01 16:23 UTC (permalink / raw)
To: Borislav Petkov
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Thomas Huth, linux-kernel
On 28. Feb 2026, at 15:58, Borislav Petkov wrote:
> On Tue, Jan 27, 2026 at 10:58:23PM +0100, Thorsten Blum wrote:
>> Replace simple_strtoul() with the recommended kstrtoul() for parsing the
>> 'mtrr_spare_reg_nr' boot parameter.
>>
>> Check the return value of kstrtoul() and reject invalid values.
>
> Where?
The check is implicit in the return statement. Previously,
parse_mtrr_spare_reg() always returned 0 (success). Returning kstrtoul()
directly propagates 0 on success and -errno on failure, which adds
proper error handling.
However, I realized that 'arg' can be NULL here, so the NULL check
cannot be removed. I'll send a v2.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-01 16:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-27 21:58 [PATCH RESEND] x86/mtrr: Replace simple_strtoul with kstrtoul in parse_mtrr_spare_reg Thorsten Blum
2026-02-28 14:58 ` Borislav Petkov
2026-03-01 16:23 ` Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®