Linux CXL
 help / color / mirror / Atom feed
* [PATCH v11 00/10] lan966x pci device: Add support for SFPs, PCI part
@ 2026-09-09  8:00 Herve Codina
  2026-09-09  8:01 ` [PATCH v11 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
                   ` (9 more replies)
  0 siblings, 10 replies; 30+ messages in thread
From: Herve Codina @ 2026-09-09  8:00 UTC (permalink / raw)
  To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Bjorn Helgaas, Charles Keepax, Richard Fitzgerald, David Rhodes,
	Linus Walleij, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Bartosz Golaszewski, Len Brown, Davidlohr Bueso,
	Jonathan Cameron, Dave Jiang, Alison Schofield, Vishal Verma,
	Dan Williams, Ira Weiny, Li Ming, Herve Codina, Lizhi Hou
  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

Hi,

Previously, I sent a big picture series adding support for SFP ports
available on the LAN966x PCI device [0].

In this series patches touch several parts and sub-system in the kernel.
Reviews have be done and it makes sense to split the series and send
parts separately.

This current series is the extraction of patches related to issues in
the PCI subsystem. It has to be seen as a continuation of the big
picture series but related to this specific core part.

Patches 1 to 6 introduce and use fw_devlink_set_device() in already
existing code. No functional change but the introduction of the
fw_devlink_set_device() wrapper.

Patch 7 avoids a dangling pointer.

Patches 8 and 9 fix fw_devlink issues specific to PCI and the
device-tree nodes created during enumeration.

Patch 10 avoids the usage of np->data and adds guards to prevent
incorrect nodes removal.

[0] https://lore.kernel.org/all/20260325143555.451852-1-herve.codina@bootlin.com/

Best regards,
Hervé

Changes:

v10 -> v11
  v10: https://lore.kernel.org/all/20260717145147.823749-1-herve.codina@bootlin.com/

  Rebase on top of v7.3-rc1

  - Patches 1 to 5
    Add 'Reviewed-by: Richard Cheng'

  - Patches 6, 7 and 8
    Add 'Reviewed-by: Richard Cheng'
    Add 'Acked-by: Manivannan Sadhasivam'

  - Patch 9
    Add 'Reviewed-by: Richard Cheng'

  - Patch 10
    Rework removing np->data usage in the PCI devicetree node creation
    and removal.

v9 -> v10
  v9: https://lore.kernel.org/all/20260708100302.517792-1-herve.codina@bootlin.com/

  - Patches 1 to 6
    No changes

  - Patch 7
    Clear fwnode->dev also on error path.

  - Patch 8
    Clear fwnode->dev also on error path.

  - Patch 9
    No changes

  - Patch 10 (New patch in v10)
    Guard against node removal with incorrect np->data.

v8 -> v9
  v8: https://lore.kernel.org/all/20260630102804.413563-1-herve.codina@bootlin.com/

  - Patch 7 (new patch in v9)
    Clear fwnode->dev during root bridge node removal (avoid a dangling
    pointer).

  - Patch 8 (patch 7 in v8)
    Clear fwnode->dev during PCI device node removal.

v7 -> v8
  v7: https://lore.kernel.org/all/20260511155930.34604-1-herve.codina@bootlin.com/

  Rebase on top of v7.2-rc1

  - patches 4 and 5
    Add 'Reviewed-by: Andy Shevchenko'

  - Other Patches
    No other changes

v6 -> v7

  Rebase on top of v7.1-rc1

  - Patch 1
     Add Cc stable. Needed for patches 11 and 12

  - Patches 2 to 5
    No changes

  - Patch 6
     Add Cc stable. Needed for patch 13
     Add 'Acked-by: Bjorn Helgaas'

  - Patch 7
     Fix a typo in commit log
     Add Fixes tag + Cc stable
     Add 'Acked-by: Bjorn Helgaas'

  - Patch 8
     Add Fixes tag + Cc stable
     Add 'Acked-by: Bjorn Helgaas'
Older iterations:
  Patches 6 to 13 in the big picture series
  https://lore.kernel.org/all/20260325143555.451852-1-herve.codina@bootlin.com/

Herve Codina (10):
  driver core: fw_devlink: Introduce fw_devlink_set_device()
  drivers: core: Use fw_devlink_set_device()
  pinctrl: cs42l43: Use fw_devlink_set_device()
  cxl/test: Use device_set_node()
  cxl/test: Use fw_devlink_set_device()
  PCI: of: Use fw_devlink_set_device()
  PCI: of: Clear fwnode->dev during root bridge node removal and error
    path
  PCI: of: Set fwnode device of newly created PCI device nodes
  PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge
    node
  PCI: of: Avoid np->data usage for the node changeset

 drivers/base/core.c                      |  4 +-
 drivers/pci/of.c                         | 48 +++++++++++++++---------
 drivers/pinctrl/cirrus/pinctrl-cs42l43.c |  2 +-
 include/linux/fwnode.h                   |  6 +++
 include/linux/pci.h                      | 11 ++++++
 tools/testing/cxl/test/cxl.c             |  4 +-
 6 files changed, 52 insertions(+), 23 deletions(-)

-- 
2.55.0


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

* [PATCH v11 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device()
  2026-09-09  8:00 [PATCH v11 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
@ 2026-09-09  8:01 ` Herve Codina
  2026-09-09  8:05   ` sashiko-bot
  2026-09-09 11:31   ` Bartosz Golaszewski
  2026-09-09  8:01 ` [PATCH v11 02/10] drivers: core: Use fw_devlink_set_device() Herve Codina
                   ` (8 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Herve Codina @ 2026-09-09  8:01 UTC (permalink / raw)
  To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Bjorn Helgaas, Charles Keepax, Richard Fitzgerald, David Rhodes,
	Linus Walleij, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Bartosz Golaszewski, Len Brown, Davidlohr Bueso,
	Jonathan Cameron, Dave Jiang, Alison Schofield, Vishal Verma,
	Dan Williams, Ira Weiny, Li Ming, Herve Codina, Lizhi Hou
  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>
Reviewed-by: Richard Cheng <icheng@nvidia.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 a9dcaf7e7076..3ce49575cf82 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -260,4 +260,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] 30+ messages in thread

* [PATCH v11 02/10] drivers: core: Use fw_devlink_set_device()
  2026-09-09  8:00 [PATCH v11 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
  2026-09-09  8:01 ` [PATCH v11 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
@ 2026-09-09  8:01 ` Herve Codina
  2026-09-09  8:11   ` sashiko-bot
  2026-09-09  9:05   ` Bartosz Golaszewski
  2026-09-09  8:01 ` [PATCH v11 03/10] pinctrl: cs42l43: " Herve Codina
                   ` (7 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Herve Codina @ 2026-09-09  8:01 UTC (permalink / raw)
  To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Bjorn Helgaas, Charles Keepax, Richard Fitzgerald, David Rhodes,
	Linus Walleij, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Bartosz Golaszewski, Len Brown, Davidlohr Bueso,
	Jonathan Cameron, Dave Jiang, Alison Schofield, Vishal Verma,
	Dan Williams, Ira Weiny, Li Ming, Herve Codina, Lizhi Hou
  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,
	Ulf Hansson

The code set directly fwnode->dev field.

Use the dedicated fw_devlink_set_device() helper to perform this
operation.

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: Richard Cheng <icheng@nvidia.com>
---
 drivers/base/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 4c0c373998a1..3268e9350c86 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3754,7 +3754,7 @@ int device_add(struct device *dev)
 	 * device and the driver sync_state callback is called for this device.
 	 */
 	if (dev->fwnode && !dev->fwnode->dev) {
-		dev->fwnode->dev = dev;
+		fw_devlink_set_device(dev->fwnode, dev);
 		fw_devlink_link_device(dev);
 	}
 
@@ -3929,7 +3929,7 @@ void device_del(struct device *dev)
 	device_unlock(dev);
 
 	if (dev->fwnode && dev->fwnode->dev == dev)
-		dev->fwnode->dev = NULL;
+		fw_devlink_set_device(dev->fwnode, NULL);
 
 	/* Notify clients of device removal.  This call must come
 	 * before dpm_sysfs_remove().
-- 
2.55.0


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

* [PATCH v11 03/10] pinctrl: cs42l43: Use fw_devlink_set_device()
  2026-09-09  8:00 [PATCH v11 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
  2026-09-09  8:01 ` [PATCH v11 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
  2026-09-09  8:01 ` [PATCH v11 02/10] drivers: core: Use fw_devlink_set_device() Herve Codina
@ 2026-09-09  8:01 ` Herve Codina
  2026-09-09  8:05   ` sashiko-bot
  2026-09-09  9:06   ` Bartosz Golaszewski
  2026-09-09  8:01 ` [PATCH v11 04/10] cxl/test: Use device_set_node() Herve Codina
                   ` (6 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Herve Codina @ 2026-09-09  8:01 UTC (permalink / raw)
  To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Bjorn Helgaas, Charles Keepax, Richard Fitzgerald, David Rhodes,
	Linus Walleij, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Bartosz Golaszewski, Len Brown, Davidlohr Bueso,
	Jonathan Cameron, Dave Jiang, Alison Schofield, Vishal Verma,
	Dan Williams, Ira Weiny, Li Ming, Herve Codina, Lizhi Hou
  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

The code set directly fwnode->dev field.

Use the dedicated fw_devlink_set_device() helper to perform this
operation.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Acked-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Richard Cheng <icheng@nvidia.com>
---
 drivers/pinctrl/cirrus/pinctrl-cs42l43.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/cirrus/pinctrl-cs42l43.c b/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
index 8990fab0446c..563070aba3d8 100644
--- a/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
+++ b/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
@@ -576,7 +576,7 @@ static int cs42l43_pin_probe(struct platform_device *pdev)
 				return ret;
 
 			if (!child->dev)
-				child->dev = priv->dev;
+				fw_devlink_set_device(child, priv->dev);
 			fwnode = child;
 		}
 	}
-- 
2.55.0


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

* [PATCH v11 04/10] cxl/test: Use device_set_node()
  2026-09-09  8:00 [PATCH v11 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
                   ` (2 preceding siblings ...)
  2026-09-09  8:01 ` [PATCH v11 03/10] pinctrl: cs42l43: " Herve Codina
@ 2026-09-09  8:01 ` Herve Codina
  2026-09-09  8:04   ` sashiko-bot
  2026-09-09  9:06   ` Bartosz Golaszewski
  2026-09-09  8:01 ` [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device() Herve Codina
                   ` (5 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Herve Codina @ 2026-09-09  8:01 UTC (permalink / raw)
  To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Bjorn Helgaas, Charles Keepax, Richard Fitzgerald, David Rhodes,
	Linus Walleij, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Bartosz Golaszewski, Len Brown, Davidlohr Bueso,
	Jonathan Cameron, Dave Jiang, Alison Schofield, Vishal Verma,
	Dan Williams, Ira Weiny, Li Ming, Herve Codina, Lizhi Hou
  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>
Reviewed-by: Richard Cheng <icheng@nvidia.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 62bd92b3be45..547ebc97bf59 100644
--- a/tools/testing/cxl/test/cxl.c
+++ b/tools/testing/cxl/test/cxl.c
@@ -1677,7 +1677,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] 30+ messages in thread

* [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device()
  2026-09-09  8:00 [PATCH v11 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
                   ` (3 preceding siblings ...)
  2026-09-09  8:01 ` [PATCH v11 04/10] cxl/test: Use device_set_node() Herve Codina
@ 2026-09-09  8:01 ` Herve Codina
  2026-09-09  8:04   ` sashiko-bot
                     ` (3 more replies)
  2026-09-09  8:01 ` [PATCH v11 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path Herve Codina
                   ` (4 subsequent siblings)
  9 siblings, 4 replies; 30+ messages in thread
From: Herve Codina @ 2026-09-09  8:01 UTC (permalink / raw)
  To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Bjorn Helgaas, Charles Keepax, Richard Fitzgerald, David Rhodes,
	Linus Walleij, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Bartosz Golaszewski, Len Brown, Davidlohr Bueso,
	Jonathan Cameron, Dave Jiang, Alison Schofield, Vishal Verma,
	Dan Williams, Ira Weiny, Li Ming, Herve Codina, Lizhi Hou
  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 fwnode.dev field.

Use the dedicated fw_devlink_set_device() 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>
Reviewed-by: Richard Cheng <icheng@nvidia.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 547ebc97bf59..e21e45fe1572 100644
--- a/tools/testing/cxl/test/cxl.c
+++ b/tools/testing/cxl/test/cxl.c
@@ -1678,7 +1678,7 @@ static void mock_companion(struct acpi_device *adev, struct device *dev)
 	device_initialize(&adev->dev);
 	fwnode_init(&adev->fwnode, NULL);
 	device_set_node(dev, &adev->fwnode);
-	adev->fwnode.dev = dev;
+	fw_devlink_set_device(&adev->fwnode, dev);
 }
 
 #ifndef SZ_64G
-- 
2.55.0


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

* [PATCH v11 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path
  2026-09-09  8:00 [PATCH v11 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
                   ` (4 preceding siblings ...)
  2026-09-09  8:01 ` [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device() Herve Codina
@ 2026-09-09  8:01 ` Herve Codina
  2026-09-09  8:12   ` sashiko-bot
  2026-09-09 11:31   ` Bartosz Golaszewski
  2026-09-09  8:01 ` [PATCH v11 08/10] PCI: of: Set fwnode device of newly created PCI device nodes Herve Codina
                   ` (3 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Herve Codina @ 2026-09-09  8:01 UTC (permalink / raw)
  To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Bjorn Helgaas, Charles Keepax, Richard Fitzgerald, David Rhodes,
	Linus Walleij, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Bartosz Golaszewski, Len Brown, Davidlohr Bueso,
	Jonathan Cameron, Dave Jiang, Alison Schofield, Vishal Verma,
	Dan Williams, Ira Weiny, Li Ming, Herve Codina, Lizhi Hou
  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, Manivannan Sadhasivam

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>
Reviewed-by: Richard Cheng <icheng@nvidia.com>
Acked-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.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 0f45c5b72458..29b63a9090ae 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -822,6 +822,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);
@@ -887,7 +888,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;
 
@@ -909,6 +910,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] 30+ messages in thread

* [PATCH v11 08/10] PCI: of: Set fwnode device of newly created PCI device nodes
  2026-09-09  8:00 [PATCH v11 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
                   ` (5 preceding siblings ...)
  2026-09-09  8:01 ` [PATCH v11 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path Herve Codina
@ 2026-09-09  8:01 ` Herve Codina
  2026-09-09  8:14   ` sashiko-bot
  2026-09-09  8:01 ` [PATCH v11 10/10] PCI: of: Avoid np->data usage for the node changeset Herve Codina
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 30+ messages in thread
From: Herve Codina @ 2026-09-09  8:01 UTC (permalink / raw)
  To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Bjorn Helgaas, Charles Keepax, Richard Fitzgerald, David Rhodes,
	Linus Walleij, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Bartosz Golaszewski, Len Brown, Davidlohr Bueso,
	Jonathan Cameron, Dave Jiang, Alison Schofield, Vishal Verma,
	Dan Williams, Ira Weiny, Li Ming, Herve Codina, Lizhi Hou
  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, Manivannan Sadhasivam

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>
Reviewed-by: Richard Cheng <icheng@nvidia.com>
Acked-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.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 29b63a9090ae..8914bfa25dc1 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -736,6 +736,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);
@@ -788,9 +789,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;
 
@@ -805,6 +813,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] 30+ messages in thread

* [PATCH v11 10/10] PCI: of: Avoid np->data usage for the node changeset
  2026-09-09  8:00 [PATCH v11 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
                   ` (6 preceding siblings ...)
  2026-09-09  8:01 ` [PATCH v11 08/10] PCI: of: Set fwnode device of newly created PCI device nodes Herve Codina
@ 2026-09-09  8:01 ` Herve Codina
  2026-09-09  8:17   ` sashiko-bot
  2026-09-09  9:12   ` Herve Codina
       [not found] ` <20260909080114.591938-7-herve.codina@bootlin.com>
       [not found] ` <20260909080114.591938-10-herve.codina@bootlin.com>
  9 siblings, 2 replies; 30+ messages in thread
From: Herve Codina @ 2026-09-09  8:01 UTC (permalink / raw)
  To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Bjorn Helgaas, Charles Keepax, Richard Fitzgerald, David Rhodes,
	Linus Walleij, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Bartosz Golaszewski, Len Brown, Davidlohr Bueso,
	Jonathan Cameron, Dave Jiang, Alison Schofield, Vishal Verma,
	Dan Williams, Ira Weiny, Li Ming, Herve Codina, Lizhi Hou
  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+noautosel

of_pci_remove_node() and of_pci_remove_host_bridge_node() check
whether the node is dynamic but not whether it has valid private data.

During the node creation, an OF changeset is used and this changeset is
stored in np->data to be available for removal functions.

If, for instance, a PCI host bridge is created using a device-tree
overlay, the related node will have the dynamic flag set but np->data
will be NULL. This leads to NULL pointer dereferences.

Checking for a non-NULL np->data pointer to determine if the node has
been created by the PCI node creation process is not enough. Indeed,
on some platforms like PowerPC, the OF_RECONFIG_ATTACH_NODE notifier
(e.g., in the pci_dn_reconfig_notifier() function) intercepts node
additions and populates np->data with its own structure, such as a
struct pci_dn. In that case, np->data is not NULL but it is not related
to our changeset stored during the PCI node process creation.

Avoid the usage of np->data to store the changeset used during the PCI
node creation. Store our changeset in a more relevant structure: either
struct pci_dev when the node is created for a PCI device or struct
pci_host_bridge when the node is created for the PCI host bridge.

With that done, no ambiguity remains on removal. Indeed, this changeset,
if non-NULL, is the one used during PCI node creation. Check and use
this changeset on the removal process.

Fixes: 407d1a51921e ("PCI: Create device tree node for bridge")
Fixes: 1f340724419e ("PCI: of: Create device tree PCI host bridge node")
Cc: <stable+noautosel@kernel.org> # Issue not triggered but could be a problem
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
 drivers/pci/of.c    | 28 ++++++++++++++--------------
 include/linux/pci.h | 11 +++++++++++
 2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 0a5797652e18..cd87128c71dd 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -732,15 +732,16 @@ void of_pci_remove_node(struct pci_dev *pdev)
 {
 	struct device_node *np;
 
-	np = pci_device_to_OF_node(pdev);
-	if (!np || !of_node_check_flag(np, OF_DYNAMIC))
+	if (!pdev->cset)
 		return;
 
+	np = pci_device_to_OF_node(pdev);
 	fw_devlink_set_device(&np->fwnode, NULL);
 	device_remove_of_node(&pdev->dev);
-	of_changeset_revert(np->data);
-	of_changeset_destroy(np->data);
+	of_changeset_revert(pdev->cset);
+	of_changeset_destroy(pdev->cset);
 	of_node_put(np);
+	kfree(pdev->cset);
 }
 
 void of_pci_make_dev_node(struct pci_dev *pdev)
@@ -800,18 +801,17 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
 	if (ret)
 		goto out_clear_devlink_dev;
 
-	np->data = cset;
-
 	ret = device_add_of_node(&pdev->dev, np);
 	if (ret)
 		goto out_revert_cset;
 
+	pdev->cset = cset;
+
 	kfree(name);
 
 	return;
 
 out_revert_cset:
-	np->data = NULL;
 	of_changeset_revert(cset);
 out_clear_devlink_dev:
 	fw_devlink_set_device(&np->fwnode, NULL);
@@ -828,16 +828,17 @@ void of_pci_remove_host_bridge_node(struct pci_host_bridge *bridge)
 {
 	struct device_node *np;
 
-	np = pci_bus_to_OF_node(bridge->bus);
-	if (!np || !of_node_check_flag(np, OF_DYNAMIC))
+	if (!bridge->cset)
 		return;
 
+	np = pci_bus_to_OF_node(bridge->bus);
 	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);
-	of_changeset_destroy(np->data);
+	of_changeset_revert(bridge->cset);
+	of_changeset_destroy(bridge->cset);
 	of_node_put(np);
+	kfree(bridge->cset);
 }
 
 void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)
@@ -899,8 +900,6 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)
 	if (ret)
 		goto out_clear_devlink_dev;
 
-	np->data = cset;
-
 	/* Add the of_node to host bridge and the root bus */
 	ret = device_add_of_node(&bridge->dev, np);
 	if (ret)
@@ -910,6 +909,8 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)
 	if (ret)
 		goto out_remove_bridge_dev_of_node;
 
+	bridge->cset = cset;
+
 	kfree(name);
 
 	return;
@@ -917,7 +918,6 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)
 out_remove_bridge_dev_of_node:
 	device_remove_of_node(&bridge->dev);
 out_revert_cset:
-	np->data = NULL;
 	of_changeset_revert(cset);
 out_clear_devlink_dev:
 	fw_devlink_set_device(&np->fwnode, NULL);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index d31a8d107b1e..7b0ba9ec7b5c 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -339,6 +339,9 @@ struct pcie_link_state;
 struct pci_sriov;
 struct pci_p2pdma;
 struct rcec_ea;
+#ifdef CONFIG_PCI_DYNAMIC_OF_NODES
+struct of_changeset;
+#endif
 
 /* struct pci_dev - describes a PCI device
  *
@@ -598,6 +601,10 @@ struct pci_dev {
 	u8		tph_mode;	/* TPH mode */
 	u8		tph_req_type;	/* TPH requester type */
 #endif
+
+#ifdef CONFIG_PCI_DYNAMIC_OF_NODES
+	struct of_changeset *cset; /* Changeset used for OF node creation */
+#endif
 };
 
 static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
@@ -670,6 +677,10 @@ struct pci_host_bridge {
 	unsigned int	broken_l1ss_resume:1;	/* Resuming from L1SS during
 						   system suspend is broken */
 
+#ifdef CONFIG_PCI_DYNAMIC_OF_NODES
+	struct of_changeset *cset; /* Changeset used for OF node creation */
+#endif
+
 	/* Resource alignment requirements */
 	resource_size_t (*align_resource)(struct pci_dev *dev,
 			const struct resource *res,
-- 
2.55.0


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

* Re: [PATCH v11 04/10] cxl/test: Use device_set_node()
  2026-09-09  8:01 ` [PATCH v11 04/10] cxl/test: Use device_set_node() Herve Codina
@ 2026-09-09  8:04   ` sashiko-bot
  2026-09-09  9:06   ` Bartosz Golaszewski
  1 sibling, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-09-09  8:04 UTC (permalink / raw)
  To: Herve Codina; +Cc: linux-cxl, linux-pci

> The code set directly dev->fwnode.
> 
> Use the dedicated helper to perform this operation.
> 
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909080114.591938-1-herve.codina@bootlin.com?part=4


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

* Re: [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device()
  2026-09-09  8:01 ` [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device() Herve Codina
@ 2026-09-09  8:04   ` sashiko-bot
  2026-09-09  9:06   ` Bartosz Golaszewski
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-09-09  8:04 UTC (permalink / raw)
  To: Herve Codina; +Cc: linux-pci, linux-cxl

> The code set directly fwnode.dev field.
> 
> Use the dedicated fw_devlink_set_device() helper to perform this
> operation.
> 
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909080114.591938-1-herve.codina@bootlin.com?part=5


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

* Re: [PATCH v11 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device()
  2026-09-09  8:01 ` [PATCH v11 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
@ 2026-09-09  8:05   ` sashiko-bot
  2026-09-09 11:31   ` Bartosz Golaszewski
  1 sibling, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-09-09  8:05 UTC (permalink / raw)
  To: Herve Codina; +Cc: linux-pci, linux-cxl

> 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>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909080114.591938-1-herve.codina@bootlin.com?part=1


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

* Re: [PATCH v11 03/10] pinctrl: cs42l43: Use fw_devlink_set_device()
  2026-09-09  8:01 ` [PATCH v11 03/10] pinctrl: cs42l43: " Herve Codina
@ 2026-09-09  8:05   ` sashiko-bot
  2026-09-09  9:06   ` Bartosz Golaszewski
  1 sibling, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-09-09  8:05 UTC (permalink / raw)
  To: Herve Codina; +Cc: linux-pci, linux-cxl

> The code set directly fwnode->dev field.
> 
> Use the dedicated fw_devlink_set_device() helper to perform this
> operation.
> 
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909080114.591938-1-herve.codina@bootlin.com?part=3


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

* Re: [PATCH v11 02/10] drivers: core: Use fw_devlink_set_device()
  2026-09-09  8:01 ` [PATCH v11 02/10] drivers: core: Use fw_devlink_set_device() Herve Codina
@ 2026-09-09  8:11   ` sashiko-bot
  2026-09-09  9:05   ` Bartosz Golaszewski
  1 sibling, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-09-09  8:11 UTC (permalink / raw)
  To: Herve Codina; +Cc: linux-cxl, linux-pci

> The code set directly fwnode->dev field.
> 
> Use the dedicated fw_devlink_set_device() helper to perform this
> operation.
> 
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909080114.591938-1-herve.codina@bootlin.com?part=2


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

* Re: [PATCH v11 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path
  2026-09-09  8:01 ` [PATCH v11 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path Herve Codina
@ 2026-09-09  8:12   ` sashiko-bot
  2026-09-09 11:31   ` Bartosz Golaszewski
  1 sibling, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-09-09  8:12 UTC (permalink / raw)
  To: Herve Codina; +Cc: linux-pci, linux-cxl

> 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);
> 
> [ ... ]
> 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>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909080114.591938-1-herve.codina@bootlin.com?part=7


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

* Re: [PATCH v11 06/10] PCI: of: Use fw_devlink_set_device()
       [not found] ` <20260909080114.591938-7-herve.codina@bootlin.com>
@ 2026-09-09  8:13   ` sashiko-bot
  2026-09-09 11:27   ` Bartosz Golaszewski
  1 sibling, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-09-09  8:13 UTC (permalink / raw)
  To: Herve Codina; +Cc: linux-cxl, linux-pci

> 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>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909080114.591938-1-herve.codina@bootlin.com?part=6


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

* Re: [PATCH v11 08/10] PCI: of: Set fwnode device of newly created PCI device nodes
  2026-09-09  8:01 ` [PATCH v11 08/10] PCI: of: Set fwnode device of newly created PCI device nodes Herve Codina
@ 2026-09-09  8:14   ` sashiko-bot
  0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-09-09  8:14 UTC (permalink / raw)
  To: Herve Codina; +Cc: linux-pci, linux-cxl

> 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>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909080114.591938-1-herve.codina@bootlin.com?part=8


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

* Re: [PATCH v11 09/10] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node
       [not found] ` <20260909080114.591938-10-herve.codina@bootlin.com>
@ 2026-09-09  8:15   ` sashiko-bot
  0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-09-09  8:15 UTC (permalink / raw)
  To: Herve Codina; +Cc: linux-cxl, linux-pci

> 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.
> 
> [ ... ]
> 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>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909080114.591938-1-herve.codina@bootlin.com?part=9


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

* Re: [PATCH v11 10/10] PCI: of: Avoid np->data usage for the node changeset
  2026-09-09  8:01 ` [PATCH v11 10/10] PCI: of: Avoid np->data usage for the node changeset Herve Codina
@ 2026-09-09  8:17   ` sashiko-bot
  2026-09-09  9:06     ` Herve Codina
  2026-09-09  9:12   ` Herve Codina
  1 sibling, 1 reply; 30+ messages in thread
From: sashiko-bot @ 2026-09-09  8:17 UTC (permalink / raw)
  To: Herve Codina; +Cc: linux-cxl, linux-pci

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing NULL check on `np` in `of_pci_remove_node` and `of_pci_remove_host_bridge_node` leading to kernel panic.
- [High] Dangling pointer in `pdev->cset` and `bridge->cset` after freeing, leading to potential use-after-free or double-free.
--

commit 506858ef76ab83f59a005bd51f3fde0f4d73a6a2
Author: Herve Codina <herve.codina@bootlin.com>

PCI: of: Avoid np->data usage for the node changeset

This patch modifies how OF changeset references are stored during PCI node
creation. Instead of using np->data, which can be altered by platform code,
it stores the changeset in pdev->cset or bridge->cset. This ensures the
correct changeset is reverted and destroyed during node removal.

> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index 0a5797652e183..cd87128c71ddc 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -732,15 +732,16 @@ void of_pci_remove_node(struct pci_dev *pdev)
>  {
>  	struct device_node *np;
>  
> -	np = pci_device_to_OF_node(pdev);
> -	if (!np || !of_node_check_flag(np, OF_DYNAMIC))
> +	if (!pdev->cset)
>  		return;
>  
> +	np = pci_device_to_OF_node(pdev);
>  	fw_devlink_set_device(&np->fwnode, NULL);

[Severity: High]
Will this result in an invalid pointer dereference if np is NULL?

The previous implementation had a NULL check for np, but the new code computes
&np->fwnode unconditionally. If pdev->dev.of_node is cleared prior to removal,
pci_device_to_OF_node() will return NULL, causing fw_devlink_set_device() to
dereference an offset address.

>  	device_remove_of_node(&pdev->dev);
> -	of_changeset_revert(np->data);
> -	of_changeset_destroy(np->data);
> +	of_changeset_revert(pdev->cset);
> +	of_changeset_destroy(pdev->cset);
>  	of_node_put(np);
> +	kfree(pdev->cset);

[Severity: High]
Is it possible for of_pci_remove_node() to be called twice for the same device?

If so, leaving pdev->cset as a dangling pointer could lead to a double-free.
Should pdev->cset be set to NULL after kfree() so that the earlier
if (!pdev->cset) check can prevent a second execution?

[ ... ]

> @@ -828,16 +828,17 @@ void of_pci_remove_host_bridge_node(struct pci_host_bridge *bridge)
>  {
>  	struct device_node *np;
>  
> -	np = pci_bus_to_OF_node(bridge->bus);
> -	if (!np || !of_node_check_flag(np, OF_DYNAMIC))
> +	if (!bridge->cset)
>  		return;
>  
> +	np = pci_bus_to_OF_node(bridge->bus);
>  	fw_devlink_set_device(&np->fwnode, NULL);

[Severity: High]
Can np evaluate to NULL here?

Similar to the issue in of_pci_remove_node(), if pci_bus_to_OF_node() returns
NULL, the missing NULL check will cause a crash during the &np->fwnode pointer
arithmetic.

>  	device_remove_of_node(&bridge->bus->dev);
>  	device_remove_of_node(&bridge->dev);
> -	of_changeset_revert(np->data);
> -	of_changeset_destroy(np->data);
> +	of_changeset_revert(bridge->cset);
> +	of_changeset_destroy(bridge->cset);
>  	of_node_put(np);
> +	kfree(bridge->cset);

[Severity: High]
Could this lead to a use-after-free or double-free on bridge->cset?

If a removal API like pci_stop_root_bus() is invoked multiple times, the
dangling pointer bypasses the if (!bridge->cset) check at the start of the
function, resulting in a double-free on the changeset.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909080114.591938-1-herve.codina@bootlin.com?part=10

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

* Re: [PATCH v11 02/10] drivers: core: Use fw_devlink_set_device()
  2026-09-09  8:01 ` [PATCH v11 02/10] drivers: core: Use fw_devlink_set_device() Herve Codina
  2026-09-09  8:11   ` sashiko-bot
@ 2026-09-09  9:05   ` Bartosz Golaszewski
  1 sibling, 0 replies; 30+ messages in thread
From: Bartosz Golaszewski @ 2026-09-09  9:05 UTC (permalink / raw)
  To: 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,
	Ulf Hansson, Richard Cheng, Andrew Lunn, Rob Herring,
	Saravana Kannan, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Bjorn Helgaas, Charles Keepax,
	Richard Fitzgerald, David Rhodes, Linus Walleij, Andy Shevchenko,
	Daniel Scally, Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Len Brown, Davidlohr Bueso, Jonathan Cameron, Dave Jiang,
	Alison Schofield, Vishal Verma, Dan Williams, Ira Weiny, Li Ming,
	Lizhi Hou

On Wed, 9 Sep 2026 10:01:01 +0200, Herve Codina <herve.codina@bootlin.com> said:
> The code set directly fwnode->dev field.
>
> Use the dedicated fw_devlink_set_device() helper to perform this
> operation.
>
> 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: Richard Cheng <icheng@nvidia.com>
> ---
>  drivers/base/core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 4c0c373998a1..3268e9350c86 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3754,7 +3754,7 @@ int device_add(struct device *dev)
>  	 * device and the driver sync_state callback is called for this device.
>  	 */
>  	if (dev->fwnode && !dev->fwnode->dev) {
> -		dev->fwnode->dev = dev;
> +		fw_devlink_set_device(dev->fwnode, dev);
>  		fw_devlink_link_device(dev);
>  	}
>
> @@ -3929,7 +3929,7 @@ void device_del(struct device *dev)
>  	device_unlock(dev);
>
>  	if (dev->fwnode && dev->fwnode->dev == dev)
> -		dev->fwnode->dev = NULL;
> +		fw_devlink_set_device(dev->fwnode, NULL);
>
>  	/* Notify clients of device removal.  This call must come
>  	 * before dpm_sysfs_remove().
> --
> 2.55.0
>
>

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

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

* Re: [PATCH v11 03/10] pinctrl: cs42l43: Use fw_devlink_set_device()
  2026-09-09  8:01 ` [PATCH v11 03/10] pinctrl: cs42l43: " Herve Codina
  2026-09-09  8:05   ` sashiko-bot
@ 2026-09-09  9:06   ` Bartosz Golaszewski
  1 sibling, 0 replies; 30+ messages in thread
From: Bartosz Golaszewski @ 2026-09-09  9:06 UTC (permalink / raw)
  To: 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,
	Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Bjorn Helgaas, Charles Keepax, Richard Fitzgerald, David Rhodes,
	Linus Walleij, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Bartosz Golaszewski, Len Brown, Davidlohr Bueso,
	Jonathan Cameron, Dave Jiang, Alison Schofield, Vishal Verma,
	Dan Williams, Ira Weiny, Li Ming, Lizhi Hou

On Wed, 9 Sep 2026 10:01:02 +0200, Herve Codina <herve.codina@bootlin.com> said:
> The code set directly fwnode->dev field.
>
> Use the dedicated fw_devlink_set_device() helper to perform this
> operation.
>
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
> Acked-by: Linus Walleij <linusw@kernel.org>
> Reviewed-by: Richard Cheng <icheng@nvidia.com>
> ---
>  drivers/pinctrl/cirrus/pinctrl-cs42l43.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/cirrus/pinctrl-cs42l43.c b/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
> index 8990fab0446c..563070aba3d8 100644
> --- a/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
> +++ b/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
> @@ -576,7 +576,7 @@ static int cs42l43_pin_probe(struct platform_device *pdev)
>  				return ret;
>
>  			if (!child->dev)
> -				child->dev = priv->dev;
> +				fw_devlink_set_device(child, priv->dev);
>  			fwnode = child;
>  		}
>  	}
> --
> 2.55.0
>
>

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

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

* Re: [PATCH v11 04/10] cxl/test: Use device_set_node()
  2026-09-09  8:01 ` [PATCH v11 04/10] cxl/test: Use device_set_node() Herve Codina
  2026-09-09  8:04   ` sashiko-bot
@ 2026-09-09  9:06   ` Bartosz Golaszewski
  1 sibling, 0 replies; 30+ messages in thread
From: Bartosz Golaszewski @ 2026-09-09  9:06 UTC (permalink / raw)
  To: 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, Richard Cheng, Andrew Lunn, Rob Herring,
	Saravana Kannan, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Bjorn Helgaas, Charles Keepax,
	Richard Fitzgerald, David Rhodes, Linus Walleij, Andy Shevchenko,
	Daniel Scally, Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Len Brown, Davidlohr Bueso, Jonathan Cameron, Dave Jiang,
	Alison Schofield, Vishal Verma, Dan Williams, Ira Weiny, Li Ming,
	Lizhi Hou

On Wed, 9 Sep 2026 10:01:03 +0200, Herve Codina <herve.codina@bootlin.com> said:
> 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>
> Reviewed-by: Richard Cheng <icheng@nvidia.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 62bd92b3be45..547ebc97bf59 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
> @@ -1677,7 +1677,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
>
>

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

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

* Re: [PATCH v11 10/10] PCI: of: Avoid np->data usage for the node changeset
  2026-09-09  8:17   ` sashiko-bot
@ 2026-09-09  9:06     ` Herve Codina
  0 siblings, 0 replies; 30+ messages in thread
From: Herve Codina @ 2026-09-09  9:06 UTC (permalink / raw)
  To: sashiko-bot; +Cc: sashiko-reviews, linux-cxl, linux-pci

On Wed, 09 Sep 2026 08:17:54 +0000
sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] Missing NULL check on `np` in `of_pci_remove_node` and `of_pci_remove_host_bridge_node` leading to kernel panic.
> - [High] Dangling pointer in `pdev->cset` and `bridge->cset` after freeing, leading to potential use-after-free or double-free.
> --
> 
> commit 506858ef76ab83f59a005bd51f3fde0f4d73a6a2
> Author: Herve Codina <herve.codina@bootlin.com>
> 
> PCI: of: Avoid np->data usage for the node changeset
> 
> This patch modifies how OF changeset references are stored during PCI node
> creation. Instead of using np->data, which can be altered by platform code,
> it stores the changeset in pdev->cset or bridge->cset. This ensures the
> correct changeset is reverted and destroyed during node removal.
> 
> > diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> > index 0a5797652e183..cd87128c71ddc 100644
> > --- a/drivers/pci/of.c
> > +++ b/drivers/pci/of.c
> > @@ -732,15 +732,16 @@ void of_pci_remove_node(struct pci_dev *pdev)
> >  {
> >  	struct device_node *np;
> >  
> > -	np = pci_device_to_OF_node(pdev);
> > -	if (!np || !of_node_check_flag(np, OF_DYNAMIC))
> > +	if (!pdev->cset)
> >  		return;
> >  
> > +	np = pci_device_to_OF_node(pdev);
> >  	fw_devlink_set_device(&np->fwnode, NULL);  
> 
> [Severity: High]
> Will this result in an invalid pointer dereference if np is NULL?
> 
> The previous implementation had a NULL check for np, but the new code computes
> &np->fwnode unconditionally. If pdev->dev.of_node is cleared prior to removal,
> pci_device_to_OF_node() will return NULL, causing fw_devlink_set_device() to
> dereference an offset address.

How np could be NULL with pdev->cset non-NULL ?

I don't think this can happen.

> 
> >  	device_remove_of_node(&pdev->dev);
> > -	of_changeset_revert(np->data);
> > -	of_changeset_destroy(np->data);
> > +	of_changeset_revert(pdev->cset);
> > +	of_changeset_destroy(pdev->cset);
> >  	of_node_put(np);
> > +	kfree(pdev->cset);  
> 
> [Severity: High]
> Is it possible for of_pci_remove_node() to be called twice for the same device?
> 
> If so, leaving pdev->cset as a dangling pointer could lead to a double-free.
> Should pdev->cset be set to NULL after kfree() so that the earlier
> if (!pdev->cset) check can prevent a second execution?

I don't think that of_pci_remove_node() can be called twice.

> 
> [ ... ]
> 
> > @@ -828,16 +828,17 @@ void of_pci_remove_host_bridge_node(struct pci_host_bridge *bridge)
> >  {
> >  	struct device_node *np;
> >  
> > -	np = pci_bus_to_OF_node(bridge->bus);
> > -	if (!np || !of_node_check_flag(np, OF_DYNAMIC))
> > +	if (!bridge->cset)
> >  		return;
> >  
> > +	np = pci_bus_to_OF_node(bridge->bus);
> >  	fw_devlink_set_device(&np->fwnode, NULL);  
> 
> [Severity: High]
> Can np evaluate to NULL here?
> 
> Similar to the issue in of_pci_remove_node(), if pci_bus_to_OF_node() returns
> NULL, the missing NULL check will cause a crash during the &np->fwnode pointer
> arithmetic.

bridge->cset protects agains a NULL np.

> 
> >  	device_remove_of_node(&bridge->bus->dev);
> >  	device_remove_of_node(&bridge->dev);
> > -	of_changeset_revert(np->data);
> > -	of_changeset_destroy(np->data);
> > +	of_changeset_revert(bridge->cset);
> > +	of_changeset_destroy(bridge->cset);
> >  	of_node_put(np);
> > +	kfree(bridge->cset);  
> 
> [Severity: High]
> Could this lead to a use-after-free or double-free on bridge->cset?
> 
> If a removal API like pci_stop_root_bus() is invoked multiple times, the
> dangling pointer bypasses the if (!bridge->cset) check at the start of the
> function, resulting in a double-free on the changeset.
> 

I don't think that pci_stop_root_bus() can be called twice.


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

* Re: [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device()
  2026-09-09  8:01 ` [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device() Herve Codina
  2026-09-09  8:04   ` sashiko-bot
@ 2026-09-09  9:06   ` Bartosz Golaszewski
  2026-09-09  9:23   ` Bartosz Golaszewski
  2026-09-09 11:27   ` Bartosz Golaszewski
  3 siblings, 0 replies; 30+ messages in thread
From: Bartosz Golaszewski @ 2026-09-09  9:06 UTC (permalink / raw)
  To: 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, Richard Cheng, Andrew Lunn, Rob Herring,
	Saravana Kannan, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Bjorn Helgaas, Charles Keepax,
	Richard Fitzgerald, David Rhodes, Linus Walleij, Andy Shevchenko,
	Daniel Scally, Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Len Brown, Davidlohr Bueso, Jonathan Cameron, Dave Jiang,
	Alison Schofield, Vishal Verma, Dan Williams, Ira Weiny, Li Ming,
	Lizhi Hou

On Wed, 9 Sep 2026 10:01:04 +0200, Herve Codina <herve.codina@bootlin.com> said:
> The code set directly fwnode.dev field.
>
> Use the dedicated fw_devlink_set_device() 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>
> Reviewed-by: Richard Cheng <icheng@nvidia.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 547ebc97bf59..e21e45fe1572 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
> @@ -1678,7 +1678,7 @@ static void mock_companion(struct acpi_device *adev, struct device *dev)
>  	device_initialize(&adev->dev);
>  	fwnode_init(&adev->fwnode, NULL);
>  	device_set_node(dev, &adev->fwnode);
> -	adev->fwnode.dev = dev;
> +	fw_devlink_set_device(&adev->fwnode, dev);
>  }
>
>  #ifndef SZ_64G
> --
> 2.55.0
>
>

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

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

* Re: [PATCH v11 10/10] PCI: of: Avoid np->data usage for the node changeset
  2026-09-09  8:01 ` [PATCH v11 10/10] PCI: of: Avoid np->data usage for the node changeset Herve Codina
  2026-09-09  8:17   ` sashiko-bot
@ 2026-09-09  9:12   ` Herve Codina
  1 sibling, 0 replies; 30+ messages in thread
From: Herve Codina @ 2026-09-09  9:12 UTC (permalink / raw)
  To: Richard Cheng, Andrew Lunn, Rob Herring, Saravana Kannan,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Bjorn Helgaas, Charles Keepax, Richard Fitzgerald, David Rhodes,
	Linus Walleij, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Bartosz Golaszewski, Len Brown, Davidlohr Bueso,
	Jonathan Cameron, Dave Jiang, Alison Schofield, Vishal Verma,
	Dan Williams, Ira Weiny, Li Ming, Herve Codina, Lizhi Hou
  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+noautosel

Hi All,

On Wed,  9 Sep 2026 10:01:09 +0200
Herve Codina <herve.codina@bootlin.com> wrote:

> of_pci_remove_node() and of_pci_remove_host_bridge_node() check
> whether the node is dynamic but not whether it has valid private data.
> 
> During the node creation, an OF changeset is used and this changeset is
> stored in np->data to be available for removal functions.
> 
> If, for instance, a PCI host bridge is created using a device-tree
> overlay, the related node will have the dynamic flag set but np->data
> will be NULL. This leads to NULL pointer dereferences.
> 
> Checking for a non-NULL np->data pointer to determine if the node has
> been created by the PCI node creation process is not enough. Indeed,
> on some platforms like PowerPC, the OF_RECONFIG_ATTACH_NODE notifier
> (e.g., in the pci_dn_reconfig_notifier() function) intercepts node
> additions and populates np->data with its own structure, such as a
> struct pci_dn. In that case, np->data is not NULL but it is not related
> to our changeset stored during the PCI node process creation.
> 
> Avoid the usage of np->data to store the changeset used during the PCI
> node creation. Store our changeset in a more relevant structure: either
> struct pci_dev when the node is created for a PCI device or struct
> pci_host_bridge when the node is created for the PCI host bridge.
> 
> With that done, no ambiguity remains on removal. Indeed, this changeset,
> if non-NULL, is the one used during PCI node creation. Check and use
> this changeset on the removal process.
> 
> Fixes: 407d1a51921e ("PCI: Create device tree node for bridge")
> Fixes: 1f340724419e ("PCI: of: Create device tree PCI host bridge node")
> Cc: <stable+noautosel@kernel.org> # Issue not triggered but could be a problem
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> ---
>  drivers/pci/of.c    | 28 ++++++++++++++--------------
>  include/linux/pci.h | 11 +++++++++++
>  2 files changed, 25 insertions(+), 14 deletions(-)
> 

Shashiko has reported issues [0].

IMO, those issues cannot be triggered but I would like to know the opinion of
other people and Maintainers.

Of course, I can update the code to more defensive but is it really needed?

Let me know if I need to send a new iteration with the update (check for a
null np and set cset to NULL after the kfree() call in remove functions).

[0] https://lore.kernel.org/all/20260909110623.2e6bbc89@bootlin.com/

Best regards,
Hervé

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

* Re: [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device()
  2026-09-09  8:01 ` [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device() Herve Codina
  2026-09-09  8:04   ` sashiko-bot
  2026-09-09  9:06   ` Bartosz Golaszewski
@ 2026-09-09  9:23   ` Bartosz Golaszewski
  2026-09-09 11:27   ` Bartosz Golaszewski
  3 siblings, 0 replies; 30+ messages in thread
From: Bartosz Golaszewski @ 2026-09-09  9:23 UTC (permalink / raw)
  To: 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, Richard Cheng, Andrew Lunn, Rob Herring,
	Saravana Kannan, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Bjorn Helgaas, Charles Keepax,
	Richard Fitzgerald, David Rhodes, Linus Walleij, Andy Shevchenko,
	Daniel Scally, Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Len Brown, Davidlohr Bueso, Jonathan Cameron, Dave Jiang,
	Alison Schofield, Vishal Verma, Dan Williams, Ira Weiny, Li Ming,
	Lizhi Hou

On Wed, 9 Sep 2026 10:01:04 +0200, Herve Codina <herve.codina@bootlin.com> said:
> The code set directly fwnode.dev field.
>
> Use the dedicated fw_devlink_set_device() 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>
> Reviewed-by: Richard Cheng <icheng@nvidia.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 547ebc97bf59..e21e45fe1572 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
> @@ -1678,7 +1678,7 @@ static void mock_companion(struct acpi_device *adev, struct device *dev)
>  	device_initialize(&adev->dev);
>  	fwnode_init(&adev->fwnode, NULL);
>  	device_set_node(dev, &adev->fwnode);
> -	adev->fwnode.dev = dev;
> +	fw_devlink_set_device(&adev->fwnode, dev);
>  }
>
>  #ifndef SZ_64G
> --
> 2.55.0
>
>

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

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

* Re: [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device()
  2026-09-09  8:01 ` [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device() Herve Codina
                     ` (2 preceding siblings ...)
  2026-09-09  9:23   ` Bartosz Golaszewski
@ 2026-09-09 11:27   ` Bartosz Golaszewski
  3 siblings, 0 replies; 30+ messages in thread
From: Bartosz Golaszewski @ 2026-09-09 11:27 UTC (permalink / raw)
  To: 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, Richard Cheng, Andrew Lunn, Rob Herring,
	Saravana Kannan, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Bjorn Helgaas, Charles Keepax,
	Richard Fitzgerald, David Rhodes, Linus Walleij, Andy Shevchenko,
	Daniel Scally, Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Len Brown, Davidlohr Bueso, Jonathan Cameron, Dave Jiang,
	Alison Schofield, Vishal Verma, Dan Williams, Ira Weiny, Li Ming,
	Lizhi Hou

On Wed, 9 Sep 2026 10:01:04 +0200, Herve Codina <herve.codina@bootlin.com> said:
> The code set directly fwnode.dev field.
>
> Use the dedicated fw_devlink_set_device() 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>
> Reviewed-by: Richard Cheng <icheng@nvidia.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 547ebc97bf59..e21e45fe1572 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
> @@ -1678,7 +1678,7 @@ static void mock_companion(struct acpi_device *adev, struct device *dev)
>  	device_initialize(&adev->dev);
>  	fwnode_init(&adev->fwnode, NULL);
>  	device_set_node(dev, &adev->fwnode);
> -	adev->fwnode.dev = dev;
> +	fw_devlink_set_device(&adev->fwnode, dev);
>  }
>
>  #ifndef SZ_64G
> --
> 2.55.0
>
>

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

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

* Re: [PATCH v11 06/10] PCI: of: Use fw_devlink_set_device()
       [not found] ` <20260909080114.591938-7-herve.codina@bootlin.com>
  2026-09-09  8:13   ` [PATCH v11 06/10] PCI: of: Use fw_devlink_set_device() sashiko-bot
@ 2026-09-09 11:27   ` Bartosz Golaszewski
  1 sibling, 0 replies; 30+ messages in thread
From: Bartosz Golaszewski @ 2026-09-09 11:27 UTC (permalink / raw)
  To: 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, Manivannan Sadhasivam, Richard Cheng, Andrew Lunn,
	Rob Herring, Saravana Kannan, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Bjorn Helgaas,
	Charles Keepax, Richard Fitzgerald, David Rhodes, Linus Walleij,
	Andy Shevchenko, Daniel Scally, Heikki Krogerus, Sakari Ailus,
	Bartosz Golaszewski, Len Brown, Davidlohr Bueso, Jonathan Cameron,
	Dave Jiang, Alison Schofield, Vishal Verma, Dan Williams,
	Ira Weiny, Li Ming, Lizhi Hou

On Wed, 9 Sep 2026 10:01:05 +0200, Herve Codina <herve.codina@bootlin.com> said:
> 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>
> Reviewed-by: Richard Cheng <icheng@nvidia.com>
> Acked-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.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 a51dff91b196..0f45c5b72458 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -882,7 +882,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
>
>

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

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

* Re: [PATCH v11 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path
  2026-09-09  8:01 ` [PATCH v11 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path Herve Codina
  2026-09-09  8:12   ` sashiko-bot
@ 2026-09-09 11:31   ` Bartosz Golaszewski
  1 sibling, 0 replies; 30+ messages in thread
From: Bartosz Golaszewski @ 2026-09-09 11:31 UTC (permalink / raw)
  To: 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, Manivannan Sadhasivam, Richard Cheng, Andrew Lunn,
	Rob Herring, Saravana Kannan, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Bjorn Helgaas,
	Charles Keepax, Richard Fitzgerald, David Rhodes, Linus Walleij,
	Andy Shevchenko, Daniel Scally, Heikki Krogerus, Sakari Ailus,
	Bartosz Golaszewski, Len Brown, Davidlohr Bueso, Jonathan Cameron,
	Dave Jiang, Alison Schofield, Vishal Verma, Dan Williams,
	Ira Weiny, Li Ming, Lizhi Hou

On Wed, 9 Sep 2026 10:01:06 +0200, Herve Codina <herve.codina@bootlin.com> said:
> 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>
> Reviewed-by: Richard Cheng <icheng@nvidia.com>
> Acked-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
> ---

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

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

* Re: [PATCH v11 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device()
  2026-09-09  8:01 ` [PATCH v11 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
  2026-09-09  8:05   ` sashiko-bot
@ 2026-09-09 11:31   ` Bartosz Golaszewski
  1 sibling, 0 replies; 30+ messages in thread
From: Bartosz Golaszewski @ 2026-09-09 11:31 UTC (permalink / raw)
  To: 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, Richard Cheng, Andrew Lunn, Rob Herring,
	Saravana Kannan, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Bjorn Helgaas, Charles Keepax,
	Richard Fitzgerald, David Rhodes, Linus Walleij, Andy Shevchenko,
	Daniel Scally, Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Len Brown, Davidlohr Bueso, Jonathan Cameron, Dave Jiang,
	Alison Schofield, Vishal Verma, Dan Williams, Ira Weiny, Li Ming,
	Lizhi Hou

On Wed, 9 Sep 2026 10:01:00 +0200, Herve Codina <herve.codina@bootlin.com> said:
> 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>
> Reviewed-by: Richard Cheng <icheng@nvidia.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 a9dcaf7e7076..3ce49575cf82 100644
> --- a/include/linux/fwnode.h
> +++ b/include/linux/fwnode.h
> @@ -260,4 +260,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
>
>
>

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

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

end of thread, other threads:[~2026-09-09 11:31 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-09  8:00 [PATCH v11 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
2026-09-09  8:01 ` [PATCH v11 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
2026-09-09  8:05   ` sashiko-bot
2026-09-09 11:31   ` Bartosz Golaszewski
2026-09-09  8:01 ` [PATCH v11 02/10] drivers: core: Use fw_devlink_set_device() Herve Codina
2026-09-09  8:11   ` sashiko-bot
2026-09-09  9:05   ` Bartosz Golaszewski
2026-09-09  8:01 ` [PATCH v11 03/10] pinctrl: cs42l43: " Herve Codina
2026-09-09  8:05   ` sashiko-bot
2026-09-09  9:06   ` Bartosz Golaszewski
2026-09-09  8:01 ` [PATCH v11 04/10] cxl/test: Use device_set_node() Herve Codina
2026-09-09  8:04   ` sashiko-bot
2026-09-09  9:06   ` Bartosz Golaszewski
2026-09-09  8:01 ` [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device() Herve Codina
2026-09-09  8:04   ` sashiko-bot
2026-09-09  9:06   ` Bartosz Golaszewski
2026-09-09  9:23   ` Bartosz Golaszewski
2026-09-09 11:27   ` Bartosz Golaszewski
2026-09-09  8:01 ` [PATCH v11 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path Herve Codina
2026-09-09  8:12   ` sashiko-bot
2026-09-09 11:31   ` Bartosz Golaszewski
2026-09-09  8:01 ` [PATCH v11 08/10] PCI: of: Set fwnode device of newly created PCI device nodes Herve Codina
2026-09-09  8:14   ` sashiko-bot
2026-09-09  8:01 ` [PATCH v11 10/10] PCI: of: Avoid np->data usage for the node changeset Herve Codina
2026-09-09  8:17   ` sashiko-bot
2026-09-09  9:06     ` Herve Codina
2026-09-09  9:12   ` Herve Codina
     [not found] ` <20260909080114.591938-7-herve.codina@bootlin.com>
2026-09-09  8:13   ` [PATCH v11 06/10] PCI: of: Use fw_devlink_set_device() sashiko-bot
2026-09-09 11:27   ` Bartosz Golaszewski
     [not found] ` <20260909080114.591938-10-herve.codina@bootlin.com>
2026-09-09  8:15   ` [PATCH v11 09/10] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node sashiko-bot

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