gpiolib: Fix irq_domain resource tracking for gpiochip_irqchip_add_domain()
Changes
2 files changed · +10 −1
| File | Status | Add | Del | Content |
|---|---|---|---|---|
| drivers/gpio/gpiolib.c | modified | +2 | −1 | View file |
| include/linux/gpio/driver.h | modified | +8 | −0 | View file |
drivers/gpio/gpiolib.c
View filediff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 9ecf93c..5be8ad6 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1745,7 +1745,7 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gc)
}
/* Remove all IRQ mappings and delete the domain */
- if (gc->irq.domain) {
+ if (!gc->irq.domain_is_allocated_externally && gc->irq.domain) {
unsigned int irq;
for (offset = 0; offset < gc->ngpio; offset++) {
@@ -1791,6 +1791,7 @@ int gpiochip_irqchip_add_domain(struct gpio_chip *gc,
gc->to_irq = gpiochip_to_irq;
gc->irq.domain = domain;
+ gc->irq.domain_is_allocated_externally = true;
/*
* Using barrier() here to prevent compiler from reordering
include/linux/gpio/driver.h
View filediff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 5c6db55..67b8774 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -252,6 +252,14 @@ struct gpio_irq_chip {
bool initialized;
/**
+ * @domain_is_allocated_externally:
+ *
+ * True it the irq_domain was allocated outside of gpiolib, in which
+ * case gpiolib won't free the irq_domain itself.
+ */
+ bool domain_is_allocated_externally;
+
+ /**
* @init_hw: optional routine to initialize hardware before
* an IRQ chip will be added. This is quite useful when
* a particular driver wants to clear IRQ related registers