Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1191868 > unrolled thread

[PATCH] leds/led-class: Add missing put_device()

Started byRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
First post2015-07-24 16:10 +0200
Last post2015-07-24 16:10 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] leds/led-class: Add missing put_device() Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> - 2015-07-24 16:10 +0200

#1191868 — [PATCH] leds/led-class: Add missing put_device()

FromRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Date2015-07-24 16:10 +0200
Subject[PATCH] leds/led-class: Add missing put_device()
Message-ID<pPLPJ-80T-53@gated-at.bofh.it>
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!

 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..380cda0bff72 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 ((dev = class_find_device(leds_class, NULL, name, match_name)) &&
+	       (ret < len)) {
+		put_device(dev);
 		ret = snprintf(name, len, "%s_%u", init_name, ++i);
+	}
 
 	if (ret >= len)
 		return -ENOMEM;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web