[PATCH v9 7/9] PCI: of: Clear fwnode->dev during root bridge node removal
From: Herve Codina
Date: Wed Jul 08 2026 - 06:07:39 EST
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.
Avoid this dangling fwnode->dev pointer by clearing it in
of_pci_remove_host_bridge_node().
Fixes: 1f340724419e ("PCI: of: Create device tree PCI host bridge node")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Herve Codina <herve.codina@xxxxxxxxxxx>
---
drivers/pci/of.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index ee9eb384b377..8dd558a490bb 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);
--
2.54.0