Skip to contentSkip to conversation

gpio: ljca: use devm_mutex_init() to simplify the error path and remove()

PATCH Applied Bartosz Golaszewski 2 participants 3 messages Oct 8, 2024 – Oct 14, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: ljca: use devm_mutex_init() to simplify the error path and remove()

From: Bartosz Golaszewski <[email protected]>

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().

---
 drivers/gpio/gpio-ljca.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpio/gpio-ljca.c +9 -8
index dfec9fbfc7a9..d67b912d884d 100644
@@ -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[] = {
Signature · 1 line
2.43.0
author Applied
#2 lore raw
In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 5 lines · Bartosz Golaszewski

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().

Applied, thanks!

[1/1] gpio: ljca: use devm_mutex_init() to simplify the error path and remove()

      commit: 476f18c0895df7b281eb84b3e687e6101c844338

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>