From: "Marco Scardovi (scardracs)" <scardracs@disroot.org>
To: linusw@kernel.org, brgl@kernel.org, heiko@sntech.de
Cc: linux-gpio@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
"Marco Scardovi (scardracs)" <scardracs@disroot.org>
Subject: [PATCH 2/2] gpio: rockchip: fix teardown bugs and resource leaks
Date: Mon, 25 May 2026 18:39:39 +0200 [thread overview]
Message-ID: <20260525164230.43307-3-scardracs@disroot.org> (raw)
In-Reply-To: <20260525164230.43307-1-scardracs@disroot.org>
This commit addresses several teardown issues and resource leaks in the
driver's remove path and error handling:
1. Debounce clock reference leak: The debounce clock (bank->db_clk) was
obtained using of_clk_get() which increments the clock's reference
count, but clk_put() was never called. A devm action is now registered
to cleanly release it on unbind. Note that of_clk_get(..., 1) remains
necessary over devm_clk_get() because the DT binding does not define
clock-names, precluding name-based lookup.
2. Unregistered chained IRQ handler: The chained IRQ handler was not
disconnected in remove(). If a stray interrupt fired after the driver
was removed, the kernel would attempt to execute a stale handler,
leading to a panic. This is fixed by clearing the handler in remove().
3. IRQ domain leak: The linear IRQ domain and its generic chips were
allocated manually during probe but never removed. The IRQ domain is
now removed during driver teardown to free the associated generic chips
and mappings.
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Marco Scardovi <scardracs@disroot.org>
---
drivers/gpio/gpio-rockchip.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index 33580093a4e7..c804f970d823 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -638,10 +638,17 @@ static int rockchip_gpiolib_register(struct rockchip_pin_bank *bank)
return ret;
}
+static void rockchip_clk_put(void *data)
+{
+ struct clk *clk = data;
+
+ clk_put(clk);
+}
+
static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
{
struct resource res;
- int id = 0;
+ int id = 0, ret;
if (of_address_to_resource(bank->of_node, 0, &res)) {
dev_err(bank->dev, "cannot find IO resource for bank\n");
@@ -673,6 +680,13 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
dev_err(bank->dev, "cannot find debounce clk\n");
return -EINVAL;
}
+
+ ret = devm_add_action_or_reset(bank->dev, rockchip_clk_put,
+ bank->db_clk);
+ if (ret) {
+ dev_err(bank->dev, "failed to register debounce clk action\n");
+ return ret;
+ }
break;
case GPIO_TYPE_V1:
bank->gpio_regs = &gpio_regs_v1;
@@ -789,6 +803,9 @@ static void rockchip_gpio_remove(struct platform_device *pdev)
{
struct rockchip_pin_bank *bank = platform_get_drvdata(pdev);
+ irq_set_chained_handler_and_data(bank->irq, NULL, NULL);
+ if (bank->domain)
+ irq_domain_remove(bank->domain);
gpiochip_remove(&bank->gpio_chip);
}
--
2.54.0
next prev parent reply other threads:[~2026-05-25 16:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 16:39 [PATCH 0/2] gpio: rockchip: fix resource leaks and teardown bugs Marco Scardovi (scardracs)
2026-05-25 16:39 ` [PATCH 1/2] gpio: rockchip: convert bank->clk to devm_clk_get_enabled() Marco Scardovi (scardracs)
2026-05-25 16:39 ` Marco Scardovi (scardracs) [this message]
2026-05-26 10:53 ` [PATCH 2/2] gpio: rockchip: fix teardown bugs and resource leaks Bartosz Golaszewski
2026-05-26 17:02 ` [PATCH v2 0/2] gpio: rockchip: fix resource leaks and teardown bugs Marco Scardovi
2026-05-26 17:02 ` [PATCH v2 1/2] gpio: rockchip: convert bank->clk to devm_clk_get_enabled() Marco Scardovi
2026-05-26 17:02 ` [PATCH v2 2/2] gpio: rockchip: teardown bugs and resource leaks Marco Scardovi
2026-05-27 8:11 ` Bartosz Golaszewski
2026-05-27 8:10 ` [PATCH v2 0/2] gpio: rockchip: fix resource leaks and teardown bugs Bartosz Golaszewski
2026-05-27 8:12 ` Bartosz Golaszewski
2026-05-27 8:17 ` Bartosz Golaszewski
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=20260525164230.43307-3-scardracs@disroot.org \
--to=scardracs@disroot.org \
--cc=brgl@kernel.org \
--cc=heiko@sntech.de \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
/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