Commit 9a4af5a0 authored by Thorsten Blum's avatar Thorsten Blum Committed by Borislav Petkov (AMD)
Browse files

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.

  ¹ https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull



  [ bp: Massage commit message. ]

Signed-off-by: default avatarThorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Link: https://patch.msgid.link/20260302135341.3473-2-thorsten.blum@linux.dev
parent 11439c46
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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);