From e5b5a61fcb3743f1dacf9e20d28f48423cecf0c1 Mon Sep 17 00:00:00 2001 From: Ricardo Ribalda Delgado Date: Fri, 31 Jul 2015 13:36:21 +0200 Subject: 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") Reported-by: Alan Tull Signed-off-by: Ricardo Ribalda Delgado Signed-off-by: Jacek Anaszewski --- drivers/leds/led-class.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers/leds') 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; -- cgit v1.2.3