Skip to contentSkip to conversation

PCI/pwrctrl: Only destroy devices created by pwrctrl core

PATCH Applied Shawn Lin 4 participants 5 messages Oct 8 – Oct 9

Subsystems (2)
lore
Share & tools
lore

Shawn Lin

author
#0 lore raw

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.

Fixes 4c4132489201 ("PCI/pwrctrl: Add APIs to create, destroy pwrctrl devices")

---

 drivers/pci/pwrctrl/core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/pwrctrl/core.c +3 -0
index 10d817a..c14df11 100644
@@ -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
#1 lore raw
Sashiko 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 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.

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

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
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Shawn Lin
Quoted 9 lines · Shawn Lin

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.

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

---

#3 lore raw
In reply to Shawn Lin
Quoted 9 lines · Shawn Lin

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.

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

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
index 10d817a..c14df11 100644
@@ -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
author
#4 lore raw

Hi Bjorn,

Quoted 13 lines · Bjorn Helgaas
Quoted 12 lines · Shawn Lin

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.

Quoted 9 lines
Quoted 2 lines
Fixes 4c4132489201 ("PCI/pwrctrl: Add APIs to create, destroy pwrctrl devices")

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?

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
index 10d817a..c14df11 100644
@@ -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