[RFC PATCH v1 10/12] module: Replace strstarts() by str_has_prefix().

From: laniel_francis
Date: Fri Dec 04 2020 - 12:06:57 EST


From: Francis Laniel <laniel_francis@xxxxxxxxxxxxxxxxxxx>

The two functions indicates if a string begins with a given prefix.
The only difference is that strstarts() returns a bool while str_has_prefix()
returns the length of the prefix if the string begins with it or 0 otherwise.

Signed-off-by: Francis Laniel <laniel_francis@xxxxxxxxxxxxxxxxxxx>
---
kernel/module.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index a4fa44a652a7..d01466f1d2a6 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2675,7 +2675,7 @@ static char elf_type(const Elf_Sym *sym, const struct load_info *info)
else
return 'b';
}
- if (strstarts(info->secstrings + sechdrs[sym->st_shndx].sh_name,
+ if (str_has_prefix(info->secstrings + sechdrs[sym->st_shndx].sh_name,
".debug")) {
return 'n';
}
@@ -2842,12 +2842,12 @@ void * __weak module_alloc(unsigned long size)

bool __weak module_init_section(const char *name)
{
- return strstarts(name, ".init");
+ return str_has_prefix(name, ".init");
}

bool __weak module_exit_section(const char *name)
{
- return strstarts(name, ".exit");
+ return str_has_prefix(name, ".exit");
}

#ifdef CONFIG_DEBUG_KMEMLEAK
--
2.20.1