modpost: use strstarts() to clean up parse_source_files()
PATCH 1/1 modpost: use strstarts() to clean up parse_source_files()
No functional changes are intended.
---
scripts/mod/sumversion.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/mod/sumversion.c +2 -2
@@ -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 ; }
Signature · 1 line
2.43.0
Quoted 33 lines · Masahiro Yamada
No functional changes are intended.
Signed-off-by Masahiro Yamada <[email protected]>---
scripts/mod/sumversion.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)scripts/mod/sumversion.c +2
-2@@ -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 ; }Signature · 1 line
2.43.0
Thanks, looks good to me.
Do you also want to replace the last strncmp() inscripts/mod/modpost.c?
scripts/mod/modpost.c +1 -1
@@ -670,7 +670,7 @@ static char *get_next_modinfo(struct elf_info *info, const char *tag, }for (p = modinfo; p; p =next_string (p, &size)) { -if (strncmp (p, tag, taglen) ==0 && p[taglen] =='=' ) +if (strstarts (p, tag) ==0 && p[taglen] =='=' )return p + taglen +1 ; }return NULL ;
Kind regards,
Nicolas
Quoted 48 lines · Nicolas Schier
Quoted 31 lines · Masahiro Yamada
No functional changes are intended.
Signed-off-by Masahiro Yamada <[email protected]>---
scripts/mod/sumversion.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)scripts/mod/sumversion.c +2
-3@@ -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 ; } --Quoted 2 lines
2.43.0
Thanks, looks good to me.
Reviewed-by Nicolas Schier <[email protected]>Do you also want to replace the last
strncmp()inscripts/mod/modpost.c?scripts/mod/modpost.c +0
-0
scripts/mod/modpost.c static char *get_next_modinfo(struct elf_info *info, const char *tag, · line 676
Quoted 8 lines
scripts/mod/modpost.c +1
-1@@ -670,7 +670,7 @@ static char *get_next_modinfo(struct elf_info *info, const char *tag, }for (p = modinfo; p; p =next_string (p, &size)) { -if (strncmp (p, tag, taglen) ==0 && p[taglen] =='=' ) +if (strstarts (p, tag) ==0 && p[taglen] =='=' )return p + taglen +1 ; }return NULL ;
I believe you meant:
if (strstarts(p, tag) && p[taglen] == '=')
I do not think there is a strong reason to do so because taglen is already calculated a few lines above, but the compiler may be clever enough to avoid calling strlen() twice. I did not check the compiler output.
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 61 lines · On Tue, Feb 11, 2025 at 09:43:05AM +0900 Masahiro Yamada wrote:
Quoted 48 lines · Nicolas Schier
Quoted 31 lines · Masahiro Yamada
No functional changes are intended.
Signed-off-by Masahiro Yamada <[email protected]>---
scripts/mod/sumversion.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)scripts/mod/sumversion.c +2
-3@@ -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 ; } --Quoted 2 lines
2.43.0
Thanks, looks good to me.
Reviewed-by Nicolas Schier <[email protected]>Do you also want to replace the last
strncmp()inscripts/mod/modpost.c?scripts/mod/modpost.c +0
-0scripts/mod/modpost.c static char *get_next_modinfo(struct elf_info *info, const char *tag, · line 676
Quoted 8 lines
scripts/mod/modpost.c +1
-1@@ -670,7 +670,7 @@ static char *get_next_modinfo(struct elf_info *info, const char *tag, }for (p = modinfo; p; p =next_string (p, &size)) { -if (strncmp (p, tag, taglen) ==0 && p[taglen] =='=' ) +if (strstarts (p, tag) ==0 && p[taglen] =='=' )return p + taglen +1 ; }return NULL ;I believe you meant:
Quoted 1 line
if (strstarts(p, tag) && p[taglen] == '=')
ups, yes.
Quoted 4 lines
I do not think there is a strong reason to do so because taglen is already calculated a few lines above, but the compiler may be clever enough to avoid calling
strlen()twice. I did not check the compiler output.
yeah, I was thinking about code (style) consistency, but you're right, it would not be beneficial.
Kind regards,
Nicolas