Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>
Cc: robh@kernel.org, Frank.Li@kernel.org, devicetree@vger.kernel.org,
	imx@lists.linux.dev, conor+dt@kernel.org
Subject: Re: [PATCH 18/23] drm/xe/i2c: use platform_device_set_fwnode()
Date: Sat, 30 May 2026 00:45:47 +0000	[thread overview]
Message-ID: <20260530004547.4BCDB1F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260521-pdev-fwnode-ref-v1-18-88c324a1b8d2@oss.qualcomm.com>

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

Pre-existing issues:
- [High] Missing `cancel_work_sync(&i2c->work)` in teardown path leads to Use-After-Free.
- [High] Missing reference count on I2C adapter across asynchronous handoff leads to Use-After-Free.
- [High] Unhandled I2C adapter removal leaves dangling client pointers which are double-freed during module unload.
--

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

drm/xe/i2c: use platform_device_set_fwnode()

Ahead of reworking the reference counting logic for platform devices,
encapsulate the assignment of the firmware node for dynamically allocated
platform devices with the provided helper.

> diff --git a/drivers/gpu/drm/xe/xe_i2c.c b/drivers/gpu/drm/xe/xe_i2c.c
> index 706783863d07d..af4ebd93ad8e6 100644
> --- a/drivers/gpu/drm/xe/xe_i2c.c
> +++ b/drivers/gpu/drm/xe/xe_i2c.c
> @@ -123,7 +123,7 @@ static int xe_i2c_register_adapter(struct xe_i2c *i2c)
>  	}
>  
>  	pdev->dev.parent = i2c->drm_dev;
> -	pdev->dev.fwnode = fwnode;
> +	platform_device_set_fwnode(pdev, fwnode);
>  	i2c->adapter_node = fwnode;
>  	i2c->pdev = pdev;

[Severity: High]
This isn't a bug introduced by this patch, but does the teardown path miss a
cancel_work_sync(&i2c->work)?

The xe_i2c_probe() function initializes i2c->work, which is scheduled
asynchronously in xe_i2c_notifier() when the I2C adapter is added. However,
the driver's teardown function xe_i2c_remove() fails to call
cancel_work_sync(&i2c->work) before returning.

Because i2c is allocated via devm_kzalloc(), the memory is automatically
freed by the devres framework shortly after xe_i2c_remove() completes. If the
background work is still pending or actively executing during or after this
teardown, xe_i2c_client_work() will dereference the freed i2c object to
access i2c->adapter and i2c->ep.addr[1], which could cause a use-after-free.

[Severity: High]
This is a pre-existing issue, but does the I2C adapter need its reference
count incremented across the asynchronous handoff?

In xe_i2c_notifier(), when a new I2C adapter is added, i2c->adapter is
assigned the raw adapter pointer and i2c->work is scheduled. No reference is
taken to ensure the adapter stays alive (e.g., via i2c_get_adapter()).

The scheduled background task xe_i2c_client_work() later accesses this
pointer to instantiate a client device via i2c_new_client_device(). If the
underlying I2C adapter is unbound or removed (e.g., via a sysfs unbind of
the i2c_designware driver) between the notifier firing and the work executing,
the adapter memory will be freed. The workqueue will then dereference a
dangling pointer when trying to register the client.

[Severity: High]
This isn't a bug introduced by this patch, but can unhandled I2C adapter
removal leave dangling client pointers?

When an I2C adapter is removed (e.g., by unbinding the platform device), the
I2C core (i2c_del_adapter()) automatically unregisters and frees all
associated client devices.

The xe_i2c_notifier() does not handle BUS_NOTIFY_DEL_DEVICE to track adapter
removal, so it fails to clear the i2c->client[i] array, leaving it populated
with dangling pointers. Later, when the xe driver is unloaded and
xe_i2c_remove() runs, it unconditionally calls
i2c_unregister_device(i2c->client[i]) on the already freed client pointers,
which could lead to a double free or use-after-free.

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

  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
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 [this message]
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=20260530004547.4BCDB1F00899@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