Skip to content

Commit dc3f5aa

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
arm64: idreg-override: Avoid parameq() and parameqn()
The only way parameq() and parameqn() deviate from the ordinary string and memory routines is that they ignore the difference between dashes and underscores. Since we copy each command line argument into a buffer before passing it to parameq() and parameqn() numerous times, let's just convert all dashes to underscores just once, and update the alias array accordingly. This also helps reduce the dependency on kernel APIs that are no longer available once we move this code into the early mini C runtime. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20231129111555.3594833-59-ardb@google.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 01fd290 commit dc3f5aa

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

arch/arm64/kernel/idreg-override.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ static const struct {
185185
char alias[FTR_ALIAS_NAME_LEN];
186186
char feature[FTR_ALIAS_OPTION_LEN];
187187
} aliases[] __initconst = {
188-
{ "kvm-arm.mode=nvhe", "id_aa64mmfr1.vh=0" },
189-
{ "kvm-arm.mode=protected", "id_aa64mmfr1.vh=0" },
188+
{ "kvm_arm.mode=nvhe", "id_aa64mmfr1.vh=0" },
189+
{ "kvm_arm.mode=protected", "id_aa64mmfr1.vh=0" },
190190
{ "arm64.nosve", "id_aa64pfr0.sve=0" },
191191
{ "arm64.nosme", "id_aa64pfr1.sme=0" },
192192
{ "arm64.nobti", "id_aa64pfr1.bt=0" },
@@ -215,7 +215,7 @@ static int __init find_field(const char *cmdline,
215215
len = snprintf(opt, ARRAY_SIZE(opt), "%s.%s=",
216216
reg->name, reg->fields[f].name);
217217

218-
if (!parameqn(cmdline, opt, len))
218+
if (memcmp(cmdline, opt, len))
219219
return -1;
220220

221221
return kstrtou64(cmdline + len, 0, v);
@@ -272,23 +272,29 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases)
272272

273273
cmdline = skip_spaces(cmdline);
274274

275-
for (len = 0; cmdline[len] && !isspace(cmdline[len]); len++);
276-
if (!len)
275+
/* terminate on "--" appearing on the command line by itself */
276+
if (cmdline[0] == '-' && cmdline[1] == '-' && isspace(cmdline[2]))
277277
return;
278278

279-
len = min(len, ARRAY_SIZE(buf) - 1);
280-
memcpy(buf, cmdline, len);
281-
buf[len] = '\0';
282-
283-
if (strcmp(buf, "--") == 0)
279+
for (len = 0; cmdline[len] && !isspace(cmdline[len]); len++) {
280+
if (len >= sizeof(buf) - 1)
281+
break;
282+
if (cmdline[len] == '-')
283+
buf[len] = '_';
284+
else
285+
buf[len] = cmdline[len];
286+
}
287+
if (!len)
284288
return;
285289

290+
buf[len] = 0;
291+
286292
cmdline += len;
287293

288294
match_options(buf);
289295

290296
for (i = 0; parse_aliases && i < ARRAY_SIZE(aliases); i++)
291-
if (parameq(buf, aliases[i].alias))
297+
if (!memcmp(buf, aliases[i].alias, len + 1))
292298
__parse_cmdline(aliases[i].feature, false);
293299
} while (1);
294300
}

0 commit comments

Comments
 (0)