Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chen-Yu Tsai" <wenst@chromium.org>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v5 12/16] power: sequencing: pcie-m2: support matching on remote "port" node
Date: Wed, 15 Jul 2026 09:29:25 +0000	[thread overview]
Message-ID: <20260715092926.028BA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260715085348.3457359-13-wenst@chromium.org>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing `serdev_controller_put()` in `pwrseq_pcie_m2_create_serdev_one()` returns path.
- [High] Unchecked `pdev->dev.parent` in `pwrseq_pcie_m2_notify()` leads to NULL pointer dereference.
- [High] Mixing `devm` registration with manual resource cleanup causes Use-After-Free of regulator consumers.
--

--- Patch [12]: [PATCH v5 12/16] power: sequencing: pcie-m2: support matching on remote "port" node ---
commit 8eb380a4e579162e00e556321400077f29d6c07e
Author: Chen-Yu Tsai <wenst@chromium.org>

power: sequencing: pcie-m2: support matching on remote "port" node

This commit updates the pcie-m2 power sequencing driver to support matching
against remote "port" nodes for USB hubs. It uses of_graph_get_remote_port()
and falls back to the remote port parent for other connection types. It
also updates the existing matching logic to use device_match_of_node().

> diff --git a/drivers/power/sequencing/pwrseq-pcie-m2.c b/drivers/power/sequencing/pwrseq-pcie-m2.c
> index ddfe6ca824945..01f9f6a717464 100644
> --- a/drivers/power/sequencing/pwrseq-pcie-m2.c
> +++ b/drivers/power/sequencing/pwrseq-pcie-m2.c
> @@ -175,9 +175,16 @@ static int pwrseq_pcie_m2_match(struct pwrseq_device *pwrseq,
>  	 * parent matches the OF node of 'dev'.
>  	 */
>  	for_each_endpoint_of_node(ctx->of_node, endpoint) {
> +		/* USB port devices are tied to the port nodes. */
> +		struct device_node *remote_port __free(device_node) =
> +				of_graph_get_remote_port(endpoint);
> +		if (device_match_of_node(dev, remote_port))
> +			return PWRSEQ_MATCH_OK;
> +
> +		/* Try the remote port parent for other types. */
>  		struct device_node *remote __free(device_node) =
>  				of_graph_get_remote_port_parent(endpoint);
> -		if (remote && (remote == dev_of_node(dev)))
> +		if (device_match_of_node(dev, remote))
>  			return PWRSEQ_MATCH_OK;
>  	}
>  

[Severity: High]
This isn't a bug introduced by this patch, but does 
pwrseq_pcie_m2_create_serdev_one() leak the serdev_ctrl reference on the
early return path?

If the serdev device was already created for the PCI device, the list
iteration returns 0 directly:

drivers/power/sequencing/pwrseq-pcie-m2.c:pwrseq_pcie_m2_create_serdev_one() {
    ...
    scoped_guard(mutex, &ctx->list_lock) {
        list_for_each_entry(pci_dev, &ctx->pci_devices, list) {
            if (pci_dev->pdev == pdev)
                return 0;
        }
    }
    ...
}

This appears to bypass the serdev_controller_put(serdev_ctrl) cleanup. Could
this accumulate leaked references during PCI bus probing or device
notification callbacks?

[Severity: High]
This is a pre-existing issue, but could pwrseq_pcie_m2_notify() trigger a
NULL pointer dereference on systems with a root PCI bus?

Some bus scanning flows use pci_create_root_bus(NULL, ...), where devices
have no parent. The BUS_NOTIFY_ADD_DEVICE notifier is registered globally
and evaluates this without checking if pdev->dev.parent is NULL:

drivers/power/sequencing/pwrseq-pcie-m2.c:pwrseq_pcie_m2_notify() {
    ...
    if (!pci_parent || (pci_parent != pdev->dev.parent->of_node))
        return NOTIFY_DONE;
    ...
}

Could this cause a kernel panic during PCI bus probing on affected systems
when the driver is active?

[Severity: High]
This isn't a bug introduced by this patch, but does mixing devm registration
with manual regulator cleanup cause a use-after-free?

In the probe error path and remove function, the regulators are manually
freed:

drivers/power/sequencing/pwrseq-pcie-m2.c:pwrseq_pcie_m2_probe() {
    ...
err_free_regulators:
    regulator_bulk_free(ctx->num_vregs, ctx->regs);
    ...
}

drivers/power/sequencing/pwrseq-pcie-m2.c:pwrseq_pcie_m2_remove() {
    ...
    regulator_bulk_free(ctx->num_vregs, ctx->regs);
    ...
}

Since the power sequencer device is registered via
devm_pwrseq_device_register(), it remains active until the devres teardown
runs after the function returns. If a consumer calls a power sequencing
operation during this window, or if the driver is unbound via sysfs, will
it access the freed regulator consumer objects?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260715085348.3457359-1-wenst@chromium.org?part=12

  reply	other threads:[~2026-07-15  9:29 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15  8:53 [PATCH v5 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
2026-07-15  8:53 ` [PATCH v5 01/16] device property: Add fwnode_graph_get_port_by_id() Chen-Yu Tsai
2026-07-15  9:03   ` sashiko-bot
2026-07-15  8:53 ` [PATCH v5 02/16] device property: Add fwnode_graph_get_next_port_endpoint() Chen-Yu Tsai
2026-07-15  9:09   ` sashiko-bot
2026-07-15  8:53 ` [PATCH v5 03/16] power: sequencing: Add pwrseq_power_is_on() Chen-Yu Tsai
2026-07-15  9:08   ` sashiko-bot
2026-07-15  9:29   ` Andy Shevchenko
2026-07-15 12:10     ` Bartosz Golaszewski
2026-07-15  8:53 ` [PATCH v5 04/16] usb: hub: Use assign_bit() in usb_hub_set_port_power() Chen-Yu Tsai
2026-07-15  9:11   ` Andy Shevchenko
2026-07-15  8:53 ` [PATCH v5 05/16] usb: hub: Return actual error from hub_configure() in hub_probe() Chen-Yu Tsai
2026-07-15  8:53 ` [PATCH v5 06/16] usb: hub: Associate port@ fwnode with USB port device Chen-Yu Tsai
2026-07-15  9:20   ` Andy Shevchenko
2026-07-15  8:53 ` [PATCH v5 07/16] usb: core: Move struct usb_port and related APIs to port.h Chen-Yu Tsai
2026-07-15  9:31   ` Andy Shevchenko
2026-07-15  8:53 ` [PATCH v5 08/16] usb: hub: Pass |struct usb_port*| to usb_port_is_power_on() Chen-Yu Tsai
2026-07-15  8:53 ` [PATCH v5 09/16] usb: hub: Use usb_hub_set_port_power() to control port power everywhere Chen-Yu Tsai
2026-07-15  8:53 ` [PATCH v5 10/16] usb: hub: Power on connected M.2 E-key connectors with power sequencing API Chen-Yu Tsai
2026-07-15  9:28   ` sashiko-bot
2026-07-15  8:53 ` [PATCH v5 11/16] dt-bindings: usb: mediatek,mtk-xhci: Switch to ports for USB connections Chen-Yu Tsai
2026-07-15  8:53 ` [PATCH v5 12/16] power: sequencing: pcie-m2: support matching on remote "port" node Chen-Yu Tsai
2026-07-15  9:29   ` sashiko-bot [this message]
2026-07-15  8:53 ` [PATCH v5 13/16] power: sequencing: pcie-m2: Add usb and sdio targets for E-key connector Chen-Yu Tsai
2026-07-15  9:34   ` sashiko-bot
2026-07-15  8:53 ` [PATCH v5 14/16] power: sequencing: pcie-m2: Split Bluetooth unit based on interface Chen-Yu Tsai
2026-07-15  9:34   ` sashiko-bot
2026-07-15  8:53 ` [PATCH v5 15/16] arm64: dts: mediatek: mt8195-cherry: Add M.2 E-key slot Chen-Yu Tsai
2026-07-15  9:45   ` sashiko-bot
2026-07-15  8:53 ` [PATCH v5 16/16] arm64: dts: mediatek: mt8188-geralt: Add WiFi/BT as " Chen-Yu Tsai

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=20260715092926.028BA1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wenst@chromium.org \
    /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