* [PATCH 6.12.y 0/3] Rockchip GPIO driver resource leaks
@ 2026-07-06 16:17 Heiko Stuebner
2026-07-06 16:17 ` [PATCH 6.12.y 1/3] gpio: rockchip: change the GPIO version judgment logic Heiko Stuebner
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Heiko Stuebner @ 2026-07-06 16:17 UTC (permalink / raw)
To: stable; +Cc: heiko, quentin.schulz, Heiko Stuebner
From: Heiko Stuebner <heiko.stuebner@cherry.de>
Patches 2+3 resolve resource leaks, while patch 1 is structural
change without functionality change, that is needed for 2+3 to
apply cleanly.
Marco Scardovi (2):
gpio: rockchip: teardown bugs and resource leaks
gpio: rockchip: fix generic IRQ chip leak on remove
Ye Zhang (1):
gpio: rockchip: change the GPIO version judgment logic
drivers/gpio/gpio-rockchip.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 6.12.y 1/3] gpio: rockchip: change the GPIO version judgment logic
2026-07-06 16:17 [PATCH 6.12.y 0/3] Rockchip GPIO driver resource leaks Heiko Stuebner
@ 2026-07-06 16:17 ` Heiko Stuebner
2026-07-06 16:17 ` [PATCH 6.12.y 2/3] gpio: rockchip: teardown bugs and resource leaks Heiko Stuebner
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Heiko Stuebner @ 2026-07-06 16:17 UTC (permalink / raw)
To: stable
Cc: heiko, quentin.schulz, Ye Zhang, Sebastian Reichel,
Andy Shevchenko, Bartosz Golaszewski, Heiko Stuebner
From: Ye Zhang <ye.zhang@rock-chips.com>
[ Upstream commit 41209307cad7f14c387c68375a93b50e54261a53 ]
Have a list of valid IDs and default to -ENODEV.
Signed-off-by: Ye Zhang <ye.zhang@rock-chips.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20241112015408.3139996-3-ye.zhang@rock-chips.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
drivers/gpio/gpio-rockchip.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index 052713bd8d07..16c1ec3a5d0e 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -653,8 +653,9 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
id = readl(bank->reg_base + gpio_regs_v2.version_id);
- /* If not gpio v2, that is default to v1. */
- if (id == GPIO_TYPE_V2 || id == GPIO_TYPE_V2_1) {
+ switch (id) {
+ case GPIO_TYPE_V2:
+ case GPIO_TYPE_V2_1:
bank->gpio_regs = &gpio_regs_v2;
bank->gpio_type = GPIO_TYPE_V2;
bank->db_clk = of_clk_get(bank->of_node, 1);
@@ -662,9 +663,14 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
dev_err(bank->dev, "cannot find debounce clk\n");
return -EINVAL;
}
- } else {
+ break;
+ case GPIO_TYPE_V1:
bank->gpio_regs = &gpio_regs_v1;
bank->gpio_type = GPIO_TYPE_V1;
+ break;
+ default:
+ dev_err(bank->dev, "unsupported version ID: 0x%08x\n", id);
+ return -ENODEV;
}
return 0;
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 6.12.y 2/3] gpio: rockchip: teardown bugs and resource leaks
2026-07-06 16:17 [PATCH 6.12.y 0/3] Rockchip GPIO driver resource leaks Heiko Stuebner
2026-07-06 16:17 ` [PATCH 6.12.y 1/3] gpio: rockchip: change the GPIO version judgment logic Heiko Stuebner
@ 2026-07-06 16:17 ` Heiko Stuebner
2026-07-06 16:17 ` [PATCH 6.12.y 3/3] gpio: rockchip: fix generic IRQ chip leak on remove Heiko Stuebner
2026-07-07 8:50 ` [PATCH 6.12.y 0/3] Rockchip GPIO driver resource leaks Sasha Levin
3 siblings, 0 replies; 5+ messages in thread
From: Heiko Stuebner @ 2026-07-06 16:17 UTC (permalink / raw)
To: stable
Cc: heiko, quentin.schulz, Marco Scardovi, Bartosz Golaszewski,
Heiko Stuebner
From: Marco Scardovi <scardracs@disroot.org>
[ Upstream commit 9500077678230e36d22bf16d2b9539c13e59a801 ]
Address 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) is
obtained using of_clk_get() which increments the clock's reference
count, but clk_put() is never called. Register a devm action 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.
OA
2. Unregistered chained IRQ handler: The chained IRQ handler is not
disconnected in remove(). If a stray interrupt fires after the driver
is removed, the kernel attempts to execute a stale handler, leading
to a panic. Fix this by clearing the handler in remove().
3. IRQ domain leak: The linear IRQ domain and its generic chips are
allocated manually during probe but never removed. Remove the IRQ
domain during driver teardown to free the associated generic chips
and mappings.
Fixes: 936ee2675eee ("gpio/rockchip: add driver for rockchip gpio")
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Marco Scardovi <scardracs@disroot.org>
Link: https://patch.msgid.link/20260526171050.12785-3-scardracs@disroot.org
[Bartosz: don't emit an error message on devres allocation failure]
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
drivers/gpio/gpio-rockchip.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index 16c1ec3a5d0e..0a93c74933f0 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -629,10 +629,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");
@@ -663,6 +670,11 @@ 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)
+ return ret;
break;
case GPIO_TYPE_V1:
bank->gpio_regs = &gpio_regs_v1;
@@ -779,6 +791,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.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 6.12.y 3/3] gpio: rockchip: fix generic IRQ chip leak on remove
2026-07-06 16:17 [PATCH 6.12.y 0/3] Rockchip GPIO driver resource leaks Heiko Stuebner
2026-07-06 16:17 ` [PATCH 6.12.y 1/3] gpio: rockchip: change the GPIO version judgment logic Heiko Stuebner
2026-07-06 16:17 ` [PATCH 6.12.y 2/3] gpio: rockchip: teardown bugs and resource leaks Heiko Stuebner
@ 2026-07-06 16:17 ` Heiko Stuebner
2026-07-07 8:50 ` [PATCH 6.12.y 0/3] Rockchip GPIO driver resource leaks Sasha Levin
3 siblings, 0 replies; 5+ messages in thread
From: Heiko Stuebner @ 2026-07-06 16:17 UTC (permalink / raw)
To: stable
Cc: heiko, quentin.schulz, Marco Scardovi, Bartosz Golaszewski,
Heiko Stuebner
From: Marco Scardovi <scardracs@disroot.org>
[ Upstream commit 1c1e0fc88d6ef65bf15d517853251f75ab9d18c3 ]
The driver allocates domain generic chips using
irq_alloc_domain_generic_chips() during probe. However, on driver
remove/teardown, the generic chips are not automatically freed when the
IRQ domain is removed because the domain flags do not include
IRQ_DOMAIN_FLAG_DESTROY_GC.
This causes both the domain generic chips structure and the associated
generic chips to be leaked. Additionally, the generic chips remain on
the global gc_list and may later be visited by generic IRQ chip suspend,
resume, or shutdown callbacks after the GPIO bank has been removed,
potentially resulting in a use-after-free and kernel crash.
Fix the resource leak by explicitly calling
irq_domain_remove_generic_chips() before removing the IRQ domain in
rockchip_gpio_remove().
Fixes: 936ee2675eee ("gpio/rockchip: add driver for rockchip gpio")
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Marco Scardovi <scardracs@disroot.org>
Link: https://patch.msgid.link/20260607230504.35392-2-scardracs@disroot.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
drivers/gpio/gpio-rockchip.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index 0a93c74933f0..9c419625c753 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -792,8 +792,10 @@ 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)
+ if (bank->domain) {
+ irq_domain_remove_generic_chips(bank->domain);
irq_domain_remove(bank->domain);
+ }
gpiochip_remove(&bank->gpio_chip);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 6.12.y 0/3] Rockchip GPIO driver resource leaks
2026-07-06 16:17 [PATCH 6.12.y 0/3] Rockchip GPIO driver resource leaks Heiko Stuebner
` (2 preceding siblings ...)
2026-07-06 16:17 ` [PATCH 6.12.y 3/3] gpio: rockchip: fix generic IRQ chip leak on remove Heiko Stuebner
@ 2026-07-07 8:50 ` Sasha Levin
3 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2026-07-07 8:50 UTC (permalink / raw)
To: stable; +Cc: Sasha Levin, heiko, quentin.schulz, Heiko Stuebner
> Patches 2+3 resolve resource leaks, while patch 1 is structural
> change without functionality change, that is needed for 2+3 to
> apply cleanly.
Queued the series for 6.12, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-07 8:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-06 16:17 [PATCH 6.12.y 0/3] Rockchip GPIO driver resource leaks Heiko Stuebner
2026-07-06 16:17 ` [PATCH 6.12.y 1/3] gpio: rockchip: change the GPIO version judgment logic Heiko Stuebner
2026-07-06 16:17 ` [PATCH 6.12.y 2/3] gpio: rockchip: teardown bugs and resource leaks Heiko Stuebner
2026-07-06 16:17 ` [PATCH 6.12.y 3/3] gpio: rockchip: fix generic IRQ chip leak on remove Heiko Stuebner
2026-07-07 8:50 ` [PATCH 6.12.y 0/3] Rockchip GPIO driver resource leaks Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox