From: Pavel Machek <pavel@ucw.cz>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>,
Dan Murphy <dmurphy@ti.com>,
linux-leds@vger.kernel.org
Subject: Re: [PATCH v1] leds: Allow to call led_classdev_unregister() unconditionally
Date: Fri, 16 Aug 2019 13:49:08 +0200 [thread overview]
Message-ID: <20190816114908.GA10081@amd> (raw)
In-Reply-To: <20190816105229.81234-1-andriy.shevchenko@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 1641 bytes --]
Hi!
> If in the certain driver the LED is optional, and it's a majority of them,
> the call of led_classdev_unregister() still requires some additional checks.
>
> The usual pattern on unregistering is to check for NULL, but we also check
> for IS_ERR() in case device_create_with_groups() fails.
>
> The change will reduce a burden in a lot of drivers to repeatedly check
> for above conditions.
I don't see majority of calls being protected. Doing nothing on NULL
sounds reasonable. I'm less sure about "IS_ERR"...
Best regards,
Pavel
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> drivers/leds/led-class.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index d231240c2047..80b62b807ea0 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -287,6 +287,7 @@ int led_classdev_register_ext(struct device *parent,
> ret = led_add_brightness_hw_changed(led_cdev);
> if (ret) {
> device_unregister(led_cdev->dev);
> + led_cdev->dev = NULL;
> mutex_unlock(&led_cdev->led_access);
> return ret;
> }
> @@ -332,6 +333,9 @@ EXPORT_SYMBOL_GPL(led_classdev_register_ext);
> */
> void led_classdev_unregister(struct led_classdev *led_cdev)
> {
> + if (IS_ERR_OR_NULL(led_cdev->dev))
> + return;
> +
> #ifdef CONFIG_LEDS_TRIGGERS
> down_write(&led_cdev->trigger_lock);
> if (led_cdev->trigger)
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
next prev parent reply other threads:[~2019-08-16 11:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-16 10:52 [PATCH v1] leds: Allow to call led_classdev_unregister() unconditionally Andy Shevchenko
2019-08-16 11:49 ` Pavel Machek [this message]
2019-08-16 13:31 ` Andy Shevchenko
2019-08-16 18:02 ` Jacek Anaszewski
2019-08-25 10:51 ` Jacek Anaszewski
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=20190816114908.GA10081@amd \
--to=pavel@ucw.cz \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dmurphy@ti.com \
--cc=jacek.anaszewski@gmail.com \
--cc=linux-leds@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox