All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
To: <pavel@ucw.cz>, <robh+dt@kernel.org>,
	<sven.schwermer@disruptive-technologies.com>,
	<krzysztof.kozlowski+dt@linaro.org>
Cc: <johan+linaro@kernel.org>, <marijn.suijten@somainline.org>,
	<bjorn.andersson@linaro.org>, <andy.shevchenko@gmail.com>,
	<linux-leds@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <sha@pengutronix.de>,
	Jean-Jacques Hiblot <jjhiblot@traphandler.com>
Subject: [RESEND PATCH v3 1/4] leds: class: simplify the implementation of devm_of_led_get()
Date: Sat, 17 Sep 2022 10:13:36 +0200	[thread overview]
Message-ID: <20220917081339.3354075-2-jjhiblot@traphandler.com> (raw)
In-Reply-To: <20220917081339.3354075-1-jjhiblot@traphandler.com>

Use the devm_add_action_or_reset() helper.

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

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 6a8ea94834fa..2c0d979d0c8a 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -258,11 +258,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(cdev);
 }
 
 /**
@@ -280,7 +278,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 +287,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;
 }
-- 
2.25.1


  reply	other threads:[~2022-09-17  8:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-17  8:13 [RESEND PATCH v3 0/4] Add a multicolor LED driver for groups of monochromatic LEDs Jean-Jacques Hiblot
2022-09-17  8:13 ` Jean-Jacques Hiblot [this message]
2022-09-17  8:23   ` [RESEND PATCH v3 1/4] leds: class: simplify the implementation of devm_of_led_get() Andy Shevchenko
2022-09-17  8:13 ` [RESEND PATCH v3 2/4] leds: class: store the color index in struct led_classdev Jean-Jacques Hiblot
2022-09-17  8:40   ` Andy Shevchenko
2022-10-07  6:29     ` Jean-Jacques Hiblot
2022-09-18 11:25   ` Jacek Anaszewski
2022-09-18 13:19     ` Jacek Anaszewski
2022-09-17  8:13 ` [RESEND PATCH v3 3/4] dt-bindings: leds: Add binding for a multicolor group of LEDs Jean-Jacques Hiblot
2022-09-17  8:13 ` [RESEND PATCH v3 4/4] leds: Add a multicolor LED driver to group monochromatic LEDs Jean-Jacques Hiblot
2022-09-17  8:37   ` Andy Shevchenko
2022-10-07  6:34     ` Jean-Jacques Hiblot
2022-10-07  8:53       ` Andy Shevchenko
2022-10-07 12:03         ` Jean-Jacques Hiblot
2022-10-07 13:14           ` Andy Shevchenko
2022-09-18 14:54   ` Jacek Anaszewski
2022-10-07  6:46     ` Jean-Jacques Hiblot
2022-09-17  8:25 ` [RESEND PATCH v3 0/4] Add a multicolor LED driver for groups of " Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220917081339.3354075-2-jjhiblot@traphandler.com \
    --to=jjhiblot@traphandler.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=johan+linaro@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=marijn.suijten@somainline.org \
    --cc=pavel@ucw.cz \
    --cc=robh+dt@kernel.org \
    --cc=sha@pengutronix.de \
    --cc=sven.schwermer@disruptive-technologies.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.