From: Thorsten Blum <thorsten.blum@linux.dev>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Thomas Huth <thuth@redhat.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>, linux-kernel@vger.kernel.org
Subject: [PATCH v2] x86/mtrr: Use kstrtoul() in parse_mtrr_spare_reg()
Date: Mon, 2 Mar 2026 14:53:40 +0100 [thread overview]
Message-ID: <20260302135341.3473-2-thorsten.blum@linux.dev> (raw)
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
next reply other threads:[~2026-03-02 13:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-02 13:53 Thorsten Blum [this message]
2026-03-02 16:38 ` [tip: x86/misc] x86/mtrr: Use kstrtoul() in parse_mtrr_spare_reg() tip-bot2 for Thorsten Blum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260302135341.3473-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@kernel.org \
--cc=thuth@redhat.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox