lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening linux-cve-announce PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Sat, 06 Nov 2021 00:34:51 -0700 From: Joe Perches <joe@...ches.com> To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>, Bartosz Golaszewski <brgl@...ev.pl>, Jianqun Xu <jay.xu@...k-chips.com>, Linus Walleij <linus.walleij@...aro.org>, Sai Krishna Potthuri <lakshmi.sai.krishna.potthuri@...inx.com>, Andrew Morton <akpm@...ux-foundation.org>, linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org, linux-rockchip@...ts.infradead.org Cc: Bamvor Jian Zhang <bamv2005@...il.com>, Andrew Lunn <andrew@...n.ch>, Gregory Clement <gregory.clement@...tlin.com>, Sebastian Hesselbarth <sebastian.hesselbarth@...il.com>, Heiko Stuebner <heiko@...ech.de>, Patrice Chotard <patrice.chotard@...s.st.com>, Michal Simek <michal.simek@...inx.com>, Andy Shevchenko <andy@...nel.org> Subject: Re: [PATCH v1 01/19] lib/string_helpers: Introduce kasprintf_strarray() On Fri, 2021-11-05 at 14:42 +0200, Andy Shevchenko wrote: > We have a few users already that basically want to have array of > sequential strings to be allocated and filled. > > Provide a helper for them (basically adjusted version from gpio-mockup.c). I think this is overkill and unnecessary bloat for the number of actual or possible in-tree uses. The devm_ variant too. And it'd be useful to have an 0/n patch cover letter describing why the patchset is useful so I could reply to that instead of the 1/n. > diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h [] > @@ -100,6 +100,7 @@ char *kstrdup_quotable(const char *src, gfp_t gfp); > char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp); > char *kstrdup_quotable_file(struct file *file, gfp_t gfp); > > +char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n); > void kfree_strarray(char **array, size_t n); > > #endif > diff --git a/lib/string_helpers.c b/lib/string_helpers.c [] > @@ -674,6 +674,39 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp) > } > EXPORT_SYMBOL_GPL(kstrdup_quotable_file); > > +/** > + * 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 > + * > + * Allocates and fills @n strings using pattern "%s-%zu", where prefix > + * is provided by caller. The caller is responsible to free them with > + * kfree_strarray() after use. > + * > + * Returns array of strings or NULL when memory can't be allocated. > + */ > +char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n) > +{ > + char **names; > + size_t i; > + > + names = kcalloc(n + 1, sizeof(char *), gfp); > + if (!names) > + return NULL; > + > + for (i = 0; i < n; i++) { > + names[i] = kasprintf(gfp, "%s-%zu", prefix, i); > + if (!names[i]) { > + kfree_strarray(names, i); > + return NULL; > + } > + } > + > + return names; > +} > +EXPORT_SYMBOL_GPL(kasprintf_strarray); > + > /** > * kfree_strarray - free a number of dynamically allocated strings contained > * in an array and the array itself
Powered by blists - more mailing lists