lib/string_helpers: fix not adding strarray to device's resource list.
Subsystems (2)
PATCH v2 1/1 lib/string_helpers: fix not adding strarray to device's resource list.
Add allocated strarray to device's resource list. This is a must to automatically release strarray when the device disappears.
---
Change since v1:
also set 'n' of strarray https://lore.kernel.org/lkml/[email protected]/
--- lib/string_helpers.c | 3 +++ 1 file changed, 3 insertions(+)
lib/string_helpers.c +3 -0
@@ -757,6 +757,9 @@ char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n)return ERR_PTR (-ENOMEM ); } + ptr->n = n; +devres_add (dev, ptr); +return ptr->array; }EXPORT_SYMBOL_GPL (devm_kasprintf_strarray);
Signature · 1 line
2.17.1
Quoted 3 lines · Puyou Lu
Add allocated strarray to device's resource list. This is a must to automatically release strarray when the device disappears.
LGTM,
Thanks!
Quoted 29 lines
Fixes acdb89b6c87a ("lib/string_helpers: Introduce managed variant of kasprintf_strarray()")Signed-off-by Puyou Lu <[email protected]>---
Change since v1:
also set 'n' of strarray https://lore.kernel.org/lkml/[email protected]/--- lib/string_helpers.c | 3 +++ 1 file changed, 3 insertions(+)lib/string_helpers.c +3
-1@@ -757,6 +757,9 @@ char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n)return ERR_PTR (-ENOMEM ); } + ptr->n = n; +devres_add (dev, ptr); +return ptr->array; }EXPORT_SYMBOL_GPL (devm_kasprintf_strarray); --2.17.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andrew Morton
maintainerQuoted 2 lines · On Fri, 6 May 2022 15:36:22 +0800 Puyou Lu <[email protected]> wrote:
Add allocated strarray to device's resource list. This is a must to automatically release strarray when the device disappears.
So at present we have a memory leak?
Is this likely to be serious enough to justify backporting the fix into -stable kernels?
Quoted 12 lines
lib/string_helpers.c +3
-0@@ -757,6 +757,9 @@ char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n)return ERR_PTR (-ENOMEM ); } + ptr->n = n; +devres_add (dev, ptr); +return ptr->array; }EXPORT_SYMBOL_GPL (devm_kasprintf_strarray);
Quoted 6 lines · Andrew Morton
Quoted 2 lines · On Fri, 6 May 2022 15:36:22 +0800 Puyou Lu <[email protected]> wrote:
Add allocated strarray to device's resource list. This is a must to automatically release strarray when the device disappears.
So at present we have a memory leak?
Yes.
Quoted 2 lines
Is this likely to be serious enough to justify backporting the fix into -stable kernels?
I think so, however there are only few drivers are using it, hence it's serious, but rare.
Signature · 2 lines
With Best Regards, Andy Shevchenko