From: sashiko-bot@kernel.org
To: "Manivannan Sadhasivam via B4 Relay"
<devnull+manivannan.sadhasivam.oss.qualcomm.com@kernel.org>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v2 4/9] power: sequencing: pcie-m2: Create serdev for PCI devices present before probe
Date: Thu, 07 May 2026 23:54:51 +0000 [thread overview]
Message-ID: <20260507235452.10C62C2BCB2@smtp.kernel.org> (raw)
In-Reply-To: <20260507-pwrseq-m2-bt-v2-4-1740bd478539@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Reference leak of 'serdev_ctrl' on early return in '__pwrseq_pcie_m2_create_serdev()'.
- [High] Potential NULL pointer dereference in 'pwrseq_pcie_m2_notify()' when accessing 'pdev->dev.parent->of_node'.
- [Medium] Subsystem guidelines violation: mixing 'goto' error handling with '__free()' cleanup helpers.
--
commit 1d901a33bb02968191e0403afce66cf3ae8ed0f3
Author: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
power: sequencing: pcie-m2: Create serdev for PCI devices present before probe
This commit adds support to create serdev devices for PCI devices that
are already present before the driver's probe function registers the
PCI notifier.
> --- a/drivers/power/sequencing/pwrseq-pcie-m2.c
> +++ b/drivers/power/sequencing/pwrseq-pcie-m2.c
> @@ -236,7 +236,7 @@ static int pwrseq_pcie_m2_create_bt_node(struct pwrseq_pcie_m2_ctx *ctx,
> return ret;
> }
>
> -static int pwrseq_pcie_m2_create_serdev(struct pwrseq_pcie_m2_ctx *ctx,
> +static int __pwrseq_pcie_m2_create_serdev(struct pwrseq_pcie_m2_ctx *ctx,
> struct pci_dev *pdev)
> {
> struct serdev_controller *serdev_ctrl;
[ ... ]
> /* Bail out if the device was already attached to this controller */
> if (serdev_ctrl->serdev) {
> serdev_controller_put(serdev_ctrl);
> return 0;
> }
>
> + /* Bail out if the serdev device was already created for the PCI dev */
> + mutex_lock(&ctx->list_lock);
> + list_for_each_entry(pci_dev, &ctx->pci_devices, list) {
> + if (pci_dev->pdev == pdev) {
> + mutex_unlock(&ctx->list_lock);
> + return 0;
Does this early return path leak the reference to serdev_ctrl?
The of_find_serdev_controller_by_node() call earlier in the function acquires
a reference, and the previous bailout path correctly calls
serdev_controller_put(serdev_ctrl), but this new path appears to return
without releasing the reference.
Also, looking at the rest of __pwrseq_pcie_m2_create_serdev() in the source,
it declares serdev_parent using the __free(device_node) macro while also
using goto labels for error paths like err_put_ctrl. Does this mix of goto
and __free() cleanup helpers violate the subsystem guidelines?
[ ... ]
> +static int pwrseq_pcie_m2_create_serdev(struct pwrseq_pcie_m2_ctx *ctx)
> +{
> + struct pci_dev *pdev = NULL;
> + int ret;
> +
> + if (!pwrseq_pcie_m2_check_remote_node(ctx->dev, 3, 0, "serial") ||
> + !pwrseq_pcie_m2_check_remote_node(ctx->dev, 0, 0, "pcie"))
> + return 0;
> +
> + struct device_node *pci_parent __free(device_node) =
> + of_graph_get_remote_node(dev_of_node(ctx->dev), 0, 0);
> + if (!pci_parent)
> + return 0;
> +
> + /* Create serdev for existing PCI devices if required */
> + for_each_pci_dev(pdev) {
> + if (!pdev->dev.parent || pci_parent != pdev->dev.parent->of_node)
> + continue;
It is good to see the defensive !pdev->dev.parent check here to prevent a
null pointer dereference.
However, the existing pwrseq_pcie_m2_notify() function performs a similar
check without validating the parent:
if (!pci_parent || (pci_parent != pdev->dev.parent->of_node))
Could a PCI device without a parent triggering a BUS_NOTIFY_ADD_DEVICE
event cause a crash in pwrseq_pcie_m2_notify() because it is missing the
same defensive check?
[ ... ]
> + ret = __pwrseq_pcie_m2_create_serdev(ctx, pdev);
> + if (ret) {
> + dev_err_probe(ctx->dev, ret,
> + "Failed to create serdev for PCI device (%s)\n",
> + pci_name(pdev));
> + pci_dev_put(pdev);
> + goto err_remove_serdev;
> }
> }
>
> return 0;
> +
> +err_remove_serdev:
> + pwrseq_pcie_m2_remove_serdev(ctx, NULL);
> +
> + return ret;
> }
Similar to the function above, this newly added function mixes the
__free(device_node) cleanup helper for pci_parent with the err_remove_serdev
goto label. Should all resources here be converted to scope-based cleanup to
avoid ownership confusion?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260507-pwrseq-m2-bt-v2-0-1740bd478539@oss.qualcomm.com?part=4
next prev parent reply other threads:[~2026-05-07 23:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 16:06 [PATCH v2 0/9] Fixes/improvements for the PCI M.2 power sequencing driver Manivannan Sadhasivam via B4 Relay
2026-05-07 16:06 ` [PATCH v2 1/9] power: sequencing: pcie-m2: Fix inconsistent function prefixes Manivannan Sadhasivam via B4 Relay
2026-05-07 16:06 ` [PATCH v2 2/9] power: sequencing: pcie-m2: Allow creating serdev for multiple PCI devices Manivannan Sadhasivam via B4 Relay
2026-05-07 23:28 ` sashiko-bot
2026-05-07 16:06 ` [PATCH v2 3/9] power: sequencing: pcie-m2: Improve PCI device ID check Manivannan Sadhasivam via B4 Relay
2026-05-07 16:06 ` [PATCH v2 4/9] power: sequencing: pcie-m2: Create serdev for PCI devices present before probe Manivannan Sadhasivam via B4 Relay
2026-05-07 23:54 ` sashiko-bot [this message]
2026-05-07 16:06 ` [PATCH v2 5/9] power: sequencing: pcie-m2: Create BT node based on the pci_device_id[] table Manivannan Sadhasivam via B4 Relay
2026-05-07 16:06 ` [PATCH v2 6/9] Bluetooth: hci_qca: Add M.2 Bluetooth device support using pwrseq Manivannan Sadhasivam via B4 Relay
2026-05-08 0:44 ` sashiko-bot
2026-05-07 16:06 ` [PATCH v2 7/9] Bluetooth: hci_qca: Rename 'power_ctrl_enabled' to 'bt_en_available' Manivannan Sadhasivam via B4 Relay
2026-05-08 0:53 ` sashiko-bot
2026-05-11 11:34 ` Bartosz Golaszewski
2026-05-07 16:06 ` [PATCH v2 8/9] power: sequencing: Add an API to return the pwrseq device's 'dev' pointer Manivannan Sadhasivam via B4 Relay
2026-05-08 1:16 ` sashiko-bot
2026-05-11 11:34 ` Bartosz Golaszewski
2026-05-07 16:06 ` [PATCH v2 9/9] Bluetooth: hci_qca: Set 'bt_en_available' based on W_DISABLE2# presence in M.2 connector Manivannan Sadhasivam via B4 Relay
2026-05-08 2:06 ` sashiko-bot
2026-05-11 11:36 ` Bartosz Golaszewski
2026-05-08 12:49 ` [PATCH v2 0/9] Fixes/improvements for the PCI M.2 power sequencing driver Wei Deng
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=20260507235452.10C62C2BCB2@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=devnull+manivannan.sadhasivam.oss.qualcomm.com@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko@lists.linux.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