driver-core: platform: Catch errors from calls to irq_get_irq_data
authorGuenter Roeck <linux@roeck-us.net>
Wed, 14 Sep 2016 03:32:44 +0000 (20:32 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 27 Sep 2016 10:30:37 +0000 (12:30 +0200)
irq_get_irq_data() can return NULL, which results in a nasty crash.
Check its return value before passing it on to irqd_set_trigger_type().

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/platform.c

index 44c9d4daf510eb881f4aed013ef50240632321d6..c4af00385502ffd9039bc73d1eccc2eedef33ce4 100644 (file)
@@ -108,9 +108,14 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
         * IORESOURCE_BITS correspond 1-to-1 to the IRQF_TRIGGER*
         * settings.
         */
-       if (r && r->flags & IORESOURCE_BITS)
-               irqd_set_trigger_type(irq_get_irq_data(r->start),
-                                     r->flags & IORESOURCE_BITS);
+       if (r && r->flags & IORESOURCE_BITS) {
+               struct irq_data *irqd;
+
+               irqd = irq_get_irq_data(r->start);
+               if (!irqd)
+                       return -ENXIO;
+               irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
+       }
 
        return r ? r->start : -ENXIO;
 #endif