device property: Fix the secondary firmware node handling in set_primary_fwnode()
Subsystems (3)
PATCH 1/1 device property: Fix the secondary firmware node handling in set_primary_fwnode()
When the primary firmware node pointer is removed from a device (set to NULL) the secondary firmware node pointer, when it exists, is made the primary node for the device. However, the secondary firmware node pointer of the original primary firmware node is never cleared (set to NULL).
To avoid situation where the secondary firmware node pointer is pointing to a non-existing object, clearing it properly when the primary node is removed from a device in set_primary_fwnode().
--- drivers/base/core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/base/core.c +8 -4
@@ -4264,9 +4264,9 @@ static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)*/ void set_primary_fwnode (struct device *dev,struct fwnode_handle *fwnode) { -if (fwnode) { -struct fwnode_handle *fn = dev->fwnode; +struct fwnode_handle *fn = dev->fwnode; +if (fwnode) {if (fwnode_is_primary (fn)) fn = fn->secondary;
@@ -4276,8 +4276,12 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode) } dev->fwnode = fwnode; }else { - dev->fwnode =fwnode_is_primary (dev->fwnode) ? - dev->fwnode->secondary :NULL ; +if (fwnode_is_primary (fn)) { + dev->fwnode = fn->secondary; + fn->secondary =NULL ; + }else { + dev->fwnode =NULL ; + } } }EXPORT_SYMBOL_GPL (set_primary_fwnode);
Signature · 1 line
2.28.0
Quoted 41 lines · Heikki Krogerus
When the primary firmware node pointer is removed from a device (set to NULL) the secondary firmware node pointer, when it exists, is made the primary node for the device. However, the secondary firmware node pointer of the original primary firmware node is never cleared (set to NULL).
To avoid situation where the secondary firmware node pointer is pointing to a non-existing object, clearing it properly when the primary node is removed from a device in
set_primary_fwnode().Fixes 97badf873ab6 ("device property: Make it possible to use secondary firmware nodes")Signed-off-by Heikki Krogerus <[email protected]>--- drivers/base/core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/base/core.c +2
-4@@ -4264,9 +4264,9 @@ static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)*/ void set_primary_fwnode (struct device *dev,struct fwnode_handle *fwnode) { -if (fwnode) { -struct fwnode_handle *fn = dev->fwnode; +struct fwnode_handle *fn = dev->fwnode; +if (fwnode) {if (fwnode_is_primary (fn)) fn = fn->secondary;@@ -4276,8 +4276,12 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode) } dev->fwnode = fwnode; }else { - dev->fwnode =fwnode_is_primary (dev->fwnode) ? - dev->fwnode->secondary :NULL ;
drivers/base/core.c void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
Quoted 10 lines
drivers/base/core.c +6
-1+if (fwnode_is_primary (fn)) { + dev->fwnode = fn->secondary; + fn->secondary =NULL ; + }else { + dev->fwnode =NULL ; + } } }EXPORT_SYMBOL_GPL (set_primary_fwnode); --
Applied as 5.9-rc material, thanks!