Patch "Revert "leds: led-core: Fix refcount leak in of_led_get()"" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    Revert "leds: led-core: Fix refcount leak in of_led_get()"

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     revert-leds-led-core-fix-refcount-leak-in-of_led_get.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit ffaa94fb21572b09d825fdb918e13829113515bf
Author: Luca Ceresoli <luca.ceresoli@xxxxxxxxxxx>
Date:   Tue Jun 25 10:34:38 2024 +0200

    Revert "leds: led-core: Fix refcount leak in of_led_get()"
    
    [ Upstream commit 940b27161afc6ec53fc66245a4fb3518394cdc92 ]
    
    This reverts commit da1afe8e6099980fe1e2fd7436dca284af9d3f29.
    
    Commit 699a8c7c4bd3 ("leds: Add of_led_get() and led_put()"), introduced in
    5.5, added of_led_get() and led_put() but missed a put_device() in
    led_put(), thus creating a leak in case the consumer device is removed.
    
    Arguably device removal was not very popular, so this went apparently
    unnoticed until 2022. In January 2023 two different patches got merged to
    fix the same bug:
    
     - commit da1afe8e6099 ("leds: led-core: Fix refcount leak in of_led_get()")
     - commit 445110941eb9 ("leds: led-class: Add missing put_device() to led_put()")
    
    They fix the bug in two different ways, which creates no patch conflicts,
    and both were merged in v6.2. The result is that now there is one more
    put_device() than get_device()s, instead of one less.
    
    Arguably device removal is not very popular yet, so this apparently hasn't
    been noticed as well up to now. But it blew up here while I'm working with
    device tree overlay insertion and removal. The symptom is an apparently
    unrelated list of oopses on device removal, with reasons:
    
      kernfs: can not remove 'uevent', no directory
      kernfs: can not remove 'brightness', no directory
      kernfs: can not remove 'max_brightness', no directory
      ...
    
    Here sysfs fails removing attribute files, which is because the device name
    changed and so the sysfs path. This is because the device name string got
    corrupted, which is because it got freed too early and its memory reused.
    
    Different symptoms could appear in different use cases.
    
    Fix by removing one of the two fixes.
    
    The choice was to remove commit da1afe8e6099 because:
    
     * it is calling put_device() inside of_led_get() just after getting the
       device, thus it is basically not refcounting the LED device at all
       during its entire lifetime
     * it does not add a corresponding put_device() in led_get(), so it fixes
       only the OF case
    
    The other fix (445110941eb9) is adding the put_device() in led_put() so it
    covers the entire lifetime, and it works even in the non-DT case.
    
    Fixes: da1afe8e6099 ("leds: led-core: Fix refcount leak in of_led_get()")
    Co-developed-by: Hervé Codina <herve.codina@xxxxxxxxxxx>
    Signed-off-by: Hervé Codina <herve.codina@xxxxxxxxxxx>
    Signed-off-by: Luca Ceresoli <luca.ceresoli@xxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20240625-led-class-device-leak-v2-1-75fdccf47421@xxxxxxxxxxx
    Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index aa39b2a48fdff..7391d2cf1370a 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -235,7 +235,6 @@ struct led_classdev *of_led_get(struct device_node *np, int index)
 
 	led_dev = class_find_device_by_of_node(leds_class, led_node);
 	of_node_put(led_node);
-	put_device(led_dev);
 
 	if (!led_dev)
 		return ERR_PTR(-EPROBE_DEFER);




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux