All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eduard Bostina" <egbostina@gmail.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org,
	lee@kernel.org, mfd@lists.linux.dev
Subject: Re: [PATCH v4] dt-bindings: mfd: Convert TI TWL6040 to DT schema
Date: Sat, 05 Sep 2026 22:06:55 +0000	[thread overview]
Message-ID: <20260905220656.2F8AC1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260905215234.454266-1-egbostina@gmail.com>

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

Pre-existing issues:
- [High] IRQ domain destroyed before devm-managed threaded IRQs are freed and before child devices are removed, causing Use-After-Free.
- [High] The child driver twl6040-vibra allocates regulator devres actions on the parent device using a pointer allocated on the child, leading to a Use-After-Free.
--

commit 0404bd7a83f494396c387e5f75dbf3991d0ac035
Author: Eduard Bostina <egbostina@gmail.com>

dt-bindings: mfd: Convert TI TWL6040 to DT schema

Convert the Texas Instruments TWL6040 audio codecs family bindings to DT
schema. It updates naming and optional parameters for modern platforms while
maintaining hardware requirements for the vibra child node.

Link to v3: https://lore.kernel.org/all/20260817100207.2970303-1-egbostina@gmail.com/
Link to v2: https://lore.kernel.org/all/20260816092847.2522994-1-egbostina@gmail.com/
Link to v1: https://lore.kernel.org/all/20260815083451.2147129-1-egbostina@gmail.com/

> diff --git a/Documentation/devicetree/bindings/mfd/ti,twl6040.yaml b/Documentation/devicetree/bindings/mfd/ti,twl6040.yaml
> new file mode 100644
> index 0000000000000..5efcd79b527c3
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/ti,twl6040.yaml
[ ... ]

While reviewing this dt-bindings conversion, I noticed a few pre-existing
issues in the related C drivers for this hardware family.

In drivers/mfd/twl6040.c:

> static void twl6040_remove(struct i2c_client *client)
> {
> 	struct twl6040 *twl6040 = i2c_get_clientdata(client);
> 
> 	if (twl6040->power_count)
> 		twl6040_power(twl6040, 0);
> 
> 	regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);
> 
> 	mfd_remove_devices(&client->dev);

[Severity: High]
This isn't a bug introduced by this patch, but does this sequence lead to a
use-after-free during teardown?

It looks like twl6040_remove() destroys the IRQ domain via
regmap_del_irq_chip() before the child devices are removed via
mfd_remove_devices(). When the children unbind and attempt to free their
IRQs, won't they access the already-destroyed IRQ domain and descriptors?

A similar sequence seems to occur in the twl6040_probe() error path:

drivers/mfd/twl6040.c:twl6040_probe() {
[ ... ]
> 	ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children,
> 			      NULL, 0, NULL);
> 	if (ret)
> 		goto readyirq_err;
> 
> 	return 0;
> 
> readyirq_err:
> 	regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);

[Severity: High]
This is a pre-existing issue, but does this error path similarly destroy the
IRQ domain before the devm-managed threaded IRQs are automatically freed by
devres? This appears to cause a use-after-free when probe fails.


In drivers/input/misc/twl6040-vibra.c:

> 	info->supplies[0].supply = "vddvibl";
> 	info->supplies[1].supply = "vddvibr";
> 	/*
> 	 * When booted with Device tree the regulators are attached to the
> 	 * parent device (twl6040 MFD core)
> 	 */
> 	error = devm_regulator_bulk_get(twl6040_core_dev,
> 					ARRAY_SIZE(info->supplies),
> 					info->supplies);

[Severity: High]
This is a pre-existing issue, but does this devres attachment cause a
use-after-free if the parent device unbinds after the child device?

The info structure is allocated via devm_kzalloc() on the child device. By
passing info->supplies to devm_regulator_bulk_get() for the parent device
(twl6040_core_dev), the parent's devres context stores this child-managed
pointer. If the child unbinds, info is freed, and when the parent later
unbinds, won't its devres call regulator_bulk_free() on the now-dangling
info->supplies pointer?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260905215234.454266-1-egbostina@gmail.com?part=1

      reply	other threads:[~2026-09-05 22:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-05 21:52 [PATCH v4] dt-bindings: mfd: Convert TI TWL6040 to DT schema Eduard Bostina
2026-09-05 22:06 ` sashiko-bot [this message]

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=20260905220656.2F8AC1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=egbostina@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.