From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15A8EC07E96 for ; Thu, 15 Jul 2021 06:48:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBFBB61362 for ; Thu, 15 Jul 2021 06:48:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237053AbhGOGvj (ORCPT ); Thu, 15 Jul 2021 02:51:39 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:42992 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236519AbhGOGvi (ORCPT ); Thu, 15 Jul 2021 02:51:38 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id B10FC1FDE2; Thu, 15 Jul 2021 06:48:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626331724; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KMVcV71TI/LuoLV2GP9IW9DEEyibgxgYmwaXh7NXv/I=; b=aI0H5jmrPeIdEFTHGuxWTQxaNoI0gdjyN3G0wKfJMP4+t3ehnQe94aS95yBNRYc84ZqSGD jjgAFU4CrjD6kI1cnQowjppCEAe8kzxiZpaWPuepAlMncGAA2chHSeXbrSPwwMkYoCNtaP aN7Tq3TqC9Mf3bg3+D/SIlg6+fSRHIg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626331724; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KMVcV71TI/LuoLV2GP9IW9DEEyibgxgYmwaXh7NXv/I=; b=pTAxrY3c/ZDLqg/BYAThxWrea5cF0ElXBugfjuzFjsmZbqTBqHBYzrBe4GWC3uEnheJNJH M0hjLd9bJxOnbMAw== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 99844A3BA4; Thu, 15 Jul 2021 06:48:44 +0000 (UTC) Date: Thu, 15 Jul 2021 08:48:44 +0200 Message-ID: From: Takashi Iwai To: Salah Triki Cc: perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] sound: usb: line6: free allocated urbs on failure In-Reply-To: <20210715005625.GA1997259@pc> References: <20210715005625.GA1997259@pc> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 15 Jul 2021 02:56:25 +0200, Salah Triki wrote: > > Free allocated urbs on failure in order to prevent memory leaks. > > Signed-off-by: Salah Triki This will lead to double-free. The resources are freed in the destructor of PCM component, line6_cleanup_pcm(). Takashi > --- > sound/usb/line6/capture.c | 22 ++++++++++++++++++---- > 1 file changed, 18 insertions(+), 4 deletions(-) > > diff --git a/sound/usb/line6/capture.c b/sound/usb/line6/capture.c > index 970c9bdce0b2..345b75ede5d5 100644 > --- a/sound/usb/line6/capture.c > +++ b/sound/usb/line6/capture.c > @@ -258,6 +258,7 @@ int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm) > { > struct usb_line6 *line6 = line6pcm->line6; > int i; > + int ret; > > line6pcm->in.urbs = kcalloc(line6->iso_buffers, sizeof(struct urb *), > GFP_KERNEL); > @@ -272,8 +273,10 @@ int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm) > urb = line6pcm->in.urbs[i] = > usb_alloc_urb(LINE6_ISO_PACKETS, GFP_KERNEL); > > - if (urb == NULL) > - return -ENOMEM; > + if (urb == NULL) { > + ret = -ENOMEM; > + goto enomem; > + } > > urb->dev = line6->usbdev; > urb->pipe = > @@ -286,9 +289,20 @@ int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm) > urb->interval = LINE6_ISO_INTERVAL; > urb->error_count = 0; > urb->complete = audio_in_callback; > - if (usb_urb_ep_type_check(urb)) > - return -EINVAL; > + if (usb_urb_ep_type_check(urb)) { > + ret = -EINVAL; > + goto einval; > + } > } > > return 0; > + > +enomem: > + i--; > + > +einval: > + while (i >= 0) > + usb_free_urb(line6pcm->in.urbs[i--]); > + > + return ret; > } > -- > 2.25.1 >