From 5350ef99018de5310650f65683ef7037cf87b14c Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Mon, 24 Feb 2025 19:49:40 +0100 Subject: [PATCH] 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 --- tools/depmod.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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); -- 2.47.2