[PATCH v2 01/10] lib: string_helpers: export and rename struct strarray

From: Bartosz Golaszewski

Date: Fri Nov 13 2026 - 11:20:51 EST


Ahead of introducing a CLASS() for string arrays, make the existing
struct strarray public in linux/string_helpers.h. Rename it to kstrarray
to avoid any potential conflicts in the future and make it clear, it's a
kernel type.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
---
include/linux/string_helpers.h | 5 +++++
lib/string_helpers.c | 9 ++-------
2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
index 3fb88a1e989833ad5ea1a46858efa16e3971bf08..c9f08066439bdd33cc26e2054dbe1ba2e867aee7 100644
--- a/include/linux/string_helpers.h
+++ b/include/linux/string_helpers.h
@@ -116,6 +116,11 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp);

char *kstrdup_and_replace(const char *src, char old, char new, gfp_t gfp);

+struct kstrarray {
+ char **array __counted_by_ptr(n);
+ size_t n;
+};
+
char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n);
void kfree_strarray(char **array, size_t n);

diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 98d6ed0eaab7e9f3d54e420c404629a28b925bf4..8ec7ff6dac1212fe8a1f242654944ba6e5568e20 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -804,21 +804,16 @@ void kfree_strarray(char **array, size_t n)
}
EXPORT_SYMBOL_GPL(kfree_strarray);

-struct strarray {
- char **array __counted_by_ptr(n);
- size_t n;
-};
-
static void devm_kfree_strarray(struct device *dev, void *res)
{
- struct strarray *array = res;
+ struct kstrarray *array = res;

kfree_strarray(array->array, array->n);
}

char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n)
{
- struct strarray *ptr;
+ struct kstrarray *ptr;

ptr = devres_alloc(devm_kfree_strarray, sizeof(*ptr), GFP_KERNEL);
if (!ptr)

--
2.47.3