PCI/pwrctrl: Only destroy devices created by pwrctrl core
Subsystems (2)
PATCH 1/1 PCI/pwrctrl: Only destroy devices created by pwrctrl core
pci_pwrctrl_create_device() only creates platform devices for OF nodes that pci_pwrctrl_is_required() accepts, but pci_pwrctrl_destroy_device() unregisters the platform device of every available child node without that check.
Nodes under a PCI host controller that are not pwrctrl devices may have been populated by another mechanism. Destroying them here would tear down devices owned by other code.
Mirror the check done at creation time so that only devices created by the pwrctrl core are removed.
---
drivers/pci/pwrctrl/core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pci/pwrctrl/core.c +3 -0
@@ -388,6 +388,9 @@ static void pci_pwrctrl_destroy_device(struct device_node *np)for_each_available_child_of_node_scoped (np, child)pci_pwrctrl_destroy_device (child); +if (!pci_pwrctrl_is_required (np)) +return ; + pdev =of_find_device_by_node (np);if (!pdev)return ;
Signature · 1 line
2.7.4
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
pci_pwrctrl_create_device()only creates platform devices for OF nodes thatpci_pwrctrl_is_required()accepts, butpci_pwrctrl_destroy_device()unregisters the platform device of every available child node without that check.Nodes under a PCI host controller that are not pwrctrl devices may have been populated by another mechanism. Destroying them here would tear down devices owned by other code.
Quoted 5 lines
Mirror the check done at creation time so that only devices created by the pwrctrl core are removed.
Fixes 4c4132489201 ("PCI/pwrctrl: Add APIs to create, destroy pwrctrl devices")Signed-off-by Shawn Lin <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 9 lines · Shawn Lin
pci_pwrctrl_create_device()only creates platform devices for OF nodes thatpci_pwrctrl_is_required()accepts, butpci_pwrctrl_destroy_device()unregisters the platform device of every available child node without that check.Nodes under a PCI host controller that are not pwrctrl devices may have been populated by another mechanism. Destroying them here would tear down devices owned by other code.
Quoted 6 lines
Mirror the check done at creation time so that only devices created by the pwrctrl core are removed.
Fixes 4c4132489201 ("PCI/pwrctrl: Add APIs to create, destroy pwrctrl devices")Signed-off-by Shawn Lin <[email protected]>---
Bjorn Helgaas
AppliedQuoted 9 lines · Shawn Lin
pci_pwrctrl_create_device()only creates platform devices for OF nodes thatpci_pwrctrl_is_required()accepts, butpci_pwrctrl_destroy_device()unregisters the platform device of every available child node without that check.Nodes under a PCI host controller that are not pwrctrl devices may have been populated by another mechanism. Destroying them here would tear down devices owned by other code.
Quoted 5 lines
Mirror the check done at creation time so that only devices created by the pwrctrl core are removed.
Fixes 4c4132489201 ("PCI/pwrctrl: Add APIs to create, destroy pwrctrl devices")Signed-off-by Shawn Lin <[email protected]>
Applied to pci/pwrctrl for v7.4, thanks!
Tearing down devices owned by other code sounds like an issue; maybe this should have a cc: stable tag, since 4c4132489201 appeared in v7.0?
Quoted 22 lines
---
drivers/pci/pwrctrl/core.c | 3 +++ 1 file changed, 3 insertions(+)drivers/pci/pwrctrl/core.c +3
-0@@ -388,6 +388,9 @@ static void pci_pwrctrl_destroy_device(struct device_node *np)for_each_available_child_of_node_scoped (np, child)pci_pwrctrl_destroy_device (child); +if (!pci_pwrctrl_is_required (np)) +return ; + pdev =of_find_device_by_node (np);if (!pdev)return ;Signature · 1 line
2.7.4
Hi Bjorn,
Quoted 13 lines · Bjorn Helgaas
Quoted 12 lines · Shawn Lin
pci_pwrctrl_create_device()only creates platform devices for OF nodes thatpci_pwrctrl_is_required()accepts, butpci_pwrctrl_destroy_device()unregisters the platform device of every available child node without that check.Nodes under a PCI host controller that are not pwrctrl devices may have been populated by another mechanism. Destroying them here would tear down devices owned by other code.
Mirror the check done at creation time so that only devices created by the pwrctrl core are removed.
Quoted 9 lines
Quoted 2 lines
Fixes 4c4132489201 ("PCI/pwrctrl: Add APIs to create, destroy pwrctrl devices")Signed-off-by Shawn Lin <[email protected]>Applied to pci/pwrctrl for v7.4, thanks!
Tearing down devices owned by other code sounds like an issue; maybe this should have a cc: stable tag, since
4c4132489201appeared in v7.0?
It would be better if this could be backported to v7.0, so it's fine for me to cc stable.
Quoted 23 lines
Quoted 22 lines
---
drivers/pci/pwrctrl/core.c | 3 +++ 1 file changed, 3 insertions(+)drivers/pci/pwrctrl/core.c +3
-0@@ -388,6 +388,9 @@ static void pci_pwrctrl_destroy_device(struct device_node *np)for_each_available_child_of_node_scoped (np, child)pci_pwrctrl_destroy_device (child); +if (!pci_pwrctrl_is_required (np)) +return ; + pdev =of_find_device_by_node (np);if (!pdev)return ;Signature · 1 line
2.7.4