Skip to contentSkip to conversation

lib/string_helpers: add allocated strarray to device resource.

PATCH In review Puyou Lu 3 participants 5 messages May 6, 2022 – May 12, 2022

Subsystems (2)
lore
Share & tools
lore

Puyou Lu

author
#0 lore raw

PATCH 1/1 lib/string_helpers: add allocated strarray to device resource.

This is a must to automatically release strarray when the device disappears.

---
 lib/string_helpers.c | 1 +
 1 file changed, 1 insertion(+)
lib/string_helpers.c +1 -0
index 4f877e9551d5..b4497c068172 100644
@@ -757,6 +757,7 @@ char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n)
 		return ERR_PTR(-ENOMEM);
 	}
 
+	devres_add(dev, ptr);
 	return ptr->array;
 }
 EXPORT_SYMBOL_GPL(devm_kasprintf_strarray);
Signature · 1 line
2.17.1
author
#1 lore raw

Re: [PATCH] lib/string_helpers: add allocated strarray to device

Hello:
I think this should be added, am I got wrong?

author
#2 lore raw

PATCH 1/1 lib/string_helpers: add allocated strarray to device's resource list.

This is a must to automatically release strarray when the device disappears.

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

Re: [PATCH] lib/string_helpers: add allocated strarray to device's resource list.

Quoted 3 lines · Puyou Lu

This is a must to automatically release strarray when the device disappears.

Thanks for your patch!

First of all, since this is a v2 of it, you need to update the subject to reflect this and add a changelog after the cutter '--- ' line below.
Second, because this is the fix, please add a Fixes tag.

Quoted 10 lines
---
 lib/string_helpers.c | 3 +++
 1 file changed, 3 insertions(+)
lib/string_helpers.c +0 -0
index 4f877e9551d5..5ed3beb066e6 100644

lib/string_helpers.c char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n) · line 761

Quoted 5 lines
lib/string_helpers.c +2 -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);

The code seems correct, good catch!

Quoted 6 lines
lib/string_helpers.c +0 -1
        return ptr->array;
 }
 EXPORT_SYMBOL_GPL(devm_kasprintf_strarray);
--

2.17.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko