* [PATCH v2 1/2] gpio: rockchip: convert bank->clk to devm_clk_get_enabled()
2026-05-26 17:02 ` [PATCH v2 0/2] gpio: rockchip: fix resource leaks and teardown bugs Marco Scardovi
@ 2026-05-26 17:02 ` Marco Scardovi
2026-05-26 17:02 ` [PATCH v2 2/2] gpio: rockchip: teardown bugs and resource leaks Marco Scardovi
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Marco Scardovi @ 2026-05-26 17:02 UTC (permalink / raw)
To: brgl
Cc: heiko, linusw, linux-arm-kernel, linux-gpio, linux-kernel,
linux-rockchip, scardracs
The bank->clk was previously obtained via of_clk_get() and manually
prepared/enabled. However, it was missing a corresponding clk_put() in
both the error paths and the remove function, leading to a reference leak.
Convert the allocation to devm_clk_get_enabled(), which also properly
propagates failures from clk_prepare_enable() that were previously ignored.
The GPIO bank device uses the same OF node as the previous of_clk_get()
call, so devm_clk_get_enabled(dev, NULL) correctly resolves the same
clock provider entry.
Fix the reference leak and simplify the code by removing the manual
clk_disable_unprepare() calls in the probe error paths and in the
remove function.
Fixes: 936ee2675eee ("gpio/rockchip: add driver for rockchip gpio")
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Marco Scardovi <scardracs@disroot.org>
---
drivers/gpio/gpio-rockchip.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index 44d7ebd12724..33580093a4e7 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -656,11 +656,10 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
if (!bank->irq)
return -EINVAL;
- bank->clk = of_clk_get(bank->of_node, 0);
+ bank->clk = devm_clk_get_enabled(bank->dev, NULL);
if (IS_ERR(bank->clk))
return PTR_ERR(bank->clk);
- clk_prepare_enable(bank->clk);
id = readl(bank->reg_base + gpio_regs_v2.version_id);
switch (id) {
@@ -672,7 +671,6 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
bank->db_clk = of_clk_get(bank->of_node, 1);
if (IS_ERR(bank->db_clk)) {
dev_err(bank->dev, "cannot find debounce clk\n");
- clk_disable_unprepare(bank->clk);
return -EINVAL;
}
break;
@@ -751,7 +749,6 @@ static int rockchip_gpio_probe(struct platform_device *pdev)
ret = rockchip_gpiolib_register(bank);
if (ret) {
- clk_disable_unprepare(bank->clk);
mutex_unlock(&bank->deferred_lock);
return ret;
}
@@ -792,7 +789,6 @@ static void rockchip_gpio_remove(struct platform_device *pdev)
{
struct rockchip_pin_bank *bank = platform_get_drvdata(pdev);
- clk_disable_unprepare(bank->clk);
gpiochip_remove(&bank->gpio_chip);
}
--
2.54.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v2 2/2] gpio: rockchip: teardown bugs and resource leaks
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 ` 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:17 ` Bartosz Golaszewski
3 siblings, 1 reply; 11+ messages in thread
From: Marco Scardovi @ 2026-05-26 17:02 UTC (permalink / raw)
To: brgl
Cc: heiko, linusw, linux-arm-kernel, linux-gpio, linux-kernel,
linux-rockchip, scardracs
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.
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>
---
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
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v2 2/2] gpio: rockchip: teardown bugs and resource leaks
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
0 siblings, 0 replies; 11+ messages in thread
From: Bartosz Golaszewski @ 2026-05-27 8:11 UTC (permalink / raw)
To: Marco Scardovi
Cc: brgl, heiko, linusw, linux-arm-kernel, linux-gpio, linux-kernel,
linux-rockchip
On Tue, 26 May 2026 19:02:46 +0200, Marco Scardovi <scardracs@disroot.org> said:
> 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.
>
> 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>
> ---
> 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;
Use return dev_err_probe() for brevity.
> + }
> 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);
Maybe if you're already touching the driver, use devres for gpiochip_remove()
too and schedule an action for removing the irq handler?
> }
>
> --
> 2.54.0
>
>
Bart
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 0/2] gpio: rockchip: fix resource leaks and teardown bugs
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:10 ` Bartosz Golaszewski
2026-05-27 8:12 ` Bartosz Golaszewski
2026-05-27 8:17 ` Bartosz Golaszewski
3 siblings, 1 reply; 11+ messages in thread
From: Bartosz Golaszewski @ 2026-05-27 8:10 UTC (permalink / raw)
To: Marco Scardovi
Cc: heiko, linusw, linux-arm-kernel, linux-gpio, linux-kernel,
linux-rockchip, brgl
On Tue, 26 May 2026 19:02:44 +0200, Marco Scardovi <scardracs@disroot.org> said:
> Hi Bartosz,
> thank you for the review on the first version of this series.
>
> TL;DR: There's no clock-names property in the DTBs for the GPIO banks,
> and they don't expose a separate debounce clock in hardware.
>
> Regarding your question: existing DTBs currently do not provide clock-names
> for these GPIO nodes and instead rely on positional clock ordering.
>
> While we could extend the binding to optionally support clock-names going
> forward, the driver still needs to remain compatible with existing DTBs, so
> it cannot rely on name-based lookup here.
>
> For this reason, keeping the index-based of_clk_get(..., 1) lookup together
> with devm_add_action_or_reset() for cleanup seemed like the safest option.
>
> A good example can be gpio1 in rk3399-base.dtsi, where the clocks property
> is defined as:
>
> clocks = <&pmucru PCLK_GPIO1_PMU>;
>
> If we switched to name-based lookup via devm_clk_get(dev, "db"), it would
> fail for existing DTBs because they do not define the corresponding
> clock-names property.
>
> Additionally, PMU banks such as gpio1 do not expose a separate debounce
> clock in hardware, so there would not be a matching entry anyway.
>
> Therefore, using of_clk_get(..., 1) is currently the only approach that
> preserves compatibility with existing DTBs while avoiding regressions.
>
I see. Can you please reverse the order of the patches? The fix should go into
v7.1 and stable branches, patch 1/2 is a new feature so it'll go into v7.2.
Bart
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 0/2] gpio: rockchip: fix resource leaks and teardown bugs
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
0 siblings, 0 replies; 11+ messages in thread
From: Bartosz Golaszewski @ 2026-05-27 8:12 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: heiko, linusw, linux-arm-kernel, linux-gpio, linux-kernel,
linux-rockchip, Marco Scardovi
On Wed, 27 May 2026 10:10:23 +0200, Bartosz Golaszewski <brgl@kernel.org> said:
> On Tue, 26 May 2026 19:02:44 +0200, Marco Scardovi <scardracs@disroot.org> said:
>> Hi Bartosz,
>> thank you for the review on the first version of this series.
>>
>> TL;DR: There's no clock-names property in the DTBs for the GPIO banks,
>> and they don't expose a separate debounce clock in hardware.
>>
>> Regarding your question: existing DTBs currently do not provide clock-names
>> for these GPIO nodes and instead rely on positional clock ordering.
>>
>> While we could extend the binding to optionally support clock-names going
>> forward, the driver still needs to remain compatible with existing DTBs, so
>> it cannot rely on name-based lookup here.
>>
>> For this reason, keeping the index-based of_clk_get(..., 1) lookup together
>> with devm_add_action_or_reset() for cleanup seemed like the safest option.
>>
>> A good example can be gpio1 in rk3399-base.dtsi, where the clocks property
>> is defined as:
>>
>> clocks = <&pmucru PCLK_GPIO1_PMU>;
>>
>> If we switched to name-based lookup via devm_clk_get(dev, "db"), it would
>> fail for existing DTBs because they do not define the corresponding
>> clock-names property.
>>
>> Additionally, PMU banks such as gpio1 do not expose a separate debounce
>> clock in hardware, so there would not be a matching entry anyway.
>>
>> Therefore, using of_clk_get(..., 1) is currently the only approach that
>> preserves compatibility with existing DTBs while avoiding regressions.
>>
>
> I see. Can you please reverse the order of the patches? The fix should go into
> v7.1 and stable branches, patch 1/2 is a new feature so it'll go into v7.2.
>
> Bart
>
Ah, nevermind my comment, I see patch 1/2 is a fix as well. I'll queue these
and fix the dev_err_probe() thing in tree.
Bart
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 0/2] gpio: rockchip: fix resource leaks and teardown bugs
2026-05-26 17:02 ` [PATCH v2 0/2] gpio: rockchip: fix resource leaks and teardown bugs Marco Scardovi
` (2 preceding siblings ...)
2026-05-27 8:10 ` [PATCH v2 0/2] gpio: rockchip: fix resource leaks and teardown bugs Bartosz Golaszewski
@ 2026-05-27 8:17 ` Bartosz Golaszewski
3 siblings, 0 replies; 11+ messages in thread
From: Bartosz Golaszewski @ 2026-05-27 8:17 UTC (permalink / raw)
To: brgl, Marco Scardovi
Cc: Bartosz Golaszewski, heiko, linusw, linux-arm-kernel, linux-gpio,
linux-kernel, linux-rockchip
On Tue, 26 May 2026 19:02:44 +0200, Marco Scardovi wrote:
> thank you for the review on the first version of this series.
>
> TL;DR: There's no clock-names property in the DTBs for the GPIO banks,
> and they don't expose a separate debounce clock in hardware.
>
> Regarding your question: existing DTBs currently do not provide clock-names
> for these GPIO nodes and instead rely on positional clock ordering.
>
> [...]
Applied, thanks!
[1/2] gpio: rockchip: convert bank->clk to devm_clk_get_enabled()
https://git.kernel.org/brgl/c/d4573b270d934c35eb77fc348866384fcb4e8eeb
[2/2] gpio: rockchip: teardown bugs and resource leaks
https://git.kernel.org/brgl/c/9c95f4b920e15c183ebbb15b0a011ba32fcb6d59
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 11+ messages in thread