Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <delicious.quinoa@gmail.com>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>

authored by

Ricardo Ribalda Delgado and committed by
Jacek Anaszewski
e5b5a61f 4fc5af86

+5 -2
+5 -2
drivers/leds/led-class.c
··· 228 228 { 229 229 unsigned int i = 0; 230 230 int ret = 0; 231 + struct device *dev; 231 232 232 233 strlcpy(name, init_name, len); 233 234 234 - while (class_find_device(leds_class, NULL, name, match_name) && 235 - (ret < len)) 235 + while ((ret < len) && 236 + (dev = class_find_device(leds_class, NULL, name, match_name))) { 237 + put_device(dev); 236 238 ret = snprintf(name, len, "%s_%u", init_name, ++i); 239 + } 237 240 238 241 if (ret >= len) 239 242 return -ENOMEM;