Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp157940pxv; Thu, 15 Jul 2021 01:06:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9NAbG0eK2icdoRt9b2wsAZoxBK5RfCzmkb65GoZFBS7L6f1ek0RQAHsSwI6IJ2TQkRxk3 X-Received: by 2002:a17:907:990f:: with SMTP id ka15mr4133371ejc.132.1626336395475; Thu, 15 Jul 2021 01:06:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626336395; cv=none; d=google.com; s=arc-20160816; b=XqLTzAyDvuIL+pGMZbeMWoe4qbI7EsPwHJruMLbTp7M6pqtTPiJE0abpvEFtcPkLD8 q3TX8PhwWsOdOfgpUoMtRs26InGw4YYbIyCrNidKO3stbXpK8sP48K53/VsYdDGQtgzz 3jpKaiUIBgQ6Q9q+S2UgjMXQa9N5Ubzejnks/yr/n6jvzmTrgey1aBx92YCD0QExlVbC FGPGrKXtBvl4s7m6crkfl86zXY8nz/7q3JqAM6kpGjv330HnmQVqKfNoBqTVNA9QPczD tImebk0c5a+VAjD8o5siMiofyL0DtsnrkU64Ds+7wETxEkIumNY3PKQoDeX3/yNYhMWX fjDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=KMVcV71TI/LuoLV2GP9IW9DEEyibgxgYmwaXh7NXv/I=; b=G3epb9S63YAKfsI4qFRGJsMQGh+j9eQrjr338WOF2DVdh3EgrBzxKHjFBSChNYps/8 t0WJlYelkRBSxXS3ed/suUDK6X6LJ/lBBrvirvFnWVnDIN5FQfFSb8HmJB/KJw+9P8lP wYxAYE0QwJFAIi8q2Vlqi7pIZY6YeljxLngvtgabVOCaxIUHDu2YR4lVnr3OEZCu5H9c gAcf6o1QAFEOUZf9yKvFspEbutNGl/5Q60WRyK4UzygcWPnIJMaRzOsj499+/cJsunOF gCrTu1wAugg2qrW9czyirGXXwniuvSLuMGzGiK/L69EPbE7g703mKsLHnyGxDny3TTL5 4ukA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=aI0H5jmr; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s2si6052752edd.65.2021.07.15.01.06.12; Thu, 15 Jul 2021 01:06:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=aI0H5jmr; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236414AbhGOGvi (ORCPT + 99 others); Thu, 15 Jul 2021 02:51:38 -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 >