From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754214Ab1G2Fgy (ORCPT ); Fri, 29 Jul 2011 01:36:54 -0400 Received: from cantor2.suse.de ([195.135.220.15]:45235 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751486Ab1G2Fgx (ORCPT ); Fri, 29 Jul 2011 01:36:53 -0400 Date: Fri, 29 Jul 2011 07:36:50 +0200 Message-ID: From: Takashi Iwai To: Jesper Juhl Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Joe Perches , Eliot Blennerhassett , Jaroslav Kysela , support@audioscience.com Subject: Re: [PATCH] Sound: AudioScience HPI: Don't leak firmware if mem alloc fails In-Reply-To: References: User-Agent: Wanderlust/2.15.6 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.7 Emacs/23.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: [PATCH] Sound: AudioScience HPI: Don't leak firmware if mem alloc fails Date: Fri, 29 Jul 2011 07:36:50 +0200 Message-ID: References: Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id C5C2C24499 for ; Fri, 29 Jul 2011 07:36:52 +0200 (CEST) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Jesper Juhl Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Eliot Blennerhassett , Joe Perches , support@audioscience.com List-Id: alsa-devel@alsa-project.org 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 > --- > 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