Skip to contentSkip to conversation

arm64: Replace strncmp with str_has_prefix

PATCH In review Chuhong Yuan 2 participants 2 messages Jul 30, 2019 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: Replace strncmp with str_has_prefix

In commit b6b2735514bc
("tracing: Use str_has_prefix() instead of using fixed sizes") the newly introduced str_has_prefix() was used
to replace error-prone strncmp(str, const, len). Here fix codes with the same pattern.

---
 arch/arm64/kernel/module-plts.c | 2 +-
 arch/arm64/mm/numa.c            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/module-plts.c +1 -1
index 044c0ae4d6c8..b182442b87a3 100644
@@ -302,7 +302,7 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
 		/* sort by type, symbol index and addend */
 		sort(rels, numrels, sizeof(Elf64_Rela), cmp_rela, NULL);
 
-		if (strncmp(secstrings + dstsec->sh_name, ".init", 5) != 0)
+		if (!str_has_prefix(secstrings + dstsec->sh_name, ".init"))
 			core_plts += count_plts(syms, rels, numrels,
 						sechdrs[i].sh_info, dstsec);
 		else
arch/arm64/mm/numa.c +1 -1
index 4f241cc7cc3b..4decf1659700 100644
@@ -29,7 +29,7 @@ static __init int numa_parse_early_param(char *opt)
 {
 	if (!opt)
 		return -EINVAL;
-	if (!strncmp(opt, "off", 3))
+	if (str_has_prefix(opt, "off"))
 		numa_off = true;
 
 	return 0;
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 11 lines · Chuhong Yuan

In commit b6b2735514bc
("tracing: Use str_has_prefix() instead of using fixed sizes") the newly introduced str_has_prefix() was used
to replace error-prone strncmp(str, const, len). Here fix codes with the same pattern.

---
 arch/arm64/kernel/module-plts.c | 2 +-
 arch/arm64/mm/numa.c            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

I can pick this up for 5.4.

Will