[PATCH v2 02/10] lib: string_helpers: implement a CLASS() for string arrays
From: Bartosz Golaszewski
Date: Fri Nov 13 2026 - 14:31:36 EST
Provide a CLASS() for managed arrays of strings. It can be used for
automated release of temporary string arrays when they go out of scope.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
---
include/linux/string_helpers.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
index c9f08066439bdd33cc26e2054dbe1ba2e867aee7..4db73bc7d4623cf45954cc8794c5baff6fb23241 100644
--- a/include/linux/string_helpers.h
+++ b/include/linux/string_helpers.h
@@ -3,6 +3,7 @@
#define _LINUX_STRING_HELPERS_H_
#include <linux/bits.h>
+#include <linux/cleanup.h>
#include <linux/ctype.h>
#include <linux/string_choices.h>
#include <linux/string.h>
@@ -124,6 +125,12 @@ struct kstrarray {
char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n);
void kfree_strarray(char **array, size_t n);
+DEFINE_CLASS(strarray,
+ struct kstrarray,
+ kfree_strarray(_T.array, _T.n),
+ ((struct kstrarray){ .array = array, .n = size }),
+ char **array, size_t size);
+
char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n);
#endif
--
2.47.3