Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>
Cc: conor+dt@kernel.org, Frank.Li@kernel.org, imx@lists.linux.dev,
	robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH 03/23] slimbus: qcom-ngd-ctrl: fix OF node refcount
Date: Sat, 30 May 2026 00:45:42 +0000	[thread overview]
Message-ID: <20260530004542.92B461F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260521-pdev-fwnode-ref-v1-3-88c324a1b8d2@oss.qualcomm.com>

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

Pre-existing issues:
- [High] Probe error path bypasses cleanup, leaking PDR handle, SSR notifier, and leading to Use-After-Free.
- [High] The dynamically allocated child platform device is never unregistered upon module removal or driver unbind.
- [High] Hardware interrupt handler is registered before underlying structures are fully initialized.
- [High] Unsafe registration of the global platform driver within the controller's probe function.
- [High] Unchecked dereference of `of_match_node()` return value leads to a potential NULL pointer dereference.
- [High] SSR notifier can execute before work_struct initialization, causing a kernel crash.
- [High] Missing cancellation of `ngd_up_work` during device removal causes a Use-After-Free.
- [High] DMA coherent memory is leaked on every suspend/resume cycle.
--

commit a849bb0b2b8baaf7273c84580d82b6ab6bc55f3a
Author: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

slimbus: qcom-ngd-ctrl: fix OF node refcount

This commit fixes an OF node reference counting issue when using the split
approach for platform device creation. It adds a missing call to of_node_get()
before platform_device_add(), preventing an unbalanced of_node_put() when the
platform device is released.

> diff --git a/drivers/slimbus/qcom-ngd-ctrl.c b/drivers/slimbus/qcom-ngd-ctrl.c
> index 1ed6be6e85d2c..428266949fdd0 100644
> --- a/drivers/slimbus/qcom-ngd-ctrl.c
> +++ b/drivers/slimbus/qcom-ngd-ctrl.c
> @@ -1542,7 +1542,7 @@ static int of_qcom_slim_ngd_register(struct device *parent,

[Severity: High]
This isn't a bug introduced by this patch, but in of_qcom_slim_ngd_register(),
the result of of_match_node() is immediately dereferenced.

If the parent device lacks a valid of_node (for example, if it is instantiated
manually or bound via sysfs), the match variable will be NULL. Could this
cause a kernel panic?

>  			kfree(ngd);
>  			return ret;
>  		}
> -		ngd->pdev->dev.of_node = node;
> +		ngd->pdev->dev.of_node = of_node_get(node);
>  		ctrl->ngd = ngd;
>  
>  		ret = platform_device_add(ngd->pdev);

[Severity: High]
This is a pre-existing issue, but of_qcom_slim_ngd_register() dynamically
allocates and adds a child platform device (ngd->pdev).

Do the controller removal function or the child device's unbind path ever
call platform_device_unregister() for this device?

If not, doesn't this cause memory and device leaks, permanently leak the
of_node reference, and prevent module reloading due to sysfs name collisions
in platform_device_add()?

[Severity: High]
This is a pre-existing issue, but if of_qcom_slim_ngd_register() fails, does
the probe function return the error directly and bypass the err_pdr_alloc and
err_pdr_lookup cleanup labels?

This would leave the SSR notifier registered. Because ctrl is managed by
devm_kzalloc(), it is freed upon probe failure. If the SSR notifier later
fires, won't it access the freed ctrl structure and lead to a Use-After-Free?
Additionally, are the cleanup labels incorrectly ordered?

[Severity: High]
This isn't a bug introduced by this patch, but in qcom_slim_ngd_ctrl_probe(),
devm_request_irq() registers qcom_slim_ngd_interrupt() before ctrl->ngd and
ctrl->ctrl.dev are assigned in the subsequent registration steps.

Could an early or spurious interrupt dereference these NULL pointers and lead
to a kernel panic?

[Severity: High]
This is a pre-existing issue, but platform_driver_register() is called for
qcom_slim_ngd_driver directly inside the controller's probe function.

Doesn't this break driver model semantics? If multiple controller instances
exist, subsequent registrations would fail. When any single controller
instance is removed, qcom_slim_ngd_ctrl_remove() unregisters this global
driver. Wouldn't that forcibly unbind all child devices across all active
controller instances?

[Severity: High]
This is a pre-existing issue, but the SSR notifier is registered in
qcom_slim_ngd_ctrl_probe() before the child device's probe function
initializes the ngd_up_work structure via INIT_WORK().

If the service is already UP, won't the notifier callback fire immediately
and call schedule_work(&ctrl->ngd_up_work) on a zero-initialized
work_struct, leading to a kernel crash?

[Severity: High]
This isn't a bug introduced by this patch, but the driver appears to fail to
call cancel_work_sync(&ctrl->ngd_up_work) in its remove path.

If an SSR event schedules this work on the system workqueue right before the
device is removed, wouldn't the work remain pending and execute after devm
has freed the ctrl structure, causing a Use-After-Free?

[Severity: High]
This is a pre-existing issue, but qcom_slim_ngd_init_dma() allocates DMA
memory for ctrl->rx_base and ctrl->tx_base using dma_alloc_coherent(), which
runs during setup and runtime resume.

However, the teardown function qcom_slim_ngd_exit_dma() only terminates the
DMA channels and never calls dma_free_coherent(). Doesn't this lead to a
repeated DMA memory leak on every suspend/resume cycle?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260521-pdev-fwnode-ref-v1-0-88c324a1b8d2@oss.qualcomm.com?part=3

  reply	other threads:[~2026-05-30  0:45 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21  8:36 [PATCH 00/23] driver core: count references of the platform device's fwnode, not OF node Bartosz Golaszewski
2026-05-21  8:36 ` [PATCH 01/23] mfd: tps6586x: fix OF node refcount Bartosz Golaszewski
2026-05-27 15:36   ` (subset) " Lee Jones
2026-05-30  0:45   ` sashiko-bot
2026-05-21  8:36 ` [PATCH 02/23] net: mv643xx: " Bartosz Golaszewski
2026-05-21  8:36 ` [PATCH 03/23] slimbus: qcom-ngd-ctrl: " Bartosz Golaszewski
2026-05-30  0:45   ` sashiko-bot [this message]
2026-05-21  8:36 ` [PATCH 04/23] pmdomain: imx: " Bartosz Golaszewski
2026-05-30  0:45   ` sashiko-bot
2026-05-21  8:36 ` [PATCH 05/23] powerpc/powermac: " Bartosz Golaszewski
2026-05-21  8:36 ` [PATCH 06/23] driver core: platform: provide platform_device_set_of_node() Bartosz Golaszewski
2026-05-21  8:36 ` [PATCH 07/23] driver core: platform: provide platform_device_set_fwnode() Bartosz Golaszewski
2026-05-21  8:36 ` [PATCH 08/23] driver core: platform: provide platform_device_set_of_node_from_dev() Bartosz Golaszewski
2026-05-21  8:36 ` [PATCH 09/23] of: platform: use platform_device_set_of_node() Bartosz Golaszewski
2026-05-21  8:36 ` [PATCH 10/23] powerpc/powermac: " Bartosz Golaszewski
2026-05-21  8:36 ` [PATCH 11/23] i2c: pxa-pci: " Bartosz Golaszewski
2026-05-21  9:13   ` Wolfram Sang
2026-05-30  0:45   ` sashiko-bot
2026-05-21  8:36 ` [PATCH 12/23] iommu/fsl: " Bartosz Golaszewski
2026-05-21  9:44   ` Robin Murphy
2026-05-21  8:36 ` [PATCH 13/23] net: bcmgenet: " Bartosz Golaszewski
2026-05-30  0:45   ` sashiko-bot
2026-05-21  8:36 ` [PATCH 14/23] pmdomain: imx: " Bartosz Golaszewski
2026-05-30  0:45   ` sashiko-bot
2026-05-21  8:36 ` [PATCH 15/23] mfd: tps6586: " Bartosz Golaszewski
2026-05-27 15:31   ` Lee Jones
2026-05-30  0:45   ` sashiko-bot
2026-05-21  8:36 ` [PATCH 16/23] slimbus: qcom-ngd-ctrl: " Bartosz Golaszewski
2026-05-30  0:45   ` sashiko-bot
2026-05-21  8:36 ` [PATCH 17/23] net: mv643xx: " Bartosz Golaszewski
2026-05-30  0:45   ` sashiko-bot
2026-05-21  8:36 ` [PATCH 18/23] drm/xe/i2c: use platform_device_set_fwnode() Bartosz Golaszewski
2026-05-30  0:45   ` sashiko-bot
2026-05-21  8:36 ` [PATCH 19/23] platform/surface: gpe: " Bartosz Golaszewski
2026-05-28 11:21   ` Ilpo Järvinen
2026-05-21  8:36 ` [PATCH 20/23] usb: chipidea: use platform_device_set_of_node_from_dev() Bartosz Golaszewski
2026-05-21  8:36 ` [PATCH 21/23] usb: musb: " Bartosz Golaszewski
2026-05-21  8:36 ` [PATCH 22/23] reset: rzg2l: " Bartosz Golaszewski
2026-05-21  8:36 ` [PATCH 23/23] driver core: platform: count references to all kinds of firmware nodes Bartosz Golaszewski
2026-05-30  0:45   ` sashiko-bot
2026-05-29 12:55 ` (subset) [PATCH 00/23] driver core: count references of the platform device's fwnode, not OF node Srinivas Kandagatla

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=20260530004542.92B461F00899@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@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