The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] device property: initialize the remaining fields of fwnode_handle in fwnode_init()
@ 2026-05-11  7:49 Bartosz Golaszewski
  2026-05-11 19:58 ` Danilo Krummrich
  0 siblings, 1 reply; 2+ messages in thread
From: Bartosz Golaszewski @ 2026-05-11  7:49 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Saravana Kannan, Rob Herring
  Cc: linux-acpi, driver-core, linux-kernel, brgl, Bartosz Golaszewski,
	stable

If a firmware node is allocated on the stack (for instance: temporary
software node whose life-time we control) or on the heap - but using a
non-zeroing allocation function - and initialized using fwnode_init(),
its secondary pointer will contain uninitalized memory which likely will
be neither NULL nor IS_ERR() and so may end up being dereferenced (for
example: in dev_to_swnode()). Set fwnode->secondary to NULL on
initialization. While at it: initialize the remaining fields of struct
fwnode_handle too just to be sure.

Cc: stable@vger.kernel.org
Fixes: 01bb86b380a3 ("driver core: Add fwnode_init()")
Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
Changes in v2:
- initialize all remaining fields in struct fwnode_handle too

 include/linux/fwnode.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index 80b38fbf2121..c30a9baafc0d 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -208,9 +208,12 @@ struct fwnode_operations {
 static inline void fwnode_init(struct fwnode_handle *fwnode,
 			       const struct fwnode_operations *ops)
 {
+	fwnode->secondary = NULL;
 	fwnode->ops = ops;
+	fwnode->dev = NULL;
 	INIT_LIST_HEAD(&fwnode->consumers);
 	INIT_LIST_HEAD(&fwnode->suppliers);
+	fwnode->flags = 0;
 }
 
 static inline void fwnode_set_flag(struct fwnode_handle *fwnode,
-- 
2.47.3


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

end of thread, other threads:[~2026-05-11 19:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11  7:49 [PATCH v2] device property: initialize the remaining fields of fwnode_handle in fwnode_init() Bartosz Golaszewski
2026-05-11 19:58 ` Danilo Krummrich

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