]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: refactor depmod_modules_search_dir
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 24 Feb 2025 19:11:14 +0000 (20:11 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 7 Mar 2025 04:57:37 +0000 (22:57 -0600)
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 <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/296
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
tools/depmod.c

index 5db9701c12060df2c2cc7e91abac4d9f11b9bcae..5d7e628d13208b0978bc3bed8b786dc73ad9bc38 100644 (file)
@@ -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;