Skip to content

Commit 417cad5

Browse files
joehattorilag-linaro
authored andcommitted
leds: cht-wcove: Use devm_led_classdev_register() to avoid memory leak
cht_wc_leds_probe() leaks memory when the second led_classdev_register() call in the for-loop fails as it does not call the cleanup function led_classdev_unregister() on the first device. Avoid this leak by calling devm_led_classdev_register(). Fixes: 047da76 ("leds: Add Intel Cherry Trail Whiskey Cove PMIC LED driver") Signed-off-by: Joe Hattori <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent e14d879 commit 417cad5

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

drivers/leds/leds-cht-wcove.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ static int cht_wc_leds_probe(struct platform_device *pdev)
394394
led->cdev.pattern_clear = cht_wc_leds_pattern_clear;
395395
led->cdev.max_brightness = 255;
396396

397-
ret = led_classdev_register(&pdev->dev, &led->cdev);
397+
ret = devm_led_classdev_register(&pdev->dev, &led->cdev);
398398
if (ret < 0)
399399
return ret;
400400
}
@@ -406,10 +406,6 @@ static int cht_wc_leds_probe(struct platform_device *pdev)
406406
static void cht_wc_leds_remove(struct platform_device *pdev)
407407
{
408408
struct cht_wc_leds *leds = platform_get_drvdata(pdev);
409-
int i;
410-
411-
for (i = 0; i < CHT_WC_LED_COUNT; i++)
412-
led_classdev_unregister(&leds->leds[i].cdev);
413409

414410
/* Restore LED1 regs if hw-control was active else leave LED1 off */
415411
if (!(leds->led1_initial_regs.ctrl & CHT_WC_LED1_SWCTL))

0 commit comments

Comments
 (0)