From 59d60d26a58be75e9e3b813104c2dfd3b58eb662 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 8 Feb 2025 02:50:13 +0900 Subject: modpost: introduce get_basename() helper The logic to retrieve the basename appears multiple times. Factor out the common pattern into a helper function. I copied kbasename() from include/linux/string.h and renamed it to get_basename(). Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/mod/sumversion.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'scripts/mod/sumversion.c') diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c index 6de9af17599d..e79fc40d852f 100644 --- a/scripts/mod/sumversion.c +++ b/scripts/mod/sumversion.c @@ -309,15 +309,10 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md) cmd = xmalloc(strlen(objfile) + sizeof("..cmd")); - base = strrchr(objfile, '/'); - if (base) { - base++; - dirlen = base - objfile; - sprintf(cmd, "%.*s.%s.cmd", dirlen, objfile, base); - } else { - dirlen = 0; - sprintf(cmd, ".%s.cmd", objfile); - } + base = get_basename(objfile); + dirlen = base - objfile; + sprintf(cmd, "%.*s.%s.cmd", dirlen, objfile, base); + dir = xmalloc(dirlen + 1); strncpy(dir, objfile, dirlen); dir[dirlen] = '\0'; -- cgit From 144fced6852ba11c90560c996e986b4563f089af Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 8 Feb 2025 02:50:55 +0900 Subject: modpost: use strstarts() to clean up parse_source_files() No functional changes are intended. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/mod/sumversion.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/mod/sumversion.c') diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c index e79fc40d852f..3dd28b4d0099 100644 --- a/scripts/mod/sumversion.c +++ b/scripts/mod/sumversion.c @@ -330,7 +330,7 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md) line++; p = line; - if (strncmp(line, "source_", sizeof("source_")-1) == 0) { + if (strstarts(line, "source_")) { p = strrchr(line, ' '); if (!p) { warn("malformed line: %s\n", line); @@ -344,7 +344,7 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md) } continue; } - if (strncmp(line, "deps_", sizeof("deps_")-1) == 0) { + if (strstarts(line, "deps_")) { check_files = 1; continue; } -- cgit