From: Tobias Stoeckmann Date: Mon, 24 Feb 2025 19:14:37 +0000 (+0100) Subject: depmod: remove strbuf_reserve_extra call X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3b9f13937c39755b2345fc3e617e2b7df9478cc3;p=thirdparty%2Fkmod.git depmod: remove strbuf_reserve_extra call 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 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 5d7e628d..1fc27f9c 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -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; }