From: Tobias Stoeckmann Date: Mon, 24 Feb 2025 18:49:40 +0000 (+0100) Subject: depmod: use stack strbuf where possible X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5350ef99018de5310650f65683ef7037cf87b14c;p=thirdparty%2Fkmod.git depmod: use stack strbuf where possible 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 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 01261242..dcc7acbe 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -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);