Skip to contentSkip to conversation

software node: allow passing reference args to PROPERTY_ENTRY_REF()

PATCH Applied Dmitry Torokhov 3 participants 3 messages Jun 7 – Jun 10

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 software node: allow passing reference args to PROPERTY_ENTRY_REF()

When dynamically creating software nodes and properties for subsequent use with software_node_register() current implementation of PROPERTY_ENTRY_REF() is not suitable because it creates a temporary instance of struct software_node_ref_args on stack which will later disappear, and software_node_register() only does shallow copy of properties.

Fix this by allowing to pass address of reference arguments structure directly into PROPERTY_ENTRY_REF(), so that caller can manage lifetime of the object properly.

---

This is pulled from a larger series dealing with breakage on Geode:
https://patch.msgid.link/[email protected]

v3: addressed Andy's comments about formatting and commit description.

 include/linux/property.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
include/linux/property.h +7 -1
index e30ef23a9af3..14c304db4664 100644
@@ -471,12 +471,18 @@ struct property_entry {
 #define PROPERTY_ENTRY_STRING(_name_, _val_)				\
 	__PROPERTY_ENTRY_ELEMENT(_name_, str, STRING, _val_)
 
+#define __PROPERTY_ENTRY_REF_ARGS(_ref_, ...)				\
+	_Generic(_ref_,							\
+		 const struct software_node_ref_args *: _ref_,		\
+		 struct software_node_ref_args *: _ref_,		\
+		 default: &SOFTWARE_NODE_REFERENCE(_ref_, ##__VA_ARGS__))
+
 #define PROPERTY_ENTRY_REF(_name_, _ref_, ...)				\
 (struct property_entry) {						\
 	.name = _name_,							\
 	.length = sizeof(struct software_node_ref_args),		\
 	.type = DEV_PROP_REF,						\
-	{ .pointer = &SOFTWARE_NODE_REFERENCE(_ref_, ##__VA_ARGS__), },	\
+	{ .pointer = __PROPERTY_ENTRY_REF_ARGS(_ref_, ##__VA_ARGS__) },	\
 }
 
 #define PROPERTY_ENTRY_BOOL(_name_)		\
Signature · 5 lines
2.54.0.1032.g2f8565e1d1-goog


-- 
Dmitry
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Dmitry Torokhov

When dynamically creating software nodes and properties for subsequent use with software_node_register() current implementation of PROPERTY_ENTRY_REF() is not suitable because it creates a temporary instance of struct software_node_ref_args on stack which will later disappear, and software_node_register() only does shallow copy of properties.

Fix this by allowing to pass address of reference arguments structure directly into PROPERTY_ENTRY_REF(), so that caller can manage lifetime of the object properly.

Now it looks nice and good, thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Applied
#2 lore raw
In reply to Dmitry Torokhov
Quoted 1 line · Dmitry Torokhov

[PATCH] software node: allow passing reference args to PROPERTY_ENTRY_REF()

Applied, thanks!

Branch: driver-core-testing
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git

[1/1] software node: allow passing reference args to PROPERTY_ENTRY_REF()

      commit: fe221742e388

The patch will appear in the next linux-next integration (typically within 24 hours on weekdays).

The patch is in the driver-core-testing branch and will be promoted to driver-core-next after validation.