Skip to content

Commit 48e1b4d

Browse files
author
Bartosz Golaszewski
committed
gpiolib: remove the GPIO device from the list when it's unregistered
If we wait until the GPIO device's .release() callback gets invoked before we remove it from the global device list, then we risk that someone will look it up using gpio_device_find() between where we dropped the last reference and before .release() is done taking a reference again to an object that's being released. The device must be removed when it's being unregistered - just like how we remove it from the GPIO bus. Fixes: ff2b135 ("gpio: make the gpiochip a real device") Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Linus Walleij <[email protected]>
1 parent c4f8457 commit 48e1b4d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/gpio/gpiolib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,6 @@ static void gpiodev_release(struct device *dev)
651651
{
652652
struct gpio_device *gdev = to_gpio_device(dev);
653653

654-
scoped_guard(mutex, &gpio_devices_lock)
655-
list_del(&gdev->list);
656-
657654
ida_free(&gpio_ida, gdev->id);
658655
kfree_const(gdev->label);
659656
kfree(gdev->descs);
@@ -1068,6 +1065,9 @@ void gpiochip_remove(struct gpio_chip *gc)
10681065
dev_crit(&gdev->dev,
10691066
"REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n");
10701067

1068+
scoped_guard(mutex, &gpio_devices_lock)
1069+
list_del(&gdev->list);
1070+
10711071
/*
10721072
* The gpiochip side puts its use of the device to rest here:
10731073
* if there are no userspace clients, the chardev and device will

0 commit comments

Comments
 (0)