From: Sergio Paracuellos <sergio.paracuellos@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: linusw@kernel.org, brgl@kernel.org, vicencb@gmail.com,
linux-kernel@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH 2/4] gpio: mt7621: more robust management of IRQ domain teardown
Date: Sat, 20 Jun 2026 14:01:34 +0200 [thread overview]
Message-ID: <20260620120136.2482872-3-sergio.paracuellos@gmail.com> (raw)
In-Reply-To: <20260620120136.2482872-1-sergio.paracuellos@gmail.com>
The driver uses devm_gpiochip_add_data() to register the GPIO chips which
means the devres subsystem will unregister them only after the function
'mt7621_gpio_remove()' returns. During the window between domain destruction
and devres unregistering the GPIO chips, the chips are still fully active.
If a consumer or userspace invokes gpiod_to_irq() during this window,
'mt7621_gpio_to_irq()' can dereference the already-freed irq domain pointer.
Thus, manage the IRQ domain teardown using 'devm_add_action_or_reset()' to
guarantee it is destroyed strictly after the GPIO chips are removed.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
drivers/gpio/gpio-mt7621.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/gpio/gpio-mt7621.c b/drivers/gpio/gpio-mt7621.c
index ceb99641baee..57384ef74703 100644
--- a/drivers/gpio/gpio-mt7621.c
+++ b/drivers/gpio/gpio-mt7621.c
@@ -272,9 +272,9 @@ static const struct irq_chip mt7621_irq_chip = {
};
static void
-mt7621_gpio_remove(struct platform_device *pdev)
+mt7621_gpio_remove(void *data)
{
- struct mtk *priv = platform_get_drvdata(pdev);
+ struct mtk *priv = data;
int offset, virq;
if (priv->gpio_irq > 0)
@@ -475,14 +475,14 @@ mediatek_gpio_probe(struct platform_device *pdev)
if (mtk->gpio_irq > 0) {
ret = mt7621_gpio_irq_setup(pdev, mtk);
if (ret)
- goto fail;
+ return ret;
}
- return 0;
+ ret = devm_add_action_or_reset(dev, mt7621_gpio_remove, mtk);
+ if (ret)
+ return ret;
-fail:
- mt7621_gpio_remove(pdev);
- return ret;
+ return 0;
}
static const struct of_device_id mediatek_gpio_match[] = {
@@ -493,7 +493,6 @@ MODULE_DEVICE_TABLE(of, mediatek_gpio_match);
static struct platform_driver mediatek_gpio_driver = {
.probe = mediatek_gpio_probe,
- .remove = mt7621_gpio_remove,
.driver = {
.name = "mt7621_gpio",
.of_match_table = mediatek_gpio_match,
--
2.43.0
next prev parent reply other threads:[~2026-06-20 12:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-20 12:01 [PATCH 0/4] gpio: mt7621: address Sashiko complains and other cleanups Sergio Paracuellos
2026-06-20 12:01 ` [PATCH 1/4] gpio: mt7621: avoid corruption of shared interrupt trigger state Sergio Paracuellos
2026-06-22 8:12 ` Bartosz Golaszewski
2026-06-20 12:01 ` Sergio Paracuellos [this message]
2026-06-22 8:12 ` [PATCH 2/4] gpio: mt7621: more robust management of IRQ domain teardown Bartosz Golaszewski
2026-06-26 6:02 ` Sergio Paracuellos
2026-06-20 12:01 ` [PATCH 3/4] gpio: mt7621: be sure IRQ domain is created before exposing GPIO chips Sergio Paracuellos
2026-06-20 12:01 ` [PATCH 4/4] gpio: mt7621: unify naming style in driver code Sergio Paracuellos
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=20260620120136.2482872-3-sergio.paracuellos@gmail.com \
--to=sergio.paracuellos@gmail.com \
--cc=brgl@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=vicencb@gmail.com \
/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