diff options
| author | Thorsten Blum <thorsten.blum@linux.dev> | 2026-04-15 14:25:43 +0200 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-05-13 10:54:08 -0700 |
| commit | 233e1ab980269394bfa78191ac12446cc6a22683 (patch) | |
| tree | a06f80a00910eb96aebd9889618c25a38fa56f68 /lib/string_helpers.c | |
| parent | e0251b5e07f313619c15054de69bee10678da3a6 (diff) | |
| download | linux-next-233e1ab980269394bfa78191ac12446cc6a22683.tar.gz linux-next-233e1ab980269394bfa78191ac12446cc6a22683.zip | |
lib/string_helpers: drop redundant allocation in kasprintf_strarray
kasprintf_strarray() returns an array of N strings and kfree_strarray()
also frees N entries. However, kasprintf_strarray() currently allocates
N+1 char pointers. Allocate exactly N pointers instead of N+1.
Also update the kernel-doc for @n.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://patch.msgid.link/20260415122542.370926-4-thorsten.blum@linux.dev
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'lib/string_helpers.c')
| -rw-r--r-- | lib/string_helpers.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 169eaf583494..6a8db441b6fd 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -752,7 +752,7 @@ EXPORT_SYMBOL_GPL(kstrdup_and_replace); * kasprintf_strarray - allocate and fill array of sequential strings * @gfp: flags for the slab allocator * @prefix: prefix to be used - * @n: amount of lines to be allocated and filled + * @n: number of strings to be allocated and filled * * Allocates and fills @n strings using pattern "%s-%zu", where prefix * is provided by caller. The caller is responsible to free them with @@ -765,7 +765,7 @@ char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n) char **names; size_t i; - names = kcalloc(n + 1, sizeof(char *), gfp); + names = kcalloc(n, sizeof(char *), gfp); if (!names) return NULL; |
