linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vinod Koul <vinod.koul@linux.intel.com>
To: Jesper Juhl <jj@chaosbits.net>
Cc: Takashi Iwai <tiwai@suse.de>,
	linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Jaroslav Kysela <perex@perex.cz>
Subject: Re: [PATCH] sound: Fix memory leak on error in snd_compr_set_params()
Date: Tue, 24 Jan 2012 14:46:14 +0530	[thread overview]
Message-ID: <1327396574.517.33.camel@vkoul-udesk3> (raw)
In-Reply-To: <alpine.LNX.2.00.1201232059540.8772@swampdragon.chaosbits.net>

On Mon, 2012-01-23 at 21:02 +0100, Jesper Juhl wrote:
> If copy_from_user() does not return 0 we'll leak the memory we
> allocated for 'params' when that variable goes out of scope.
> 
> Also a small CodingStyle cleanup: Use braces on both branches of
> if/else when one branch needs it.
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Thanks for the fix
Acked-by: Vinod Koul <vinod.koul@linux.intel.com>
> ---
>  sound/core/compress_offload.c |   13 ++++++++-----
>  1 files changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
> index dac3633..a68aed7 100644
> --- a/sound/core/compress_offload.c
> +++ b/sound/core/compress_offload.c
> @@ -441,19 +441,22 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
>  		params = kmalloc(sizeof(*params), GFP_KERNEL);
>  		if (!params)
>  			return -ENOMEM;
> -		if (copy_from_user(params, (void __user *)arg, sizeof(*params)))
> -			return -EFAULT;
> +		if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
> +			retval = -EFAULT;
> +			goto out;
> +		}
>  		retval = snd_compr_allocate_buffer(stream, params);
>  		if (retval) {
> -			kfree(params);
> -			return -ENOMEM;
> +			retval = -ENOMEM;
> +			goto out;
>  		}
>  		retval = stream->ops->set_params(stream, params);
>  		if (retval)
>  			goto out;
>  		stream->runtime->state = SNDRV_PCM_STATE_SETUP;
> -	} else
> +	} else {
>  		return -EPERM;
> +	}
>  out:
>  	kfree(params);
>  	return retval;
> -- 
> 1.7.8.4
> 
> 


-- 
~Vinod


  reply	other threads:[~2012-01-24  9:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-23 20:02 [PATCH] sound: Fix memory leak on error in snd_compr_set_params() Jesper Juhl
2012-01-24  9:16 ` Vinod Koul [this message]
2012-01-24 14:30 ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1327396574.517.33.camel@vkoul-udesk3 \
    --to=vinod.koul@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=jj@chaosbits.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).