From: sashiko-bot@kernel.org
To: "Yureka Lilian" <yureka@cyberchaos.dev>
Cc: linux-pci@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 2/3] PCI: apple: Integrate pwrctrl API
Date: Wed, 04 Nov 2026 11:51:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-197213@kernel.org> (raw)
In-Reply-To: <20261104-apple-pcie-pwren-v2-2-216a4066965f@cyberchaos.dev>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] PCI: apple: unbalanced pwrctrl power and device cleanup in apple_pcie_init()
--
commit 3ba5f942a54bed93131c2e3157428ab3600ebf03
Author: Yureka Lilian <yureka@cyberchaos.dev>
PCI: apple: Integrate pwrctrl API
This commit integrates the PCI pwrctrl API into the Apple PCIe host
controller driver so child port devices are created and powered on before
setting up the ports in apple_pcie_init().
> diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
> index c2cffc0659f44..2d32092e2122b 100644
> --- a/drivers/pci/controller/pcie-apple.c
> +++ b/drivers/pci/controller/pcie-apple.c
[ ... ]
> @@ -825,6 +826,28 @@ static int apple_pcie_init(struct pci_config_window *cfg)
> if (WARN_ON(!pcie))
> return -ENOENT;
>
> + // Ensure all ports can be powered on before attempting initialization
> + for_each_available_child_of_node_scoped(dev->of_node, of_port) {
> + ret = pci_pwrctrl_create_device(of_port, pcie->dev);
> + if (ret) {
> + dev_err(pcie->dev, "Failed to create pwrctrl device: %pe\n", ERR_PTR(ret));
> + return ret;
> + }
> +
> + ret = pci_pwrctrl_power_on_device(of_port);
> + if (ret) {
> + if (ret != -EPROBE_DEFER) {
> + dev_err(pcie->dev,
> + "Failed to power on device: %pe\n",
> + ERR_PTR(ret));
> + for_each_available_child_of_node_scoped(dev->of_node, of_port) {
> + pci_pwrctrl_destroy_device(of_port);
> + }
> + }
> + return ret;
> + }
> + }
> +
> for_each_available_child_of_node_scoped(dev->of_node, of_port) {
> ret = apple_pcie_setup_port(pcie, of_port);
> if (ret) {
[Severity: Medium]
Can this loop in apple_pcie_init() leave pwrctrl devices powered on or leaked
when an error or probe deferral occurs on a multi-port controller?
If an earlier port succeeds in both pci_pwrctrl_create_device() and
pci_pwrctrl_power_on_device(), and a subsequent port fails in:
1. pci_pwrctrl_create_device(): apple_pcie_init() returns immediately without
powering off or destroying the pwrctrl devices created and powered on in
previous iterations.
2. pci_pwrctrl_power_on_device() with -EPROBE_DEFER:
pci_pwrctrl_power_on_device() only unwinds children of the failing port
node, leaving earlier sibling ports powered on. When deferred probing
retries apple_pcie_init(), pci_pwrctrl_power_on_device() is called again
on the earlier ports, enabling their regulators and clocks a second time
and leaking enable reference counts on every retry.
3. pci_pwrctrl_power_on_device() with a non-deferral error: the error path
calls pci_pwrctrl_destroy_device() without first calling
pci_pwrctrl_power_off_device() on the ports that were already powered on,
which unregisters active pwrctrl platform devices and frees regulators
while they are still enabled. The inner
for_each_available_child_of_node_scoped(dev->of_node, of_port) loop also
redeclares of_port and shadows the outer loop variable (-Wshadow).
4. apple_pcie_setup_port() in the second loop: if port setup fails or returns
-EPROBE_DEFER (for example from devm_fwnode_gpiod_get()), apple_pcie_init()
returns without powering off the pwrctrl devices enabled in the first loop
or destroying them on non-deferral errors.
Would it be cleaner to use the controller-level helpers
pci_pwrctrl_create_devices(), pci_pwrctrl_power_on_devices(),
pci_pwrctrl_power_off_devices(), and pci_pwrctrl_destroy_devices() with goto
error unwinding so all ports are balanced properly?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261104-apple-pcie-pwren-v2-0-216a4066965f@cyberchaos.dev?part=2
next prev parent reply other threads:[~2026-11-04 11:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 11:40 [PATCH v2 0/3] PCI: apple: Integrate pwrctrl API Yureka Lilian
2026-11-04 11:40 ` [PATCH v2 1/3] PCI/pwrctrl: Export per-device APIs Yureka Lilian
2026-11-04 11:48 ` sashiko-bot
2026-11-04 11:40 ` [PATCH v2 2/3] PCI: apple: Integrate pwrctrl API Yureka Lilian
2026-11-04 11:51 ` sashiko-bot [this message]
2026-11-04 13:41 ` Janne Grunau
2026-11-04 11:40 ` [PATCH v2 3/3] arm64: dts: apple: t600x: Add PCIe pwren gpios Yureka Lilian
2026-11-04 11:58 ` sashiko-bot
2026-11-04 13:57 ` Janne Grunau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-197213@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yureka@cyberchaos.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox