Skip to content

Commit

Permalink
modinfo: Avoid unneeded system call
Browse files Browse the repository at this point in the history
If a file name does not end with ".ko", there is no need to call fstat.
Since common use cases are like "modinfo modname", the string check
should come first to save a tiny amount of system time.

Signed-off-by: Tobias Stoeckmann <[email protected]>
  • Loading branch information
stoeckmann committed Sep 24, 2024
1 parent dccdc0b commit f474c05
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tools/modinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ static bool is_module_filename(const char *name)
{
struct stat st;

if (stat(name, &st) == 0 && S_ISREG(st.st_mode) &&
path_ends_with_kmod_ext(name, strlen(name)))
if (path_ends_with_kmod_ext(name, strlen(name)) && stat(name, &st) == 0 &&
S_ISREG(st.st_mode))
return true;

return false;
Expand Down

0 comments on commit f474c05

Please sign in to comment.