Up until commit 6a45b0e2589f ("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.
Unified · Split
| @@ -1745,7 +1745,7 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gc) · 1744 unmodified lines | |||
| 1745 | } | 1745 | } |
| 1746 | 1746 | ||
| 1747 | /* Remove all IRQ mappings and delete the domain */ | 1747 | /* Remove all IRQ mappings and delete the domain */ |
| 1748 | if (gc->irq.domain) { | 1748 | if (!gc->irq.domain_is_allocated_externally && gc->irq.domain) { |
| 1749 | unsigned int irq; | 1749 | unsigned int irq; |
| 1750 | 1750 | ||
| 1751 | for (offset = 0; offset < gc->ngpio; offset++) { | 1751 | for (offset = 0; offset < gc->ngpio; offset++) { |
| @@ -1791,6 +1791,7 @@ int gpiochip_irqchip_add_domain(struct gpio_chip *gc, · 39 unmodified lines | |||
| 1791 | 1791 | ||
| 1792 | gc->to_irq = gpiochip_to_irq; | 1792 | gc->to_irq = gpiochip_to_irq; |
| 1793 | gc->irq.domain = domain; | 1793 | gc->irq.domain = domain; |
| 1794 | gc->irq.domain_is_allocated_externally = true; | ||
| 1794 | 1795 | ||
| 1795 | /* | 1796 | /* |
| 1796 | * Using barrier() here to prevent compiler from reordering | 1797 | * Using barrier() here to prevent compiler from reordering |
| @@ -251,6 +251,14 @@ struct gpio_irq_chip { · 250 unmodified lines | |||
| 251 | */ | 251 | */ |
| 252 | bool initialized; | 252 | bool initialized; |
| 253 | 253 | ||
| 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 | |||
| 254 | /** | 262 | /** |
| 255 | * @init_hw: optional routine to initialize hardware before | 263 | * @init_hw: optional routine to initialize hardware before |
| 256 | * an IRQ chip will be added. This is quite useful when | 264 | * an IRQ chip will be added. This is quite useful when |