Re: [PATCH v4 4/8] PCI/pwrctrl: Add APIs to power on/off the pwrctrl devices

From: Bjorn Helgaas

Date: Sun Jan 11 2026 - 22:27:20 EST


On Mon, Jan 05, 2026 at 07:25:44PM +0530, Manivannan Sadhasivam via B4 Relay wrote:
> From: Manivannan Sadhasivam <manivannan.sadhasivam@xxxxxxxxxxxxxxxx>
>
> To fix PCIe bridge resource allocation issues when powering PCIe
> switches with the pwrctrl driver, introduce APIs to explicitly power
> on and off all related devices simultaneously.
> ...

> +static void pci_pwrctrl_power_off_device(struct device_node *np)
> +{
> + struct platform_device *pdev;
> + int ret;
> +
> + for_each_available_child_of_node_scoped(np, child)
> + pci_pwrctrl_power_off_device(child);
> +
> + pdev = of_find_device_by_node(np);
> + if (pdev) {
> + if (device_is_bound(&pdev->dev)) {
> + ret = __pci_pwrctrl_power_off_device(&pdev->dev);
> + if (ret)
> + dev_err(&pdev->dev, "Failed to power off device: %d", ret);
> + }
> +
> + platform_device_put(pdev);
> + }

Suggest this to reduce indentation:

pdev = of_find_device_by_node(np);
if (!pdev)
return;

if (device_is_bound(&pdev->dev)) {
...
}

platform_device_put(pdev);

> +static int pci_pwrctrl_power_on_device(struct device_node *np)
> +{
> + struct platform_device *pdev;
> + int ret;
> +
> + for_each_available_child_of_node_scoped(np, child) {
> + ret = pci_pwrctrl_power_on_device(child);
> + if (ret)
> + return ret;
> + }
> +
> + pdev = of_find_device_by_node(np);
> + if (pdev) {
> + if (!device_is_bound(&pdev->dev)) {
> + /* FIXME: Use blocking wait instead of probe deferral */
> + dev_dbg(&pdev->dev, "driver is not bound\n");
> + ret = -EPROBE_DEFER;
> + } else {
> + ret = __pci_pwrctrl_power_on_device(&pdev->dev);
> + }
> + platform_device_put(pdev);
> +
> + if (ret)
> + return ret;
> + }
> +
> + return 0;

And this:

pdev = of_find_device_by_node(np);
if (!pdev)
return 0;

if (device_is_bound(&pdev->dev)) {
...
} else {
...
}

platform_device_put(pdev);

return ret;