From: sashiko-bot@kernel.org
To: "Michael Walle" <mwalle@kernel.org>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [RFT PATCH 03/13] gpio: rtd1625: create the IRQ domain from the gpio-regmap callback
Date: Thu, 26 Nov 2026 15:54:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-235857@kernel.org> (raw)
In-Reply-To: <20261126153600.299724-4-mwalle@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] gpio: rtd1625: use-after-free of gpio_reg due to devres
lifetime mismatch
- [Low] gpio: rtd1625: missing Fixes trailer for probe NULL dereference
fix
--
commit 836b597a055624fd11d643d1081b9d412a5134af
Author: Michael Walle <mwalle@kernel.org>
> gpio: rtd1625: create the IRQ domain from the gpio-regmap callback
>
> Use the new .create_irq_domain() to actually create the domain. This
> way, there is no window where a NULL pointer could be dereferenced.
>
> Switch the irq host_data to the gpio_regmap pointer because it will
> already be needed in the irq domain callbacks. Otherwise the
> .create_irq_domain() callback would have to set the data->gpio_reg
> pointer which looks odd.
>
> Signed-off-by: Michael Walle <mwalle@kernel.org>
[Severity: Low]
Since this fixes a probe NULL pointer dereference window, should it carry:
Fixes: 6435d21cbd42 ("gpio: realtek: Add driver for Realtek DHC RTD1625 SoC")
> diff --git a/drivers/gpio/gpio-rtd1625.c b/drivers/gpio/gpio-rtd1625.c
> index cf4f61603dfbf..0713692804e21 100644
> --- a/drivers/gpio/gpio-rtd1625.c
> +++ b/drivers/gpio/gpio-rtd1625.c
[ ... ]
> @@ -505,9 +506,9 @@ static int rtd1625_gpio_setup_irq(struct platform_device *pdev, struct rtd1625_g
> static int rtd1625_gpio_irq_map(struct irq_domain *domain, unsigned int irq,
> irq_hw_number_t hwirq)
> {
> - struct rtd1625_gpio *data = domain->host_data;
> + struct gpio_regmap *gpio_reg = domain->host_data;
>
> - irq_set_chip_data(irq, data);
> + irq_set_chip_data(irq, gpio_reg);
>
> irq_set_chip_and_handler(irq, &rtd1625_iso_gpio_irq_chip, handle_bad_irq);
[ ... ]
> @@ -524,6 +525,31 @@ static const struct irq_domain_ops rtd1625_gpio_irq_domain_ops = {
> .xlate = irq_domain_xlate_twocell,
> };
>
> +static struct irq_domain *rtd1625_gpio_create_irq_domain(struct gpio_regmap *gpio_reg)
> +{
> + struct rtd1625_gpio *data = gpio_regmap_get_drvdata(gpio_reg);
> + struct device *dev = regmap_get_device(data->regmap);
> + struct platform_device *pdev = to_platform_device(dev);
> + struct irq_domain_info d_info = {};
> + int ret;
> +
> + d_info.fwnode = dev_fwnode(&pdev->dev);
> + d_info.size = data->info->num_gpios;
> + d_info.hwirq_max = data->info->num_gpios;
> + d_info.ops = &rtd1625_gpio_irq_domain_ops;
> + d_info.host_data = gpio_reg;
> +
> + data->domain = devm_irq_domain_instantiate(dev, &d_info);
> + if (IS_ERR(data->domain))
> + return data->domain;
> +
> + ret = rtd1625_gpio_setup_irq(pdev, data);
> + if (ret)
> + return ERR_PTR(ret);
> +
> + return data->domain;
> +}
[Severity: Medium]
Can storing gpio_reg in domain->host_data and irq_data->chip_data cause a
use-after-free of gpio_reg on probe failure or driver unbind?
rtd1625_gpio_create_irq_domain() runs inside gpio_regmap_register(), so
devm_irq_domain_instantiate() queues devm_irq_domain_remove() on dev's
devres list before devm_gpio_regmap_register() queues
devm_gpio_regmap_unregister():
drivers/gpio/gpio-regmap.c:devm_gpio_regmap_register() {
gpio = gpio_regmap_register(config);
if (IS_ERR(gpio))
return gpio;
ret = devm_add_action_or_reset(dev, devm_gpio_regmap_unregister, gpio);
...
}
Because gpio_reg is allocated with kzalloc_obj() rather than devm and
freed in gpio_regmap_unregister(), devres teardown on unbind runs
devm_gpio_regmap_unregister() first and calls kfree(gpio) while
data->domain is still published with host_data and mapped chip_data
pointing to freed gpio_reg until devm_irq_domain_remove() runs.
The same mismatch occurs if rtd1625_gpio_setup_irq() fails after
devm_irq_domain_instantiate() succeeds: gpio_regmap_register() immediately
calls kfree(gpio) in its error path while data->domain remains live until
rtd1625_gpio_probe() returns and devres cleans up.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126153600.299724-1-mwalle@kernel.org?part=3
next prev parent reply other threads:[~2026-11-26 15:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 15:35 [RFT PATCH 00/13] gpio: regmap: IRQ domain cleanups Michael Walle
2026-11-26 15:35 ` [RFT PATCH 01/13] gpio: regmap: remove gpiochip before tearing down irqchip Michael Walle
2026-11-26 15:35 ` [RFT PATCH 02/13] gpio: regmap: add a callback to create the IRQ domain Michael Walle
2026-11-26 15:47 ` sashiko-bot
2026-11-26 15:35 ` [RFT PATCH 03/13] gpio: rtd1625: create the IRQ domain from the gpio-regmap callback Michael Walle
2026-11-26 15:54 ` sashiko-bot [this message]
2026-11-26 15:35 ` [RFT PATCH 04/13] gpio: axiado-sgpio: " Michael Walle
2026-11-26 15:35 ` [RFT PATCH 05/13] gpio: regmap: add a helper to add a regmap-irq chip Michael Walle
2026-11-26 15:35 ` [RFT PATCH 06/13] gpio: max7360: create the regmap-irq chip from the gpio-regmap callback Michael Walle
2026-11-26 15:35 ` [RFT PATCH 07/13] gpio: sl28cpld: " Michael Walle
2026-11-26 15:35 ` [RFT PATCH 08/13] gpio: idio-16: " Michael Walle
2026-11-26 15:35 ` [RFT PATCH 09/13] gpio: pcie-idio-24: " Michael Walle
2026-11-26 15:48 ` sashiko-bot
2026-11-26 15:35 ` [RFT PATCH 10/13] gpio: ws16c48: " Michael Walle
2026-11-26 15:35 ` [RFT PATCH 11/13] gpio: 104-idi-48: " Michael Walle
2026-11-26 15:48 ` sashiko-bot
2026-11-26 15:35 ` [RFT PATCH 12/13] gpio: i8255: " Michael Walle
2026-11-26 15:35 ` [RFT PATCH 13/13] gpio: regmap: remove irq_domain and the regmap-irq configuration Michael Walle
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=sashiko-outbox-235857@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=mwalle@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