[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VfcpM9rVkWTZzytLgEqM5TOrhYHhntAFKa220AJbshxzw@mail.gmail.com>
Date: Sat, 17 Sep 2022 11:23:29 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Jean-Jacques Hiblot <jjhiblot@...phandler.com>
Cc: pavel@....cz, robh+dt@...nel.org,
sven.schwermer@...ruptive-technologies.com,
krzysztof.kozlowski+dt@...aro.org, johan+linaro@...nel.org,
marijn.suijten@...ainline.org, bjorn.andersson@...aro.org,
linux-leds@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, sha@...gutronix.de
Subject: Re: [RESEND PATCH v3 1/4] leds: class: simplify the implementation of devm_of_led_get()
On Sat, Sep 17, 2022 at 11:14 AM Jean-Jacques Hiblot
<jjhiblot@...phandler.com> wrote:
>
> Use the devm_add_action_or_reset() helper.
Reviewed-by: Andy Shevchenko <andy.shevchenko@...il.com>
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@...phandler.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
>
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists