Linux ACPI
 help / color / mirror / Atom feed
* [PATCH] software node: allow passing reference args to PROPERTY_ENTRY_REF()
@ 2026-06-07  3:51 Dmitry Torokhov
  2026-06-09  6:04 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Torokhov @ 2026-06-07  3:51 UTC (permalink / raw)
  To: Danilo Krummrich, Greg Kroah-Hartman
  Cc: Andy Shevchenko, Daniel Scally, Heikki Krogerus, Sakari Ailus,
	Rafael J. Wysocki, linux-acpi, driver-core, linux-kernel

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.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

This is pulled from a larger series dealing with breakage on Geode:
https://patch.msgid.link/20260329-property-gpio-fix-v2-0-3cca5ba136d8@gmail.com

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

 include/linux/property.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/property.h b/include/linux/property.h
index e30ef23a9af3..14c304db4664 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -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_)		\
-- 
2.54.0.1032.g2f8565e1d1-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] software node: allow passing reference args to PROPERTY_ENTRY_REF()
  2026-06-07  3:51 [PATCH] software node: allow passing reference args to PROPERTY_ENTRY_REF() Dmitry Torokhov
@ 2026-06-09  6:04 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2026-06-09  6:04 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Danilo Krummrich, Greg Kroah-Hartman, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki, linux-acpi,
	driver-core, linux-kernel

On Sat, Jun 06, 2026 at 08:51:29PM -0700, Dmitry Torokhov wrote:
> 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!
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-09  6:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-07  3:51 [PATCH] software node: allow passing reference args to PROPERTY_ENTRY_REF() Dmitry Torokhov
2026-06-09  6:04 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox