]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: remove strbuf_reserve_extra call
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 24 Feb 2025 19:14:37 +0000 (20:14 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 7 Mar 2025 04:57:37 +0000 (22:57 -0600)
The strbuf_reserve_extra call is only left for a possible '/' addition,
which only occurs before depmod_modules_search_dir recursively calls
itself.

By adding the slash at the start, it also simplifies
depmod_modules_search_path which does not have to do this before calling
depmod_modules_search_dir on its own.

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 5d7e628d13208b0978bc3bed8b786dc73ad9bc38..1fc27f9c2711d9e2510f5d5c52764f845528ff2c 100644 (file)
@@ -1347,7 +1347,13 @@ static void depmod_modules_search_dir(struct depmod *depmod, DIR *d, struct strb
 {
        struct dirent *de;
        int dfd = dirfd(d);
-       const size_t baselen = strbuf_used(path);
+       size_t baselen;
+
+       if (!strbuf_pushchar(path, '/')) {
+               ERR("No memory\n");
+               return;
+       }
+       baselen = strbuf_used(path);
 
        while ((de = readdir(d)) != NULL) {
                const char *name = de->d_name;
@@ -1361,9 +1367,7 @@ static void depmod_modules_search_dir(struct depmod *depmod, DIR *d, struct strb
 
                namelen = strlen(name);
 
-               if (!strbuf_pushchars(path, name) ||
-                   /* Ensure space for (possible) '/' */
-                   !strbuf_reserve_extra(path, 1)) {
+               if (!strbuf_pushchars(path, name)) {
                        ERR("No memory\n");
                        continue;
                }
@@ -1403,7 +1407,6 @@ static void depmod_modules_search_dir(struct depmod *depmod, DIR *d, struct strb
                                continue;
                        }
 
-                       strbuf_pushchar(path, '/');
                        depmod_modules_search_dir(depmod, subdir, path);
                        closedir(subdir);
                } else {
@@ -1428,7 +1431,7 @@ static int depmod_modules_search_path(struct depmod *depmod, const char *path)
                return err;
        }
 
-       if (!strbuf_pushchars(&s_path_buf, path) || !strbuf_pushchar(&s_path_buf, '/')) {
+       if (!strbuf_pushchars(&s_path_buf, path)) {
                err = -ENOMEM;
                goto out;
        }