From: Tobias Stoeckmann Date: Mon, 24 Feb 2025 19:11:14 +0000 (+0100) Subject: depmod: refactor depmod_modules_search_dir X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=72029c4293c156af855eaa959aa4319d069a0673;p=thirdparty%2Fkmod.git depmod: refactor depmod_modules_search_dir The function depmod_modules_search_dir is supposed to ignore all errors encountered during directory entry iteration. This was not true for out of memory conditions, which could also lead to wrong output. Clarify this fact by turning it void and adjust callers accordingly. Signed-off-by: Tobias Stoeckmann Link: https://github.com/kmod-project/kmod/pull/296 Signed-off-by: Lucas De Marchi --- diff --git a/tools/depmod.c b/tools/depmod.c index 5db9701c..5d7e628d 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -1343,10 +1343,10 @@ static bool should_exclude_dir(const struct cfg *cfg, const char *name) return false; } -static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, struct strbuf *path) +static void depmod_modules_search_dir(struct depmod *depmod, DIR *d, struct strbuf *path) { struct dirent *de; - int err = 0, dfd = dirfd(d); + int dfd = dirfd(d); const size_t baselen = strbuf_used(path); while ((de = readdir(d)) != NULL) { @@ -1364,7 +1364,6 @@ static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, struct strbu if (!strbuf_pushchars(path, name) || /* Ensure space for (possible) '/' */ !strbuf_reserve_extra(path, 1)) { - err = -ENOMEM; ERR("No memory\n"); continue; } @@ -1405,27 +1404,22 @@ static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, struct strbu } strbuf_pushchar(path, '/'); - err = depmod_modules_search_dir(depmod, subdir, path); + depmod_modules_search_dir(depmod, subdir, path); closedir(subdir); } else { - err = depmod_modules_search_file(depmod, baselen, namelen, - strbuf_str(path)); - } - - if (err < 0) { - ERR("failed %s: %s\n", strbuf_str(path), strerror(-err)); - err = 0; /* ignore errors */ + int err = depmod_modules_search_file(depmod, baselen, namelen, + strbuf_str(path)); + if (err < 0) + ERR("failed %s: %s\n", strbuf_str(path), strerror(-err)); } } - - return err; } static int depmod_modules_search_path(struct depmod *depmod, const char *path) { DECLARE_STRBUF_WITH_STACK(s_path_buf, 256); DIR *d; - int err; + int err = 0; d = opendir(path); if (d == NULL) { @@ -1439,7 +1433,7 @@ static int depmod_modules_search_path(struct depmod *depmod, const char *path) goto out; } - err = depmod_modules_search_dir(depmod, d, &s_path_buf); + depmod_modules_search_dir(depmod, d, &s_path_buf); out: closedir(d); return err;