gpio: potential null dereference
authorDan Carpenter <error27@gmail.com>
Tue, 27 Apr 2010 21:12:03 +0000 (14:12 -0700)
committerGrant Likely <grant.likely@secretlab.ca>
Wed, 28 Apr 2010 06:50:01 +0000 (00:50 -0600)
Smatch found a potential null dereference in gpio_setup_irq().  The
"pdesc" variable is allocated with idr_find() that can return NULL.  If
gpio_setup_irq() is called with 0 as gpio_flags and "pdesc" is null, it
would OOPs here.

Signed-off-by: Dan Carpenter <error27@gmail.com>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
drivers/gpio/gpiolib.c

index 76be229c814d40479f37d158c9cc1532a94e9b33..eb0c3fe44b29b32e6ee72dc0bb52ccd351aa9323 100644 (file)
@@ -416,7 +416,8 @@ static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev,
        return 0;
 
 free_sd:
-       sysfs_put(pdesc->value_sd);
+       if (pdesc)
+               sysfs_put(pdesc->value_sd);
 free_id:
        idr_remove(&pdesc_idr, id);
        desc->flags &= GPIO_FLAGS_MASK;