diff mbox series

ALSA: core: control_led: fix memory leak in snd_ctl_led_set_state()

Message ID 20210404064031.48711-1-o-takashi@sakamocchi.jp (mailing list archive)
State New
Headers show
Series ALSA: core: control_led: fix memory leak in snd_ctl_led_set_state() | expand

Commit Message

Takashi Sakamoto April 4, 2021, 6:40 a.m. UTC
When inquired control element is not in led group, snd_ctl_led_set_state()
attempts to add the element into the group, according to function
arguments. Although an memory object is allocated for led instance, it's
left as is without being released.

This commit fixes the memory leak.

Fixes: 22d8de62f11b ("ALSA: control - add generic LED trigger module as the new control layer")
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/core/control_led.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Jaroslav Kysela April 4, 2021, 8:16 a.m. UTC | #1
Dne 04. 04. 21 v 8:40 Takashi Sakamoto napsal(a):
> When inquired control element is not in led group, snd_ctl_led_set_state()
> attempts to add the element into the group, according to function
> arguments. Although an memory object is allocated for led instance, it's
> left as is without being released.
> 
> This commit fixes the memory leak.
> 
> Fixes: 22d8de62f11b ("ALSA: control - add generic LED trigger module as the new control layer")
> Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
> ---
>  sound/core/control_led.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/sound/core/control_led.c b/sound/core/control_led.c
> index 788fd9e275e0..b97f118cd54e 100644
> --- a/sound/core/control_led.c
> +++ b/sound/core/control_led.c
> @@ -161,6 +161,7 @@ static void snd_ctl_led_set_state(struct snd_card *card, unsigned int access,
>  			list_add(&lctl->list, &led->controls);
>  			UPDATE_ROUTE(route, snd_ctl_led_get(lctl));
>  		}
> +		kfree(lctl);

NAK: The lctl pointer is added to led->controls list to track the related
kctl. The kfree is called from snd_ctl_led_clean().

				Jaroslav
Takashi Sakamoto April 6, 2021, 1:16 a.m. UTC | #2
On Sun, Apr 04, 2021 at 10:16:03AM +0200, Jaroslav Kysela wrote:
> Dne 04. 04. 21 v 8:40 Takashi Sakamoto napsal(a):
> > When inquired control element is not in led group, snd_ctl_led_set_state()
> > attempts to add the element into the group, according to function
> > arguments. Although an memory object is allocated for led instance, it's
> > left as is without being released.
> > 
> > This commit fixes the memory leak.
> > 
> > Fixes: 22d8de62f11b ("ALSA: control - add generic LED trigger module as the new control layer")
> > Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
> > ---
> >  sound/core/control_led.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/sound/core/control_led.c b/sound/core/control_led.c
> > index 788fd9e275e0..b97f118cd54e 100644
> > --- a/sound/core/control_led.c
> > +++ b/sound/core/control_led.c
> > @@ -161,6 +161,7 @@ static void snd_ctl_led_set_state(struct snd_card *card, unsigned int access,
> >  			list_add(&lctl->list, &led->controls);
> >  			UPDATE_ROUTE(route, snd_ctl_led_get(lctl));
> >  		}
> > +		kfree(lctl);
> 
> NAK: The lctl pointer is added to led->controls list to track the related
> kctl. The kfree is called from snd_ctl_led_clean().

Ah. I overlooked it. Please abandon the patch.


Regards

Takashi Sakamoto
diff mbox series

Patch

diff --git a/sound/core/control_led.c b/sound/core/control_led.c
index 788fd9e275e0..b97f118cd54e 100644
--- a/sound/core/control_led.c
+++ b/sound/core/control_led.c
@@ -161,6 +161,7 @@  static void snd_ctl_led_set_state(struct snd_card *card, unsigned int access,
 			list_add(&lctl->list, &led->controls);
 			UPDATE_ROUTE(route, snd_ctl_led_get(lctl));
 		}
+		kfree(lctl);
 	}
 	mutex_unlock(&snd_ctl_led_mutex);
 	switch (led->mode) {