]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
gpio: ljca: use devm_mutex_init() to simplify the error path and remove()
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 8 Oct 2024 16:24:16 +0000 (18:24 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 14 Oct 2024 08:30:36 +0000 (10:30 +0200)
Destroying the mutexes is done at the end of remove() so switching to
devres does not constitute a functional change. Use devm_mutex_init()
and remove repetitions of mutex_destroy().

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20241008162416.85111-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpio-ljca.c

index dfec9fbfc7a9bd8a98916a5ad2676aa380470852..d67b912d884ddb1ffc33fcfa2f513e252ca600b3 100644 (file)
@@ -420,8 +420,14 @@ static int ljca_gpio_probe(struct auxiliary_device *auxdev,
        if (!ljca_gpio->connect_mode)
                return -ENOMEM;
 
-       mutex_init(&ljca_gpio->irq_lock);
-       mutex_init(&ljca_gpio->trans_lock);
+       ret = devm_mutex_init(&auxdev->dev, &ljca_gpio->irq_lock);
+       if (ret)
+               return ret;
+
+       ret = devm_mutex_init(&auxdev->dev, &ljca_gpio->trans_lock);
+       if (ret)
+               return ret;
+
        ljca_gpio->gc.direction_input = ljca_gpio_direction_input;
        ljca_gpio->gc.direction_output = ljca_gpio_direction_output;
        ljca_gpio->gc.get_direction = ljca_gpio_get_direction;
@@ -453,11 +459,8 @@ static int ljca_gpio_probe(struct auxiliary_device *auxdev,
 
        INIT_WORK(&ljca_gpio->work, ljca_gpio_async);
        ret = gpiochip_add_data(&ljca_gpio->gc, ljca_gpio);
-       if (ret) {
+       if (ret)
                ljca_unregister_event_cb(ljca);
-               mutex_destroy(&ljca_gpio->irq_lock);
-               mutex_destroy(&ljca_gpio->trans_lock);
-       }
 
        return ret;
 }
@@ -469,8 +472,6 @@ static void ljca_gpio_remove(struct auxiliary_device *auxdev)
        gpiochip_remove(&ljca_gpio->gc);
        ljca_unregister_event_cb(ljca_gpio->ljca);
        cancel_work_sync(&ljca_gpio->work);
-       mutex_destroy(&ljca_gpio->irq_lock);
-       mutex_destroy(&ljca_gpio->trans_lock);
 }
 
 static const struct auxiliary_device_id ljca_gpio_id_table[] = {