diff options
author | Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> | 2016-06-03 13:10:02 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2016-06-08 04:40:29 -0400 |
commit | f4833b8cc7edab57d3f3033e549111a546c2e02b (patch) | |
tree | 9ec107aa22c29db288c6444ee21d3f1be5521266 /drivers/gpio | |
parent | 11f33a6d15bfa397867ac0d7f3481b6dd683286f (diff) |
gpiolib: Fix unaligned used of reference counters
gpiolib relies on the reference counters to clean up the gpio_device
structure.
Although the number of get/put is properly aligned on gpiolib.c
itself, it does not take into consideration how the referece counters
are affected by other external functions such as cdev_add and device_add.
Because of this, after the last call to put_device, the reference counter
has a value of +3, therefore never calling gpiodevice_release.
Due to the fact that some of the device has already been cleaned on
gpiochip_remove, the library will end up OOPsing the kernel (e.g. a call
to of_gpiochip_find_and_xlate).
Cc: stable@vger.kernel.org
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/gpiolib.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index a2c31a5a677f..58d822d7e8da 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -449,7 +449,6 @@ static void gpiodevice_release(struct device *dev) | |||
449 | { | 449 | { |
450 | struct gpio_device *gdev = dev_get_drvdata(dev); | 450 | struct gpio_device *gdev = dev_get_drvdata(dev); |
451 | 451 | ||
452 | cdev_del(&gdev->chrdev); | ||
453 | list_del(&gdev->list); | 452 | list_del(&gdev->list); |
454 | ida_simple_remove(&gpio_ida, gdev->id); | 453 | ida_simple_remove(&gpio_ida, gdev->id); |
455 | kfree(gdev->label); | 454 | kfree(gdev->label); |
@@ -482,7 +481,6 @@ static int gpiochip_setup_dev(struct gpio_device *gdev) | |||
482 | 481 | ||
483 | /* From this point, the .release() function cleans up gpio_device */ | 482 | /* From this point, the .release() function cleans up gpio_device */ |
484 | gdev->dev.release = gpiodevice_release; | 483 | gdev->dev.release = gpiodevice_release; |
485 | get_device(&gdev->dev); | ||
486 | pr_debug("%s: registered GPIOs %d to %d on device: %s (%s)\n", | 484 | pr_debug("%s: registered GPIOs %d to %d on device: %s (%s)\n", |
487 | __func__, gdev->base, gdev->base + gdev->ngpio - 1, | 485 | __func__, gdev->base, gdev->base + gdev->ngpio - 1, |
488 | dev_name(&gdev->dev), gdev->chip->label ? : "generic"); | 486 | dev_name(&gdev->dev), gdev->chip->label ? : "generic"); |
@@ -770,6 +768,8 @@ void gpiochip_remove(struct gpio_chip *chip) | |||
770 | * be removed, else it will be dangling until the last user is | 768 | * be removed, else it will be dangling until the last user is |
771 | * gone. | 769 | * gone. |
772 | */ | 770 | */ |
771 | cdev_del(&gdev->chrdev); | ||
772 | device_del(&gdev->dev); | ||
773 | put_device(&gdev->dev); | 773 | put_device(&gdev->dev); |
774 | } | 774 | } |
775 | EXPORT_SYMBOL_GPL(gpiochip_remove); | 775 | EXPORT_SYMBOL_GPL(gpiochip_remove); |