From: Tobias Stoeckmann Date: Tue, 24 Sep 2024 20:37:26 +0000 (+0200) Subject: modinfo: Avoid unneeded system call X-Git-Tag: v34~285 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6b539ed83652ad2bad6a627b17ddc49d2c1d895a;p=thirdparty%2Fkmod.git modinfo: Avoid unneeded system call 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 Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/154 Signed-off-by: Lucas De Marchi --- diff --git a/tools/modinfo.c b/tools/modinfo.c index 865bbec7..f1323c50 100644 --- a/tools/modinfo.c +++ b/tools/modinfo.c @@ -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;