Skip to content

Commit 6edecb9

Browse files
committed
Merge tag 'gpio-fixes-for-v6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
Pull gpio fixes from Bartosz Golaszewski: - fix IRQ initialization in gpiochip_irqchip_add_domain() - add a missing return value check for platform_get_irq() in gpio-sifive - don't free irq_domains which GPIOLIB does not manage * tag 'gpio-fixes-for-v6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: gpiolib: Fix irq_domain resource tracking for gpiochip_irqchip_add_domain() gpio: sifive: add missing check for platform_get_irq gpiolib: Fix GPIO chip IRQ initialization restriction
2 parents afa4bb7 + ff7a179 commit 6edecb9

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

drivers/gpio/gpio-sifive.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,12 @@ static int sifive_gpio_probe(struct platform_device *pdev)
221221
return -ENODEV;
222222
}
223223

224-
for (i = 0; i < ngpio; i++)
225-
chip->irq_number[i] = platform_get_irq(pdev, i);
224+
for (i = 0; i < ngpio; i++) {
225+
ret = platform_get_irq(pdev, i);
226+
if (ret < 0)
227+
return ret;
228+
chip->irq_number[i] = ret;
229+
}
226230

227231
ret = bgpio_init(&chip->gc, dev, 4,
228232
chip->base + SIFIVE_GPIO_INPUT_VAL,

drivers/gpio/gpiolib.c

Lines changed: 10 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,15 @@ 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;
1795+
1796+
/*
1797+
* Using barrier() here to prevent compiler from reordering
1798+
* gc->irq.initialized before adding irqdomain.
1799+
*/
1800+
barrier();
1801+
1802+
gc->irq.initialized = true;
17941803

17951804
return 0;
17961805
}

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)