Add the __counted_by_ptr() compiler attribute to 'array' to improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE.
Signed-off-by: Thorsten Blum <[email protected]> --- lib/string_helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 6a8db441b6fd..98d6ed0eaab7 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -805,7 +805,7 @@ void kfree_strarray(char **array, size_t n) EXPORT_SYMBOL_GPL(kfree_strarray); struct strarray { - char **array; + char **array __counted_by_ptr(n); size_t n; }; @@ -824,13 +824,13 @@ char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n) if (!ptr) return ERR_PTR(-ENOMEM); + ptr->n = n; ptr->array = kasprintf_strarray(GFP_KERNEL, prefix, n); if (!ptr->array) { devres_free(ptr); return ERR_PTR(-ENOMEM); } - ptr->n = n; devres_add(dev, ptr); return ptr->array;

