From 4bf91d1c8761206c70cab17bb03f5693d3297ccf Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Wed, 23 Dec 2020 09:57:04 +0800 Subject: [PATCH 1/3] Revert "device property: Keep secondary firmware node secondary by type" While the commit d5dcce0c414f ("device property: Keep secondary firmware node secondary by type") describes everything correct in its commit message the change it made does the opposite and original commit c15e1bdda436 ("device property: Fix the secondary firmware node handling in set_primary_fwnode()") was fully correct. Thus, revert the former one here and improve documentation in the next patch. Fixes: d5dcce0c414f ("device property: Keep secondary firmware node secondary by type") Signed-off-by: Bard Liao --- drivers/base/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index d661ada1518fb4..2d1e7bab8fbde4 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4278,7 +4278,7 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode) if (fwnode_is_primary(fn)) { dev->fwnode = fn->secondary; if (!(parent && fn == parent->fwnode)) - fn->secondary = ERR_PTR(-ENODEV); + fn->secondary = NULL; } else { dev->fwnode = NULL; } From 1ff85ed58c35ebb5704afedc67badb318242fb44 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Wed, 23 Dec 2020 10:55:03 +0800 Subject: [PATCH 2/3] device property: add description of fwnode cases There are only four valid fwnode cases which are - primary --> secondary --> -ENODEV - primary --> NULL - secondary --> -ENODEV - NULL dev->fwnode should be converted between the 4 cases above no matter how/when set_primary_fwnode() and set_secondary_fwnode() are called. Describe it in the code so people will keep it in mind. Signed-off-by: Bard Liao --- drivers/base/core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 2d1e7bab8fbde4..7dc367dba17472 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4259,6 +4259,12 @@ static inline bool fwnode_is_primary(struct fwnode_handle *fwnode) * * Set the device's firmware node pointer to @fwnode, but if a secondary * firmware node of the device is present, preserve it. + * + * Valid fwnode cases are: + * - primary --> secondary --> -ENODEV + * - primary --> NULL + * - secondary --> -ENODEV + * - NULL */ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode) { @@ -4277,6 +4283,7 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode) } else { if (fwnode_is_primary(fn)) { dev->fwnode = fn->secondary; + /* Set fn->secondary = NULL to keep fn as a primary fwnode */ if (!(parent && fn == parent->fwnode)) fn->secondary = NULL; } else { From d7175bc19d8f8d154f9dd27b5af54edb97a21d54 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Wed, 23 Dec 2020 09:35:40 +0800 Subject: [PATCH 3/3] Revert "soundwire: slave: force fwnode as primary" The fwnode->secondary pointer is modified by set_primary_fwnode(). We don't need to set fwnode->secondary = NULL if commit d5dcce0c414f ("device property: Keep secondary firmware node secondary by type") is reversed. This reverts commit 03b55f5be6ed6a040877c836a13f3077e14e4913. Signed-off-by: Bard Liao --- drivers/soundwire/slave.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/soundwire/slave.c b/drivers/soundwire/slave.c index 80d11c0b01a796..180f38bd003bca 100644 --- a/drivers/soundwire/slave.c +++ b/drivers/soundwire/slave.c @@ -35,6 +35,7 @@ int sdw_slave_add(struct sdw_bus *bus, /* Initialize data structure */ memcpy(&slave->id, id, sizeof(*id)); slave->dev.parent = bus->dev; + slave->dev.fwnode = fwnode; if (id->unique_id == SDW_IGNORED_UNIQUE_ID) { /* name shall be sdw:link:mfg:part:class */ @@ -52,9 +53,6 @@ int sdw_slave_add(struct sdw_bus *bus, slave->dev.of_node = of_node_get(to_of_node(fwnode)); slave->dev.type = &sdw_slave_type; slave->dev.groups = sdw_slave_status_attr_groups; - /* make sure fwnode is a primary fwnode */ - fwnode->secondary = NULL; - set_primary_fwnode(&slave->dev, fwnode); slave->bus = bus; slave->status = SDW_SLAVE_UNATTACHED; init_completion(&slave->enumeration_complete);