Skip to contentSkip to conversation

gpio: Fix potentially NULL handler data passed to chained irqchip handler

PATCH In review Jarkko Nikula 3 participants 3 messages Sep 16, 2014 – Sep 24, 2014 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: Fix potentially NULL handler data passed to chained irqchip handler

There is possibility with misconfigured pins that interrupt occurs instantly after setting irq_set_chained_handler() in gpiochip_set_chained_irqchip(). Now if handler gets called before irq_set_handler_data() the handler gets NULL handler data.

Fix this by moving irq_set_handler_data() call before irq_set_chained_handler() in gpiochip_set_chained_irqchip().

---
I noticed this while debugging why commit e1ee5c578fb1 ("pinctrl: baytrail:
Convert to use gpiolib irqchip") was showing a regression on a development machine with a few misconfigured pins by the BIOS. For those pins drivers/pinctrl/pinctrl-baytrail.c: byt_gpio_irq_handler() was often called instantly with handler data being NULL and dummy if (vg == NULL) return; test there didn't allow code further in byt_gpio_irq_handler() to disable those flooding pins.

---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib.c +1 -1
index 15cc0bb65dda..ed3f518e4337 100644
@@ -413,12 +413,12 @@ void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
 		return;
 	}
 
-	irq_set_chained_handler(parent_irq, parent_handler);
 	/*
 	 * The parent irqchip is already using the chip_data for this
 	 * irqchip, so our callbacks simply use the handler_data.
 	 */
 	irq_set_handler_data(parent_irq, gpiochip);
+	irq_set_chained_handler(parent_irq, parent_handler);
 }
 EXPORT_SYMBOL_GPL(gpiochip_set_chained_irqchip);
 
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jarkko Nikula

There is possibility with misconfigured pins that interrupt occurs instantly after setting irq_set_chained_handler() in gpiochip_set_chained_irqchip(). Now if handler gets called before irq_set_handler_data() the handler gets NULL handler data.

Fix this by moving irq_set_handler_data() call before irq_set_chained_handler() in gpiochip_set_chained_irqchip().

#2 lore raw
In reply to Jarkko Nikula
Quoted 10 lines · Jarkko Nikula

There is possibility with misconfigured pins that interrupt occurs instantly after setting irq_set_chained_handler() in gpiochip_set_chained_irqchip(). Now if handler gets called before irq_set_handler_data() the handler gets NULL handler data.

Fix this by moving irq_set_handler_data() call before irq_set_chained_handler() in gpiochip_set_chained_irqchip().

Patch applied for fixes with Alex's review tag.

Yours,
Linus Walleij