diff mbox series

[1/4] leds: class: simplify the implementation of devm_of_led_get()

Message ID 20220615154918.521687-2-jjhiblot@traphandler.com
State New
Headers show
Series [1/4] leds: class: simplify the implementation of devm_of_led_get() | expand

Commit Message

Jean-Jacques Hiblot June 15, 2022, 3:49 p.m. UTC
Use the devm_add_action_or_reset() helper.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
---
 drivers/leds/led-class.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 6a8ea94834fa..72fd6ee7af88 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -20,8 +20,10 @@ 
 #include <linux/timer.h>
 #include <uapi/linux/uleds.h>
 #include <linux/of.h>
+#include <linux/acpi.h>
 #include "leds.h"
 
+
 static struct class *leds_class;
 
 static ssize_t brightness_show(struct device *dev,
@@ -258,11 +260,9 @@  void led_put(struct led_classdev *led_cdev)
 }
 EXPORT_SYMBOL_GPL(led_put);
 
-static void devm_led_release(struct device *dev, void *res)
+static void devm_led_release(void *cdev)
 {
-	struct led_classdev **p = res;
-
-	led_put(*p);
+	led_put((struct led_classdev *) cdev);
 }
 
 /**
@@ -280,7 +280,7 @@  struct led_classdev *__must_check devm_of_led_get(struct device *dev,
 						  int index)
 {
 	struct led_classdev *led;
-	struct led_classdev **dr;
+	int ret;
 
 	if (!dev)
 		return ERR_PTR(-EINVAL);
@@ -289,15 +289,9 @@  struct led_classdev *__must_check devm_of_led_get(struct device *dev,
 	if (IS_ERR(led))
 		return led;
 
-	dr = devres_alloc(devm_led_release, sizeof(struct led_classdev *),
-			  GFP_KERNEL);
-	if (!dr) {
-		led_put(led);
-		return ERR_PTR(-ENOMEM);
-	}
-
-	*dr = led;
-	devres_add(dev, dr);
+	ret = devm_add_action_or_reset(dev, devm_led_release, led);
+	if (ret)
+		return ERR_PTR(ret);
 
 	return led;
 }