lkml.org 
[lkml]   [2011]   [Jul]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Sound: AudioScience HPI: Don't leak firmware if mem alloc fails
At Thu, 28 Jul 2011 21:48:27 +0200 (CEST),
Jesper Juhl wrote:
>
> We leak the memory allocated to 'firmware' when we fail to
> release_firmware() after a kmalloc() failure in hpi_dsp_code_open().
> This patch should take care of the leak.
>
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
> sound/pci/asihpi/hpidspcd.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> Build tested only.
>
> diff --git a/sound/pci/asihpi/hpidspcd.c b/sound/pci/asihpi/hpidspcd.c
> index 3a7afa3..8d261ef 100644
> --- a/sound/pci/asihpi/hpidspcd.c
> +++ b/sound/pci/asihpi/hpidspcd.c
> @@ -85,8 +85,10 @@ short hpi_dsp_code_open(u32 adapter, void *os_data, struct dsp_code *dsp_code,
>
> HPI_DEBUG_LOG(DEBUG, "dsp code %s opened\n", fw_name);
> dsp_code->pvt = kmalloc(sizeof(*dsp_code->pvt), GFP_KERNEL);
> - if (!dsp_code->pvt)
> + if (!dsp_code->pvt) {
> + release_firmware(firmware);
> return HPI_ERROR_MEMORY_ALLOC;
> + }

IMO, it's better to use the same error handling like others, i.e.
"goto error2". But you want to pass a different error code, so we'd
need to introduce an error code variable there...


Takashi


\
 
 \ /
  Last update: 2011-07-29 07:39    [W:0.045 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site