Skip to contentSkip to conversation

gpio: rockchip: Fix generic IRQ chip leak and modernize resource mapping

PATCH Applied Marco Scardovi 2 participants 6 messages Jun 7 – Jun 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover gpio: rockchip: Fix generic IRQ chip leak and modernize resource mapping

Hi all,

This series fixes a generic IRQ chip leak in the gpio-rockchip driver and performs two small cleanups to use standard platform device helper APIs.

Patch 1 fixes a leak caused by generic IRQ chips not being removed before IRQ domain teardown.

Patch 2 converts register mapping to use devm_platform_ioremap_resource().

Patch 3 converts interrupt retrieval to use platform_get_irq().

Marco Scardovi (3):
gpio: rockchip: fix generic IRQ chip leak on remove
gpio: rockchip: use devm_platform_ioremap_resource() to map registers
gpio: rockchip: use platform_get_irq() to retrieve interrupt

 drivers/gpio/gpio-rockchip.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/3 gpio: rockchip: fix generic IRQ chip leak on remove

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
---
 drivers/gpio/gpio-rockchip.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpio/gpio-rockchip.c +3 -1
index bc97d5d5d329..9478a58f1caa 100644
@@ -802,8 +802,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);
 }
 
Signature · 1 line
2.54.0
#2 lore raw

PATCH 2/3 gpio: rockchip: use devm_platform_ioremap_resource() to map registers

In reply to Marco Scardovi

Currently, the driver retrieves the memory resource with of_address_to_resource() and maps it with devm_ioremap_resource().

Since the bank device is a platform_device, simplify and modernize the code by using devm_platform_ioremap_resource(). This also removes the need for the local struct resource variable.

Assisted-by Antigravity:gemini-3.5-flash
---
 drivers/gpio/gpio-rockchip.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/gpio/gpio-rockchip.c +2 -7
index 9478a58f1caa..8647d006d103 100644
@@ -647,15 +647,10 @@ static void rockchip_clk_put(void *data)
 
 static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 {
-	struct resource res;
+	struct platform_device *pdev = to_platform_device(bank->dev);
 	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");
-		return -ENOENT;
-	}
-
-	bank->reg_base = devm_ioremap_resource(bank->dev, &res);
+	bank->reg_base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(bank->reg_base))
 		return PTR_ERR(bank->reg_base);
 
Signature · 1 line
2.54.0
#3 lore raw

PATCH 3/3 gpio: rockchip: use platform_get_irq() to retrieve interrupt

In reply to Marco Scardovi

The driver currently uses irq_of_parse_and_map() to parse and map the GPIO bank interrupt from the device tree node. Since the bank device is represented by a platform_device, use the standard platform_get_irq() API instead. This integrates cleanly with the platform device framework and ensures proper error propagation (such as -EPROBE_DEFER).

Assisted-by Antigravity:gemini-3.5-flash
---
 drivers/gpio/gpio-rockchip.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpio/gpio-rockchip.c +4 -3
index 8647d006d103..77b239a9a601 100644
@@ -654,9 +654,10 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 	if (IS_ERR(bank->reg_base))
 		return PTR_ERR(bank->reg_base);
 
-	bank->irq = irq_of_parse_and_map(bank->of_node, 0);
-	if (!bank->irq)
-		return -EINVAL;
+	ret = platform_get_irq(pdev, 0);
+	if (ret < 0)
+		return ret;
+	bank->irq = ret;
 
 	bank->clk = devm_clk_get_enabled(bank->dev, NULL);
 	if (IS_ERR(bank->clk))
Signature · 1 line
2.54.0
#4 lore raw

Re: (subset) [PATCH 0/3] gpio: rockchip: Fix generic IRQ chip leak and modernize resource mapping

In reply to Marco Scardovi
Quoted 9 lines · Marco Scardovi

This series fixes a generic IRQ chip leak in the gpio-rockchip driver and performs two small cleanups to use standard platform device helper APIs.

Patch 1 fixes a leak caused by generic IRQ chips not being removed before IRQ domain teardown.

Patch 2 converts register mapping to use devm_platform_ioremap_resource().

[...]

Applied, thanks!

[1/3] gpio: rockchip: fix generic IRQ chip leak on remove

      https://git.kernel.org/brgl/c/1c1e0fc88d6ef65bf15d517853251f75ab9d18c3

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>
#5 lore raw

Re: (subset) [PATCH 0/3] gpio: rockchip: Fix generic IRQ chip leak and modernize resource mapping

In reply to Marco Scardovi
Quoted 9 lines · Marco Scardovi

This series fixes a generic IRQ chip leak in the gpio-rockchip driver and performs two small cleanups to use standard platform device helper APIs.

Patch 1 fixes a leak caused by generic IRQ chips not being removed before IRQ domain teardown.

Patch 2 converts register mapping to use devm_platform_ioremap_resource().

[...]

Applied, thanks!

[2/3] gpio: rockchip: use devm_platform_ioremap_resource() to map registers

      https://git.kernel.org/brgl/c/c03c6a086d188dc5b52e7db2b2991ecead9bb669
[3/3] gpio: rockchip: use platform_get_irq() to retrieve interrupt
      https://git.kernel.org/brgl/c/c2e26f2408226de7464ba4cdcd86827e0a000db9

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>