gpio: rockchip: Fix generic IRQ chip leak and modernize resource mapping
Subsystems (2)
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
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().
--- drivers/gpio/gpio-rockchip.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpio/gpio-rockchip.c +3 -1
@@ -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
PATCH 2/3 gpio: rockchip: use devm_platform_ioremap_resource() to map registers
In reply to Marco ScardoviCurrently, 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.
--- drivers/gpio/gpio-rockchip.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/gpio/gpio-rockchip.c +2 -7
@@ -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
PATCH 3/3 gpio: rockchip: use platform_get_irq() to retrieve interrupt
In reply to Marco ScardoviThe 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).
--- drivers/gpio/gpio-rockchip.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpio/gpio-rockchip.c +4 -3
@@ -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
Bartosz Golaszewski
AppliedRe: (subset) [PATCH 0/3] gpio: rockchip: Fix generic IRQ chip leak and modernize resource mapping
In reply to Marco ScardoviQuoted 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]>
Bartosz Golaszewski
AppliedRe: (subset) [PATCH 0/3] gpio: rockchip: Fix generic IRQ chip leak and modernize resource mapping
In reply to Marco ScardoviQuoted 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]>