]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
device property: initialize the remaining fields of fwnode_handle in fwnode_init()
authorBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Mon, 11 May 2026 07:49:26 +0000 (09:49 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Mon, 11 May 2026 19:55:35 +0000 (21:55 +0200)
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 uninitialized 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>
Link: https://patch.msgid.link/20260511074927.9473-1-bartosz.golaszewski@oss.qualcomm.com
[ Fix typo in commit message. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
include/linux/fwnode.h

index 80b38fbf2121c615cb216245bffa878aa5a531ca..c30a9baafc0d99edbc6482a01b388006e74bc722 100644 (file)
@@ -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,