2019-08-19 20:43:26

by Wenwen Wang

[permalink] [raw]
Subject: [PATCH] led: triggers: Fix a memory leak bug

In led_trigger_set(), 'event' is allocated in kasprintf(). However, it is
not deallocated in the following execution if the label 'err_activate' or
'err_add_groups' is entered, leading to memory leaks. To fix this issue,
free 'event' before returning the error.

Signed-off-by: Wenwen Wang <[email protected]>
---
drivers/leds/led-triggers.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 8d11a5e..eff1bda 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -173,6 +173,7 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
list_del(&led_cdev->trig_list);
write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags);
led_set_brightness(led_cdev, LED_OFF);
+ kfree(event);

return ret;
}
--
2.7.4


2019-08-19 21:17:27

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH] led: triggers: Fix a memory leak bug

On Mon 2019-08-19 15:41:42, Wenwen Wang wrote:
> In led_trigger_set(), 'event' is allocated in kasprintf(). However, it is
> not deallocated in the following execution if the label 'err_activate' or
> 'err_add_groups' is entered, leading to memory leaks. To fix this issue,
> free 'event' before returning the error.
>
> Signed-off-by: Wenwen Wang <[email protected]>

Acked-by: Pavel Machek <[email protected]>

> +++ b/drivers/leds/led-triggers.c
> @@ -173,6 +173,7 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
> list_del(&led_cdev->trig_list);
> write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags);
> led_set_brightness(led_cdev, LED_OFF);
> + kfree(event);
>
> return ret;
> }

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (900.00 B)
signature.asc (188.00 B)
Digital signature
Download all attachments

2019-08-20 18:28:47

by Jacek Anaszewski

[permalink] [raw]
Subject: Re: [PATCH] led: triggers: Fix a memory leak bug

Hi Wenwen,

Thank you for the patch.

On 8/19/19 10:41 PM, Wenwen Wang wrote:
> In led_trigger_set(), 'event' is allocated in kasprintf(). However, it is
> not deallocated in the following execution if the label 'err_activate' or
> 'err_add_groups' is entered, leading to memory leaks. To fix this issue,
> free 'event' before returning the error.
>
> Signed-off-by: Wenwen Wang <[email protected]>
> ---
> drivers/leds/led-triggers.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
> index 8d11a5e..eff1bda 100644
> --- a/drivers/leds/led-triggers.c
> +++ b/drivers/leds/led-triggers.c
> @@ -173,6 +173,7 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
> list_del(&led_cdev->trig_list);
> write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags);
> led_set_brightness(led_cdev, LED_OFF);
> + kfree(event);
>
> return ret;
> }
>

Added tag:

Fixes: 52c47742f79d ("leds: triggers: send uevent when changing triggers")

and applied.

--
Best regards,
Jacek Anaszewski