* [PATCH v2] leds/led-class: Add missing put_device()
@ 2015-07-31 11:36 Ricardo Ribalda Delgado
2015-07-31 16:15 ` Jacek Anaszewski
0 siblings, 1 reply; 2+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-07-31 11:36 UTC (permalink / raw)
To: Alan Tull, Bryan Wu, Richard Purdie, Jacek Anaszewski, linux-leds,
linux-kernel, Jacek Anaszewski
Cc: Ricardo Ribalda Delgado
Devices found by class_find_device must be freed with put_device().
Otherwise the reference count will not work properly.
Fixes: a96aa64cb572 ("leds/led-class: Handle LEDs with the same name")
Reported-by: Alan Tull <delicious.quinoa@gmail.com>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
Thanks Alan for the initial report and Jacek for the review
v2: Changes from Jacek Anaszewski <jacek.anaszewski@gmail.com>
If ret <= len device was not relased
drivers/leds/led-class.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index beabfbc6f7cd..ca51d58bed24 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -228,12 +228,15 @@ static int led_classdev_next_name(const char *init_name, char *name,
{
unsigned int i = 0;
int ret = 0;
+ struct device *dev;
strlcpy(name, init_name, len);
- while (class_find_device(leds_class, NULL, name, match_name) &&
- (ret < len))
+ while ((ret < len) &&
+ (dev = class_find_device(leds_class, NULL, name, match_name))) {
+ put_device(dev);
ret = snprintf(name, len, "%s_%u", init_name, ++i);
+ }
if (ret >= len)
return -ENOMEM;
--
2.4.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] leds/led-class: Add missing put_device()
2015-07-31 11:36 [PATCH v2] leds/led-class: Add missing put_device() Ricardo Ribalda Delgado
@ 2015-07-31 16:15 ` Jacek Anaszewski
0 siblings, 0 replies; 2+ messages in thread
From: Jacek Anaszewski @ 2015-07-31 16:15 UTC (permalink / raw)
To: Ricardo Ribalda Delgado, Alan Tull, Bryan Wu, Richard Purdie,
Jacek Anaszewski, linux-leds, linux-kernel
Hi Ricardo,
Thanks for the update.
On 31.07.2015 13:36, Ricardo Ribalda Delgado wrote:
> Devices found by class_find_device must be freed with put_device().
> Otherwise the reference count will not work properly.
>
> Fixes: a96aa64cb572 ("leds/led-class: Handle LEDs with the same name")
> Reported-by: Alan Tull <delicious.quinoa@gmail.com>
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> ---
> Thanks Alan for the initial report and Jacek for the review
>
> v2: Changes from Jacek Anaszewski <jacek.anaszewski@gmail.com>
> If ret <= len device was not relased
>
> drivers/leds/led-class.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index beabfbc6f7cd..ca51d58bed24 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -228,12 +228,15 @@ static int led_classdev_next_name(const char *init_name, char *name,
> {
> unsigned int i = 0;
> int ret = 0;
> + struct device *dev;
>
> strlcpy(name, init_name, len);
>
> - while (class_find_device(leds_class, NULL, name, match_name) &&
> - (ret < len))
> + while ((ret < len) &&
> + (dev = class_find_device(leds_class, NULL, name, match_name))) {
> + put_device(dev);
> ret = snprintf(name, len, "%s_%u", init_name, ++i);
> + }
>
> if (ret >= len)
> return -ENOMEM;
>
Acked-by: Jacek Anaszewski <j.anaszewski@samsung.com>
--
Best Regards,
Jacek Anaszewski
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-07-31 16:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-31 11:36 [PATCH v2] leds/led-class: Add missing put_device() Ricardo Ribalda Delgado
2015-07-31 16:15 ` Jacek Anaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).