diff mbox

ASoC: rsnd: don't double free kctrl

Message ID 20161208130543.11560-1-colin.king@canonical.com (mailing list archive)
State Accepted
Commit 0ea617a298dcdc2251b4e10f83ac3f3e627b66e3
Headers show

Commit Message

Colin King Dec. 8, 2016, 1:05 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

On an error, snd_ctl_add already free's kctrl, so calling snd_ctl_free_one
to free it again leads to a double free error.  Fix this by removing
the extraneous snd_ctl_free_one call.

Issue found using static analysis with CoverityScan, CID 1372908

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 sound/soc/sh/rcar/core.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Kuninori Morimoto Dec. 9, 2016, 12:04 a.m. UTC | #1
Hi Colin

> From: Colin Ian King <colin.king@canonical.com>
> 
> On an error, snd_ctl_add already free's kctrl, so calling snd_ctl_free_one
> to free it again leads to a double free error.  Fix this by removing
> the extraneous snd_ctl_free_one call.
> 
> Issue found using static analysis with CoverityScan, CID 1372908
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---

Indeed...
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

If my memory was correct, this code was copied from somewhere...

BTW, in my opinion, function parameter automatically freed in "add" function
is a little bit strange behavior for me...

>  sound/soc/sh/rcar/core.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
> index 4bd68de..99b5b08 100644
> --- a/sound/soc/sh/rcar/core.c
> +++ b/sound/soc/sh/rcar/core.c
> @@ -1030,10 +1030,8 @@ static int __rsnd_kctrl_new(struct rsnd_mod *mod,
>  		return -ENOMEM;
>  
>  	ret = snd_ctl_add(card, kctrl);
> -	if (ret < 0) {
> -		snd_ctl_free_one(kctrl);
> +	if (ret < 0)
>  		return ret;
> -	}
>  
>  	cfg->update = update;
>  	cfg->card = card;
> -- 
> 2.10.2
>
diff mbox

Patch

diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index 4bd68de..99b5b08 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -1030,10 +1030,8 @@  static int __rsnd_kctrl_new(struct rsnd_mod *mod,
 		return -ENOMEM;
 
 	ret = snd_ctl_add(card, kctrl);
-	if (ret < 0) {
-		snd_ctl_free_one(kctrl);
+	if (ret < 0)
 		return ret;
-	}
 
 	cfg->update = update;
 	cfg->card = card;