Skip to contentSkip to conversation

lib/string_helpers: fix not adding strarray to device's resource list.

PATCH In review Puyou Lu 4 participants 4 messages May 6, 2022 – May 8, 2022

Subsystems (2)
lore
Share & tools
lore

Puyou Lu

author
#0 lore raw

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.

Fixes acdb89b6c87a ("lib/string_helpers: Introduce managed variant of kasprintf_strarray()")

---

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
index 4f877e9551d5..5ed3beb066e6 100644
@@ -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
Reviewed-by on v2 1/1
#1 lore raw
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()")

---

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
index 4f877e9551d5..5ed3beb066e6 100644
@@ -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
maintainer
#2 lore raw
In reply to Puyou Lu
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?

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);
#3 lore raw
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