]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: use stack strbuf where possible
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 24 Feb 2025 18:49:40 +0000 (19:49 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 7 Mar 2025 04:57:37 +0000 (22:57 -0600)
The deps bin output uses a strbuf. A size of 2048 covers all cases
on current Arch Linux (max used size is 1548) and removes heap
allocations.

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 0126124260a02344725d10d4a8da5977b8bf2ac6..dcc7acbeb481532fbc94ab23bac7fe1e6c93982d 100644 (file)
@@ -2157,10 +2157,10 @@ end:
 
 static int output_deps_bin(struct depmod *depmod, FILE *out)
 {
+       DECLARE_STRBUF_WITH_STACK(sbuf, 2048);
        struct index_node *idx;
        size_t i;
        struct array array;
-       struct strbuf sbuf;
 
        if (out == stdout)
                return 0;
@@ -2170,7 +2170,6 @@ static int output_deps_bin(struct depmod *depmod, FILE *out)
                return -ENOMEM;
 
        array_init(&array, 64);
-       strbuf_init(&sbuf);
 
        for (i = 0; i < depmod->modules.count; i++) {
                const struct mod *mod = depmod->modules.array[i];
@@ -2206,7 +2205,6 @@ static int output_deps_bin(struct depmod *depmod, FILE *out)
                        WRN("duplicate module deps:\n%s\n", line);
        }
 
-       strbuf_release(&sbuf);
        array_free_array(&array);
        index_write(idx, out);
        index_destroy(idx);