* [PATCH v10 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device()
2026-07-17 14:51 [PATCH v10 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
@ 2026-07-17 14:51 ` Herve Codina
2026-07-17 14:51 ` [PATCH v10 04/10] cxl/test: Use device_set_node() Herve Codina
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Herve Codina @ 2026-07-17 14:51 UTC (permalink / raw)
To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Bjorn Helgaas, David Rhodes, Richard Fitzgerald, Charles Keepax,
Linus Walleij, Len Brown, Andy Shevchenko, Daniel Scally,
Heikki Krogerus, Sakari Ailus, Davidlohr Bueso, Jonathan Cameron,
Dave Jiang, Alison Schofield, Vishal Verma, Dan Williams,
Ira Weiny, Li Ming, Lizhi Hou, Herve Codina
Cc: driver-core, linux-kernel, linux-pci, linux-sound, patches,
linux-gpio, linux-acpi, linux-cxl, Allan Nielsen, Horatiu Vultur,
Daniel Machon, Steen Hegelund, Luca Ceresoli, Thomas Petazzoni,
stable, Ulf Hansson
Setting fwnode->dev is specific to fw_devlink.
In order to avoid having a direct 'fwnode->dev = dev;' in several
place in the kernel, introduce fw_devlink_set_device() helper to perform
this operation.
Having this helper allows to hide the fwnode devlink related stuff
behind the helper.
Cc: stable@vger.kernel.org
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
Cc stable because used by other patches with Fixes + Cc stable
---
include/linux/fwnode.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index 4e86e6990d28..31538f54b1ca 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -256,4 +256,10 @@ void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode);
void fw_devlink_refresh_fwnode(struct fwnode_handle *fwnode);
bool fw_devlink_is_strict(void);
+static inline void fw_devlink_set_device(struct fwnode_handle *fwnode,
+ struct device *dev)
+{
+ fwnode->dev = dev;
+}
+
#endif
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v10 04/10] cxl/test: Use device_set_node()
2026-07-17 14:51 [PATCH v10 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
2026-07-17 14:51 ` [PATCH v10 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
@ 2026-07-17 14:51 ` Herve Codina
2026-07-17 14:51 ` [PATCH v10 06/10] PCI: of: Use fw_devlink_set_device() Herve Codina
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Herve Codina @ 2026-07-17 14:51 UTC (permalink / raw)
To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Bjorn Helgaas, David Rhodes, Richard Fitzgerald, Charles Keepax,
Linus Walleij, Len Brown, Andy Shevchenko, Daniel Scally,
Heikki Krogerus, Sakari Ailus, Davidlohr Bueso, Jonathan Cameron,
Dave Jiang, Alison Schofield, Vishal Verma, Dan Williams,
Ira Weiny, Li Ming, Lizhi Hou, Herve Codina
Cc: driver-core, linux-kernel, linux-pci, linux-sound, patches,
linux-gpio, linux-acpi, linux-cxl, Allan Nielsen, Horatiu Vultur,
Daniel Machon, Steen Hegelund, Luca Ceresoli, Thomas Petazzoni,
Jonathan Cameron
The code set directly dev->fwnode.
Use the dedicated helper to perform this operation.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
tools/testing/cxl/test/cxl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
index ef92dd35e030..69da0727362b 100644
--- a/tools/testing/cxl/test/cxl.c
+++ b/tools/testing/cxl/test/cxl.c
@@ -1528,7 +1528,7 @@ static void mock_companion(struct acpi_device *adev, struct device *dev)
{
device_initialize(&adev->dev);
fwnode_init(&adev->fwnode, NULL);
- dev->fwnode = &adev->fwnode;
+ device_set_node(dev, &adev->fwnode);
adev->fwnode.dev = dev;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v10 06/10] PCI: of: Use fw_devlink_set_device()
2026-07-17 14:51 [PATCH v10 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
2026-07-17 14:51 ` [PATCH v10 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
2026-07-17 14:51 ` [PATCH v10 04/10] cxl/test: Use device_set_node() Herve Codina
@ 2026-07-17 14:51 ` Herve Codina
2026-07-17 14:51 ` [PATCH v10 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path Herve Codina
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Herve Codina @ 2026-07-17 14:51 UTC (permalink / raw)
To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Bjorn Helgaas, David Rhodes, Richard Fitzgerald, Charles Keepax,
Linus Walleij, Len Brown, Andy Shevchenko, Daniel Scally,
Heikki Krogerus, Sakari Ailus, Davidlohr Bueso, Jonathan Cameron,
Dave Jiang, Alison Schofield, Vishal Verma, Dan Williams,
Ira Weiny, Li Ming, Lizhi Hou, Herve Codina
Cc: driver-core, linux-kernel, linux-pci, linux-sound, patches,
linux-gpio, linux-acpi, linux-cxl, Allan Nielsen, Horatiu Vultur,
Daniel Machon, Steen Hegelund, Luca Ceresoli, Thomas Petazzoni,
stable
The code set directly fwnode.dev field.
Use the dedicated fw_devlink_set_device() helper to perform this
operation.
Cc: stable@vger.kernel.org
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
Cc stable because used by other patches with Fixes + Cc stable
---
drivers/pci/of.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 8b18c4ba845c..ee9eb384b377 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -803,7 +803,7 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)
* bus. Avoid any new device creation.
*/
of_node_set_flag(np, OF_POPULATED);
- np->fwnode.dev = &bridge->dev;
+ fw_devlink_set_device(&np->fwnode, &bridge->dev);
fwnode_dev_initialized(&np->fwnode, true);
ret = of_changeset_apply(cset);
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v10 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path
2026-07-17 14:51 [PATCH v10 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
` (2 preceding siblings ...)
2026-07-17 14:51 ` [PATCH v10 06/10] PCI: of: Use fw_devlink_set_device() Herve Codina
@ 2026-07-17 14:51 ` Herve Codina
2026-07-17 14:51 ` [PATCH v10 08/10] PCI: of: Set fwnode device of newly created PCI device nodes Herve Codina
2026-07-17 14:51 ` [PATCH v10 09/10] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node Herve Codina
5 siblings, 0 replies; 7+ messages in thread
From: Herve Codina @ 2026-07-17 14:51 UTC (permalink / raw)
To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Bjorn Helgaas, David Rhodes, Richard Fitzgerald, Charles Keepax,
Linus Walleij, Len Brown, Andy Shevchenko, Daniel Scally,
Heikki Krogerus, Sakari Ailus, Davidlohr Bueso, Jonathan Cameron,
Dave Jiang, Alison Schofield, Vishal Verma, Dan Williams,
Ira Weiny, Li Ming, Lizhi Hou, Herve Codina
Cc: driver-core, linux-kernel, linux-pci, linux-sound, patches,
linux-gpio, linux-acpi, linux-cxl, Allan Nielsen, Horatiu Vultur,
Daniel Machon, Steen Hegelund, Luca Ceresoli, Thomas Petazzoni,
stable
During the of_pci_make_host_bridge_node() call, an OF node is created
dynamically and its fwnode device (fwnode->dev) is set to the PCI root
bridge device using the fw_devlink_set_device(&np->fwnode, &bridge->dev)
call.
On removal, of_pci_remove_host_bridge_node() is called and calls
device_remove_of_node() which in turn set to NULL the related
dev->fwnode.
Later in the removal sequence, device_del() is called and runs its
cleanup logic:
if (dev->fwnode && dev->fwnode->dev == dev)
fw_devlink_set_device(dev->fwnode, NULL);
Because dev->fwnode has been cleared earlier, fw_devlink_set_device()
is not called and leaves fwnode->dev unchanged. This fwnode device
(fwnode->dev) becomes an dangling pointer.
If any reference to the OF node is held after this removal, the pointer
is still accessible using the OF node (np->fwnode.dev) but points to a
freed area.
The exact same issue is present in the of_pci_make_host_bridge_node()
error path leading to the exact same dangling fwnode->dev.
Avoid this dangling fwnode->dev pointer by clearing it in
of_pci_remove_host_bridge_node() and in of_pci_make_host_bridge_node()
error path.
Fixes: 1f340724419e ("PCI: of: Create device tree PCI host bridge node")
Cc: stable@vger.kernel.org
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/pci/of.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index ee9eb384b377..6a533f9bbf3c 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -743,6 +743,7 @@ void of_pci_remove_host_bridge_node(struct pci_host_bridge *bridge)
if (!np || !of_node_check_flag(np, OF_DYNAMIC))
return;
+ fw_devlink_set_device(&np->fwnode, NULL);
device_remove_of_node(&bridge->bus->dev);
device_remove_of_node(&bridge->dev);
of_changeset_revert(np->data);
@@ -808,7 +809,7 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)
ret = of_changeset_apply(cset);
if (ret)
- goto out_free_node;
+ goto out_clear_devlink_dev;
np->data = cset;
@@ -830,6 +831,8 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)
out_revert_cset:
np->data = NULL;
of_changeset_revert(cset);
+out_clear_devlink_dev:
+ fw_devlink_set_device(&np->fwnode, NULL);
out_free_node:
of_node_put(np);
out_destroy_cset:
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v10 08/10] PCI: of: Set fwnode device of newly created PCI device nodes
2026-07-17 14:51 [PATCH v10 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
` (3 preceding siblings ...)
2026-07-17 14:51 ` [PATCH v10 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path Herve Codina
@ 2026-07-17 14:51 ` Herve Codina
2026-07-17 14:51 ` [PATCH v10 09/10] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node Herve Codina
5 siblings, 0 replies; 7+ messages in thread
From: Herve Codina @ 2026-07-17 14:51 UTC (permalink / raw)
To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Bjorn Helgaas, David Rhodes, Richard Fitzgerald, Charles Keepax,
Linus Walleij, Len Brown, Andy Shevchenko, Daniel Scally,
Heikki Krogerus, Sakari Ailus, Davidlohr Bueso, Jonathan Cameron,
Dave Jiang, Alison Schofield, Vishal Verma, Dan Williams,
Ira Weiny, Li Ming, Lizhi Hou, Herve Codina
Cc: driver-core, linux-kernel, linux-pci, linux-sound, patches,
linux-gpio, linux-acpi, linux-cxl, Allan Nielsen, Horatiu Vultur,
Daniel Machon, Steen Hegelund, Luca Ceresoli, Thomas Petazzoni,
stable
Device-tree node can be created when CONFIG_PCI_DYNAMIC_OF_NODES. Those
nodes are created and filled based on PCI core information but the
fwnode device field is not set.
When later an overlay is applied, this confuses fw_devlink. Indeed,
without any device attached to the node, fw_devlink considers that this
node will never become a device. When this node is pointed as a
supplier, devlink looks at its ancestors in order to find a node with a
device that could be used as the supplier.
In the PCI use case, this leads to links that wrongly use the PCI root
bridge device as the supplier instead of the expected PCI device.
Setting the fwnode device to the device of the PCI device allows devlink
to use this device as a supplier and so, correct links are created.
Fixes: 407d1a51921e ("PCI: Create device tree node for bridge")
Cc: stable@vger.kernel.org
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/of.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 6a533f9bbf3c..a98f360c289a 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -657,6 +657,7 @@ void of_pci_remove_node(struct pci_dev *pdev)
if (!np || !of_node_check_flag(np, OF_DYNAMIC))
return;
+ fw_devlink_set_device(&np->fwnode, NULL);
device_remove_of_node(&pdev->dev);
of_changeset_revert(np->data);
of_changeset_destroy(np->data);
@@ -709,9 +710,16 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
if (ret)
goto out_free_node;
+ /*
+ * Set the fwnode device in order to have fw_devlink creating links
+ * pointing to this PCI device instead of walking up to the PCI host
+ * bridge.
+ */
+ fw_devlink_set_device(&np->fwnode, &pdev->dev);
+
ret = of_changeset_apply(cset);
if (ret)
- goto out_free_node;
+ goto out_clear_devlink_dev;
np->data = cset;
@@ -726,6 +734,8 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
out_revert_cset:
np->data = NULL;
of_changeset_revert(cset);
+out_clear_devlink_dev:
+ fw_devlink_set_device(&np->fwnode, NULL);
out_free_node:
of_node_put(np);
out_destroy_cset:
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v10 09/10] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node
2026-07-17 14:51 [PATCH v10 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
` (4 preceding siblings ...)
2026-07-17 14:51 ` [PATCH v10 08/10] PCI: of: Set fwnode device of newly created PCI device nodes Herve Codina
@ 2026-07-17 14:51 ` Herve Codina
5 siblings, 0 replies; 7+ messages in thread
From: Herve Codina @ 2026-07-17 14:51 UTC (permalink / raw)
To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Bjorn Helgaas, David Rhodes, Richard Fitzgerald, Charles Keepax,
Linus Walleij, Len Brown, Andy Shevchenko, Daniel Scally,
Heikki Krogerus, Sakari Ailus, Davidlohr Bueso, Jonathan Cameron,
Dave Jiang, Alison Schofield, Vishal Verma, Dan Williams,
Ira Weiny, Li Ming, Lizhi Hou, Herve Codina
Cc: driver-core, linux-kernel, linux-pci, linux-sound, patches,
linux-gpio, linux-acpi, linux-cxl, Allan Nielsen, Horatiu Vultur,
Daniel Machon, Steen Hegelund, Luca Ceresoli, Thomas Petazzoni,
stable
During the instantiation of devices described by a device-tree overlay
applied on a PCI device, devlink displays the following kind of debug
messages instead of creating the expected links:
'Not linking xxxx - might never become dev'
Without those expected links, the device removal order cannot be
correct.
Those debug traces are printed by fw_devlink_create_devlink(). In our
use case, they are all printed because the supplier of the link has at
least one of its ancestor with its fwnode flag FWNODE_FLAG_INITIALIZED
set.
The culprit ancestor is the PCI root bridge.
The fwnode related to the PCI root bridge is created dynamically by the
of_pci_make_host_bridge_node() function. During this creation
fwnode_dev_initialized() is called which set the FWNODE_FLAG_INITIALIZED
flag.
Calling fwnode_dev_initialized() tells devlink that the device related
to this node is handled out of the driver core. This is not correct in
our case. Indeed the device related to this firmware node is handled
using driver core mechanisms and is fully compliant devlink
expectations.
Simply remove the fwnode_dev_initialized() call. With that done, the
devlink debug messages are no more displayed and links that were missing
are correctly created.
Fixes: 1f340724419e ("PCI: of: Create device tree PCI host bridge node")
Cc: stable@vger.kernel.org
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/of.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index a98f360c289a..28896f748e8d 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -815,7 +815,6 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)
*/
of_node_set_flag(np, OF_POPULATED);
fw_devlink_set_device(&np->fwnode, &bridge->dev);
- fwnode_dev_initialized(&np->fwnode, true);
ret = of_changeset_apply(cset);
if (ret)
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread