]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
modinfo: Avoid unneeded system call
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 24 Sep 2024 20:37:26 +0000 (22:37 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Sat, 28 Sep 2024 04:12:45 +0000 (23:12 -0500)
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 <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/154
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
tools/modinfo.c

index 865bbec70f76b4017c96e73fb90b2b397954cb6a..f1323c50aaa0a467b3f24c7c60e90a0f9ecc80f7 100644 (file)
@@ -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;