Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org, conor+dt@kernel.org,
	imx@lists.linux.dev, lee@kernel.org, robh@kernel.org,
	mfd@lists.linux.dev, Frank.Li@kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v3 12/20] mfd: tps6586: use platform_device_set_of_node()
Date: Tue, 07 Jul 2026 13:24:59 +0000	[thread overview]
Message-ID: <20260707132459.6CEAD1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260706-pdev-fwnode-ref-v3-12-1ff028e33779@oss.qualcomm.com>

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

Pre-existing issues:
- [High] Subdevice cleanup unconditionally unregisters all children, prematurely removing MFD cell devices and bypassing `mfd_remove_devices_fn()`.
- [Medium] Manual assignment of `pdev->dev.platform_data` leads to invalid `kfree()`.
- [Medium] Missing IRQ domain and IRQ descriptors cleanup on teardown and error paths.
--

commit 0df04ec4b22ac2adb3b77bf67e6a1339f5fd4523
Author: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
mfd: tps6586: use platform_device_set_of_node()

This commit encapsulates the assignment of the OF node for dynamically
allocated platform devices by using the platform_device_set_of_node() helper.
This change prepares for reworking the reference counting logic for platform
devices.

> diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c
> index f5f8054466033..3cfd2f02b62f3 100644
> --- a/drivers/mfd/tps6586x.c
> +++ b/drivers/mfd/tps6586x.c
> @@ -397,7 +397,7 @@ static int tps6586x_add_subdevs(struct tps6586x *tps6586x,
>  
>  		pdev->dev.parent = tps6586x->dev;
>  		pdev->dev.platform_data = subdev->platform_data;

[Severity: Medium]
This is a pre-existing issue, but does this manual assignment of
platform_data at line 399 in tps6586x_add_subdevs() cause problems during
device release?

When the platform device is unregistered, platform_device_release()
unconditionally calls kfree(pdev->dev.platform_data).

If subdev->platform_data was statically allocated or part of devm_kzalloc
memory, could this corrupt the heap?

> -		pdev->dev.of_node = of_node_get(subdev->of_node);
> +		platform_device_set_of_node(pdev, subdev->of_node);
>  
>  		ret = platform_device_add(pdev);
>  		if (ret) {

[Severity: High]
This isn't a bug introduced by this patch, but does the cleanup in
tps6586x_remove_subdevs() interfere with MFD core cleanup?

drivers/mfd/tps6586x.c:tps6586x_remove_subdevs() {
    ...
    return device_for_each_child(tps6586x->dev, NULL, __remove_subdev);
}

drivers/mfd/tps6586x.c:__remove_subdev() {
    ...
    platform_device_unregister(to_platform_device(dev));
}

Since MFD cells added by mfd_add_devices() are children of tps6586x->dev,
this unconditional unregistering of all children appears to bypass
mfd_remove_devices_fn().

Could blindly casting dev to struct platform_device also be unsafe if any
child is not a platform device?

[Severity: Medium]
This is a pre-existing issue, but does the driver leak IRQ descriptors and
the IRQ domain during removal or on error paths?

In the removal path, tps6586x_i2c_remove() in drivers/mfd/tps6586x.c cleans
up other resources but misses IRQ cleanup:

drivers/mfd/tps6586x.c:tps6586x_i2c_remove() {
    struct tps6586x *tps6586x = i2c_get_clientdata(client);

    tps6586x_remove_subdevs(tps6586x);
    mfd_remove_devices(tps6586x->dev);
}

Additionally, if irq_domain_create_simple() or request_threaded_irq() fail
in tps6586x_irq_init():

drivers/mfd/tps6586x.c:tps6586x_irq_init() {
    ...
    if (!tps6586x->irq_domain) {
        dev_err(tps6586x->dev, "Failed to create IRQ domain\n");
        return -ENOMEM;
    }
    ...
}

The error paths exit without freeing the previously allocated descriptors or
domain. Can this cause resource leakage on cold paths?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260706-pdev-fwnode-ref-v3-0-1ff028e33779@oss.qualcomm.com?part=12

  reply	other threads:[~2026-07-07 13:25 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 12:44 [PATCH v3 00/20] driver core: count references of the platform device's fwnode, not OF node Bartosz Golaszewski
2026-07-06 12:44 ` [PATCH v3 01/20] powerpc/powermac: fix OF node refcount Bartosz Golaszewski
2026-07-07 13:24   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 02/20] driver core: platform: provide platform_device_set_of_node() Bartosz Golaszewski
2026-07-06 14:39   ` Manuel Ebner
2026-07-06 14:48     ` Manuel Ebner
2026-07-06 15:49     ` Andy Shevchenko
2026-07-06 17:26       ` Mark Brown
2026-07-07 13:24   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 03/20] driver core: platform: provide platform_device_set_fwnode() Bartosz Golaszewski
2026-07-07 13:24   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 04/20] driver core: platform: provide platform_device_set_of_node_from_dev() Bartosz Golaszewski
2026-07-07 13:24   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 05/20] driver core: update kerneldoc for platform_device_alloc() Bartosz Golaszewski
2026-07-07 13:24   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 06/20] of: platform: use platform_device_set_of_node() Bartosz Golaszewski
2026-07-07 13:24   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 07/20] powerpc/powermac: " Bartosz Golaszewski
2026-07-07 13:24   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 08/20] i2c: pxa-pci: " Bartosz Golaszewski
2026-07-07 13:24   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 09/20] iommu/fsl: " Bartosz Golaszewski
2026-07-06 14:51   ` Frank Li
2026-07-07 13:24   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 10/20] net: bcmgenet: " Bartosz Golaszewski
2026-07-07 13:24   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 11/20] pmdomain: imx: " Bartosz Golaszewski
2026-07-07 13:24   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 12/20] mfd: tps6586: " Bartosz Golaszewski
2026-07-07 13:24   ` sashiko-bot [this message]
2026-07-06 12:44 ` [PATCH v3 13/20] slimbus: qcom-ngd-ctrl: " Bartosz Golaszewski
2026-07-07 13:25   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 14/20] net: mv643xx: " Bartosz Golaszewski
2026-07-07 13:25   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 15/20] drm/xe/i2c: use platform_device_set_fwnode() Bartosz Golaszewski
2026-07-07 13:25   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 16/20] platform/surface: gpe: " Bartosz Golaszewski
2026-07-07 13:25   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 17/20] usb: chipidea: use platform_device_set_of_node_from_dev() Bartosz Golaszewski
2026-07-07 13:25   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 18/20] usb: musb: " Bartosz Golaszewski
2026-07-07 13:25   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 19/20] reset: rzg2l: " Bartosz Golaszewski
2026-07-07 13:25   ` sashiko-bot
2026-07-06 12:44 ` [PATCH v3 20/20] driver core: platform: count references to all kinds of firmware nodes Bartosz Golaszewski
2026-07-07 13:25   ` sashiko-bot

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=20260707132459.6CEAD1F000E9@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=dri-devel@lists.freedesktop.org \
    --cc=imx@lists.linux.dev \
    --cc=lee@kernel.org \
    --cc=mfd@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