PCI/pwrctrl: Power off child devices on power-on failure
Subsystems (2)
PATCH 1/1 PCI/pwrctrl: Power off child devices on power-on failure
pci_pwrctrl_power_on_device() recursively powers on the child nodes of a device before powering on the device itself. If powering on a child fails (e.g. returning -EPROBE_DEFER), the function returned immediately, leaving the sibling children that were already powered on in the same loop iteration enabled.
Since probe deferral is a standard boot path, this leads to unbounded regulator and clock enable increments across retries. The error path in pci_pwrctrl_power_on_devices() only powers off the top-level children processed before the failing one and explicitly stops at it, so it can never clean up the siblings leaked deeper in the failed subtree.
Power off the sibling children that were successfully powered on before a child fails, and power off all children if the device's own power_on() fails after its children were already enabled. Switch to a manual child iterator so the failing node can be tracked and its reference released in the error path.
--- drivers/pci/pwrctrl/core.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/pci/pwrctrl/core.c +17 -2
@@ -252,14 +252,16 @@ static int __pci_pwrctrl_power_on_device(struct device *dev)static int pci_pwrctrl_power_on_device (struct device_node *np) {struct platform_device *pdev; +struct device_node *child;int ret =0 ; -for_each_available_child_of_node_scoped (np, child) { +for_each_available_child_of_node (np, child) { ret =pci_pwrctrl_power_on_device (child);if (ret) -return ret; + goto err_power_off; } + child =NULL ;if (!pci_pwrctrl_is_required (np))return 0 ;
@@ -279,6 +281,19 @@ static int pci_pwrctrl_power_on_device(struct device_node *np)platform_device_put (pdev); +if (ret) + goto err_power_off; + +return 0 ; + +err_power_off: +for_each_available_child_of_node_scoped (np, tmp) { +if (tmp == child) +break ; +pci_pwrctrl_power_off_device (tmp); + } +of_node_put (child); +return ret; }
---
base-commit: 028f86457e822ab9de5b0d6d23efddc1b8b54ae1
change-id: 20260908-pwrtctl-power-on-rallback-5c6364b080ce
Best regards,
Signature · 1 line
Lorenzo Bianconi <[email protected]>
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 13 lines
pci_pwrctrl_power_on_device()recursively powers on the child nodes of a device before powering on the device itself. If powering on a child fails (e.g. returning -EPROBE_DEFER), the function returned immediately, leaving the sibling children that were already powered on in the same loop iteration enabled.Since probe deferral is a standard boot path, this leads to unbounded regulator and clock enable increments across retries. The error path in
pci_pwrctrl_power_on_devices()only powers off the top-level children processed before the failing one and explicitly stops at it, so it can never clean up the siblings leaked deeper in the failed subtree.
Quoted 8 lines
Power off the sibling children that were successfully powered on before a child fails, and power off all children if the device's own
power_on()fails after its children were already enabled. Switch to a manual child iterator so the failing node can be tracked and its reference released in the error path.Fixes b35cf3b6aa1e ("PCI/pwrctrl: Add APIs to power on/off pwrctrl devices")Signed-off-by Lorenzo Bianconi <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260909-pwrtctl-power-on-rallback-v1-1-412ef996ba27@oss.qualcomm.com?part=1
Quoted 13 lines · Lorenzo Bianconi
pci_pwrctrl_power_on_device()recursively powers on the child nodes of a device before powering on the device itself. If powering on a child fails (e.g. returning -EPROBE_DEFER), the function returned immediately, leaving the sibling children that were already powered on in the same loop iteration enabled.Since probe deferral is a standard boot path, this leads to unbounded regulator and clock enable increments across retries. The error path in
pci_pwrctrl_power_on_devices()only powers off the top-level children processed before the failing one and explicitly stops at it, so it can never clean up the siblings leaked deeper in the failed subtree.
Quoted 8 lines
Power off the sibling children that were successfully powered on before a child fails, and power off all children if the device's own
power_on()fails after its children were already enabled. Switch to a manual child iterator so the failing node can be tracked and its reference released in the error path.Fixes b35cf3b6aa1e ("PCI/pwrctrl: Add APIs to power on/off pwrctrl devices")Signed-off-by Lorenzo Bianconi <[email protected]>
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Quoted 19 lines · Lorenzo Bianconi
pci_pwrctrl_power_on_device()recursively powers on the child nodes of a device before powering on the device itself. If powering on a child fails (e.g. returning -EPROBE_DEFER), the function returned immediately, leaving the sibling children that were already powered on in the same loop iteration enabled.Since probe deferral is a standard boot path, this leads to unbounded regulator and clock enable increments across retries. The error path in
pci_pwrctrl_power_on_devices()only powers off the top-level children processed before the failing one and explicitly stops at it, so it can never clean up the siblings leaked deeper in the failed subtree.Power off the sibling children that were successfully powered on before a child fails, and power off all children if the device's own
power_on()fails after its children were already enabled. Switch to a manual child iterator so the failing node can be tracked and its reference released in the error path.
Quoted 3 lines
Fixes b35cf3b6aa1e ("PCI/pwrctrl: Add APIs to power on/off pwrctrl devices")Signed-off-by Lorenzo Bianconi <[email protected]>---
Quoted 13 lines
pci_pwrctrl_power_on_device()recursively powers on the child nodes of a device before powering on the device itself. If powering on a child fails (e.g. returning -EPROBE_DEFER), the function returned immediately, leaving the sibling children that were already powered on in the same loop iteration enabled.Since probe deferral is a standard boot path, this leads to unbounded regulator and clock enable increments across retries. The error path in
pci_pwrctrl_power_on_devices()only powers off the top-level children processed before the failing one and explicitly stops at it, so it can never clean up the siblings leaked deeper in the failed subtree.
Quoted 8 lines
Power off the sibling children that were successfully powered on before a child fails, and power off all children if the device's own
power_on()fails after its children were already enabled. Switch to a manual child iterator so the failing node can be tracked and its reference released in the error path.Fixes b35cf3b6aa1e ("PCI/pwrctrl: Add APIs to power on/off pwrctrl devices")Signed-off-by Lorenzo Bianconi <[email protected]>
Hi all,
do you have any update about this fix? Thanks in advance.
Regards,
Lorenzo
Quoted 56 lines
--- drivers/pci/pwrctrl/core.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)drivers/pci/pwrctrl/core.c +17
-3@@ -252,14 +252,16 @@ static int __pci_pwrctrl_power_on_device(struct device *dev)static int pci_pwrctrl_power_on_device (struct device_node *np) {struct platform_device *pdev; +struct device_node *child;int ret =0 ; -for_each_available_child_of_node_scoped (np, child) { +for_each_available_child_of_node (np, child) { ret =pci_pwrctrl_power_on_device (child);if (ret) -return ret; + goto err_power_off; } + child =NULL ;if (!pci_pwrctrl_is_required (np))return 0 ;@@ -279,6 +281,19 @@ static int pci_pwrctrl_power_on_device(struct device_node *np)platform_device_put (pdev); +if (ret) + goto err_power_off; + +return 0 ; + +err_power_off: +for_each_available_child_of_node_scoped (np, tmp) { +if (tmp == child) +break ; +pci_pwrctrl_power_off_device (tmp); + } +of_node_put (child); +return ret; } ---base-commit:
028f86457e822ab9de5b0d6d23efddc1b8b54ae1
change-id: 20260908-pwrtctl-power-on-rallback-5c6364b080ceBest regards,
Signature · 1 line
Lorenzo Bianconi <[email protected]>
Bjorn Helgaas
AppliedQuoted 13 lines · Lorenzo Bianconi
pci_pwrctrl_power_on_device()recursively powers on the child nodes of a device before powering on the device itself. If powering on a child fails (e.g. returning -EPROBE_DEFER), the function returned immediately, leaving the sibling children that were already powered on in the same loop iteration enabled.Since probe deferral is a standard boot path, this leads to unbounded regulator and clock enable increments across retries. The error path in
pci_pwrctrl_power_on_devices()only powers off the top-level children processed before the failing one and explicitly stops at it, so it can never clean up the siblings leaked deeper in the failed subtree.
Quoted 8 lines
Power off the sibling children that were successfully powered on before a child fails, and power off all children if the device's own
power_on()fails after its children were already enabled. Switch to a manual child iterator so the failing node can be tracked and its reference released in the error path.Fixes b35cf3b6aa1e ("PCI/pwrctrl: Add APIs to power on/off pwrctrl devices")Signed-off-by Lorenzo Bianconi <[email protected]>
Applied to pci/pwrctrl for v7.4, thanks!
Quoted 56 lines
--- drivers/pci/pwrctrl/core.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)drivers/pci/pwrctrl/core.c +17
-3@@ -252,14 +252,16 @@ static int __pci_pwrctrl_power_on_device(struct device *dev)static int pci_pwrctrl_power_on_device (struct device_node *np) {struct platform_device *pdev; +struct device_node *child;int ret =0 ; -for_each_available_child_of_node_scoped (np, child) { +for_each_available_child_of_node (np, child) { ret =pci_pwrctrl_power_on_device (child);if (ret) -return ret; + goto err_power_off; } + child =NULL ;if (!pci_pwrctrl_is_required (np))return 0 ;@@ -279,6 +281,19 @@ static int pci_pwrctrl_power_on_device(struct device_node *np)platform_device_put (pdev); +if (ret) + goto err_power_off; + +return 0 ; + +err_power_off: +for_each_available_child_of_node_scoped (np, tmp) { +if (tmp == child) +break ; +pci_pwrctrl_power_off_device (tmp); + } +of_node_put (child); +return ret; } ---base-commit:
028f86457e822ab9de5b0d6d23efddc1b8b54ae1
change-id: 20260908-pwrtctl-power-on-rallback-5c6364b080ceBest regards,
Signature · 1 line
Lorenzo Bianconi <[email protected]>