Skip to contentSkip to conversation

leds/led-class: Add missing put_device()

PATCH In review Ricardo Ribalda Delgado 2 participants 2 messages Jul 31, 2015 LED

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 leds/led-class: Add missing put_device()

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")

---
Thanks Alan for the initial report and Jacek for the review

v2: Changes from Jacek Anaszewski <[email protected]> If ret <= len device was not relased

 drivers/leds/led-class.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/leds/led-class.c +5 -2
index beabfbc6f7cd..ca51d58bed24 100644
@@ -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;
Signature · 1 line
2.4.6
Acked-by on v2 1/1
#1 lore raw

Hi Ricardo,

Thanks for the update.

Quoted 28 lines · 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")

---
Thanks Alan for the initial report and Jacek for the review

v2: Changes from Jacek Anaszewski <[email protected]> If ret <= len device was not relased

  drivers/leds/led-class.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/leds/led-class.c +1 -0
index beabfbc6f7cd..ca51d58bed24 100644
@@ -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);
 

drivers/leds/led-class.c static int led_classdev_next_name(const char *init_name, char *name, · line 242

Quoted 10 lines
drivers/leds/led-class.c +4 -2
-	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;
Signature · 2 lines
Best Regards,
Jacek Anaszewski