Skip to content

Commit ff7a179

Browse files
mwalleBartosz Golaszewski
authored andcommitted
gpiolib: Fix irq_domain resource tracking for gpiochip_irqchip_add_domain()
Up until commit 6a45b0e ("gpiolib: Introduce gpiochip_irqchip_add_domain()") all irq_domains were allocated by gpiolib itself and thus gpiolib also takes care of freeing it. With gpiochip_irqchip_add_domain() a user of gpiolib can associate an irq_domain with the gpio_chip. This irq_domain is not managed by gpiolib and therefore must not be freed by gpiolib. Fixes: 6a45b0e ("gpiolib: Introduce gpiochip_irqchip_add_domain()") Reported-by: Jiawen Wu <jiawenwu@trustnetic.com> Signed-off-by: Michael Walle <mwalle@kernel.org> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Andy Shevchenko <andy@kernel.org> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent c1bcb97 commit ff7a179

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

drivers/gpio/gpiolib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gc)
17451745
}
17461746

17471747
/* Remove all IRQ mappings and delete the domain */
1748-
if (gc->irq.domain) {
1748+
if (!gc->irq.domain_is_allocated_externally && gc->irq.domain) {
17491749
unsigned int irq;
17501750

17511751
for (offset = 0; offset < gc->ngpio; offset++) {
@@ -1791,6 +1791,7 @@ int gpiochip_irqchip_add_domain(struct gpio_chip *gc,
17911791

17921792
gc->to_irq = gpiochip_to_irq;
17931793
gc->irq.domain = domain;
1794+
gc->irq.domain_is_allocated_externally = true;
17941795

17951796
/*
17961797
* Using barrier() here to prevent compiler from reordering

include/linux/gpio/driver.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ struct gpio_irq_chip {
251251
*/
252252
bool initialized;
253253

254+
/**
255+
* @domain_is_allocated_externally:
256+
*
257+
* True it the irq_domain was allocated outside of gpiolib, in which
258+
* case gpiolib won't free the irq_domain itself.
259+
*/
260+
bool domain_is_allocated_externally;
261+
254262
/**
255263
* @init_hw: optional routine to initialize hardware before
256264
* an IRQ chip will be added. This is quite useful when

0 commit comments

Comments
 (0)