History

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

Linus Torvalds committed 3 years ago

Commit 6edecb92 parents afa4bb7 ff7a1793 files · +24 −3Browse files

Unified · Split

3 files
  1. drivers/gpio/gpio-sifive.c +6 −2
  2. drivers/gpio/gpiolib.c +10 −1
  3. include/linux/gpio/driver.h +8 −0
drivers/gpio/gpio-sifive.c+6−2
@@ -221,8 +221,12 @@ static int sifive_gpio_probe(struct platform_device *pdev) · 220 unmodified lines
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+10−1
@@ -1745,7 +1745,7 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gc) · 1744 unmodified lines
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, · 39 unmodified lines
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+8−0
@@ -251,6 +251,14 @@ struct gpio_irq_chip { · 250 unmodified lines
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