Skip to content

Commit f4833b8

Browse files
ribaldalinusw
authored andcommitted
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: [email protected] Signed-off-by: Ricardo Ribalda Delgado <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 11f33a6 commit f4833b8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/gpio/gpiolib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ static void gpiodevice_release(struct device *dev)
449449
{
450450
struct gpio_device *gdev = dev_get_drvdata(dev);
451451

452-
cdev_del(&gdev->chrdev);
453452
list_del(&gdev->list);
454453
ida_simple_remove(&gpio_ida, gdev->id);
455454
kfree(gdev->label);
@@ -482,7 +481,6 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
482481

483482
/* From this point, the .release() function cleans up gpio_device */
484483
gdev->dev.release = gpiodevice_release;
485-
get_device(&gdev->dev);
486484
pr_debug("%s: registered GPIOs %d to %d on device: %s (%s)\n",
487485
__func__, gdev->base, gdev->base + gdev->ngpio - 1,
488486
dev_name(&gdev->dev), gdev->chip->label ? : "generic");
@@ -770,6 +768,8 @@ void gpiochip_remove(struct gpio_chip *chip)
770768
* be removed, else it will be dangling until the last user is
771769
* gone.
772770
*/
771+
cdev_del(&gdev->chrdev);
772+
device_del(&gdev->dev);
773773
put_device(&gdev->dev);
774774
}
775775
EXPORT_SYMBOL_GPL(gpiochip_remove);

0 commit comments

Comments
 (0)