Skip to content

Commit ea48626

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
arm64: idreg-override: Avoid kstrtou64() to parse a single hex digit
All ID register value overrides are =0 with the exception of the nokaslr pseudo feature which uses =1. In order to remove the dependency on kstrtou64(), which is part of the core kernel and no longer usable once we move idreg-override into the early mini C runtime, let's just parse a single hex digit (with optional leading 0x) and set the output value accordingly. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20231129111555.3594833-62-ardb@google.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 060260a commit ea48626

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

arch/arm64/kernel/idreg-override.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,20 @@ static int __init parse_nokaslr(char *unused)
206206
}
207207
early_param("nokaslr", parse_nokaslr);
208208

209+
static int __init parse_hexdigit(const char *p, u64 *v)
210+
{
211+
// skip "0x" if it comes next
212+
if (p[0] == '0' && tolower(p[1]) == 'x')
213+
p += 2;
214+
215+
// check whether the RHS is a single hex digit
216+
if (!isxdigit(p[0]) || (p[1] && !isspace(p[1])))
217+
return -EINVAL;
218+
219+
*v = tolower(*p) - (isdigit(*p) ? '0' : 'a' - 10);
220+
return 0;
221+
}
222+
209223
static int __init find_field(const char *cmdline, char *opt, int len,
210224
const struct ftr_set_desc *reg, int f, u64 *v)
211225
{
@@ -219,7 +233,7 @@ static int __init find_field(const char *cmdline, char *opt, int len,
219233
if (memcmp(cmdline, opt, len))
220234
return -1;
221235

222-
return kstrtou64(cmdline + len, 0, v);
236+
return parse_hexdigit(cmdline + len, v);
223237
}
224238

225239
static void __init match_options(const char *cmdline)

0 commit comments

Comments
 (0)