leds: led-core: Fix refcount leak in of_led_get

Message ID 20221220121807.1543790-1-linmq006@gmail.com
State New
Headers
Series leds: led-core: Fix refcount leak in of_led_get |

Commit Message

Miaoqian Lin Dec. 20, 2022, 12:18 p.m. UTC
  class_find_device_by_of_node() calls class_find_device(), it will take
the reference, use the put_device() to drop the reference when not need
anymore.

Fixes: 699a8c7c4bd3 ("leds: Add of_led_get() and led_put()")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/leds/led-class.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Lee Jones Jan. 4, 2023, 6:58 p.m. UTC | #1
On Tue, 20 Dec 2022, Miaoqian Lin wrote:

> class_find_device_by_of_node() calls class_find_device(), it will take
> the reference, use the put_device() to drop the reference when not need
> anymore.
> 
> Fixes: 699a8c7c4bd3 ("leds: Add of_led_get() and led_put()")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  drivers/leds/led-class.c | 1 +
>  1 file changed, 1 insertion(+)

Applied, thanks
  

Patch

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 6a8ea94834fa..705b7a89f3d8 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -240,6 +240,7 @@  struct led_classdev *of_led_get(struct device_node *np, int index)
 		return ERR_PTR(-EPROBE_DEFER);
 
 	led_cdev = dev_get_drvdata(led_dev);
+	put_device(led_dev);
 
 	if (!try_module_get(led_cdev->dev->parent->driver->owner))
 		return ERR_PTR(-ENODEV);