Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp1941084rdb; Tue, 5 Sep 2023 09:21:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwrCdjJ5LvhUXalCPe4kJCsEDB2HYqJoldPw4bXdqzLLG4vKETgsY+O+LpSgH6d4vs+kWY X-Received: by 2002:a17:906:5a70:b0:9a1:c352:b6a5 with SMTP id my48-20020a1709065a7000b009a1c352b6a5mr267377ejc.69.1693930916669; Tue, 05 Sep 2023 09:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693930916; cv=none; d=google.com; s=arc-20160816; b=n74i0yAjFIQjCBS7IQHi21L7QCux+hNRL6cK2ezQ6AXAC/LDo+JP5h0FQuoOBHJmfq 70BXsNcmHu8Ur+WhWdNCxRpmMGAxiF+gvp0vXLP/qS/T1pee6CDlbBsTejOCiZyVjpoG ABT7nJGjw5zUYEllL6IBLDF5ENRC7T5fmu6TcPGcOV+2pf7fa+tURdlCGuAex7u0rHVD NRjZnatr55Cu3reNzJzq5DvVY/j3FL9SJ86FpKILihHmP1z9XcZAT/TUB5T87L5NOIn3 HhXvXYLlEZEaQtzUKwD97EsLoEKekq5ug85Ox8W054+N87of5IIuvxEn8yigtGVAdM6t yTqw== 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=kXC+3FqTHA/mLgbq2RC3Hciy9DRGxqa82vRW3oFylp0=; fh=r2P83izfehVW7t8OL+XbVOFdgo28W8Q6R+TU5BHjzH8=; b=vGNysRuLpZpVbI2uwPMyU8iT78yd2750t5ksfEha8FCehCAvbsYH2vAvYvEMKtWfdD TvbCdxvLO0/F6BqnbB6SOpbKxr3kqYvAuKRxdCwR8WbMnJFDLQpGJP5ffthorvt2tfX0 az/PIv5O4hVbqQSqOiIJuAQ2WcoBCxqvCchDiB3eFPb2TLmwEu3Lp9doFR0eI6AsIQuY 2iKXzqvOL+rPXVU8QPpBBwI+t8CYQABpUFl+NErltWlmzNP3FzPatK5y7riyKdk9qRfe t7yDj/9JUDM7jwo30Ai4IF+rzutUqPn3mRfyAvc+DPfuBf/1eyOErEYyOaFOLlu/Cs1N shPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=L4nm2hkU; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l13-20020a170906a40d00b0099bd627bb9dsi7355197ejz.983.2023.09.05.09.21.51; Tue, 05 Sep 2023 09:21:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=L4nm2hkU; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235449AbjICOYA (ORCPT + 11 others); Sun, 3 Sep 2023 10:24:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbjICOX7 (ORCPT ); Sun, 3 Sep 2023 10:23:59 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28B67FA; Sun, 3 Sep 2023 07:23:56 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CCA1E216DA; Sun, 3 Sep 2023 14:23:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1693751034; 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=kXC+3FqTHA/mLgbq2RC3Hciy9DRGxqa82vRW3oFylp0=; b=L4nm2hkUtYLnahhlzqi7c3QjOLM1gtjpY/Ilb/oP/21ePdfXlHLtBiPJbfMFSmJPQHbL/S X1XNK/1FfTXKXzsdjC3sOkcor6z+3+F05SO/j3Sbc1MUdrBEL/R/ERMG4U12NsTOyN7Ujo cy2ZKODj+oYhmVc2oGMdjKEJtWkJzGM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1693751034; 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=kXC+3FqTHA/mLgbq2RC3Hciy9DRGxqa82vRW3oFylp0=; b=sNgjXc1hkIBDJQXwnhjfFDBR7ihql78Wt1v+14Lq/WKOPUVATyfqNxkU1r/yO2LrwOfG6/ 60PQL6wk2mWtD7Dg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A244E13583; Sun, 3 Sep 2023 14:23:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id dXG0JvqW9GRIcgAAMHmgww (envelope-from ); Sun, 03 Sep 2023 14:23:54 +0000 Date: Sun, 03 Sep 2023 16:23:54 +0200 Message-ID: <871qffmj2d.wl-tiwai@suse.de> From: Takashi Iwai To: Christophe JAILLET Cc: Jaroslav Kysela , Takashi Iwai , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, alsa-devel@alsa-project.org Subject: Re: [PATCH] ALSA: usb-audio: Fix a potential memory leak in scarlett2_init_notify() In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 03 Sep 2023 15:06:00 +0200, Christophe JAILLET wrote: > > If usb_alloc_coherent() or usb_urb_ep_type_check() fail, we should release > the resources previously allocated. Those are freed in the caller side, start_input_streams() instead. thanks, Takashi > > Fixes: ff49d1df79ae ("ALSA: usb-audio: USB MIDI 2.0 UMP support") > Signed-off-by: Christophe JAILLET > --- > sound/usb/midi2.c | 17 ++++++++++++++--- > 1 file changed, 14 insertions(+), 3 deletions(-) > > diff --git a/sound/usb/midi2.c b/sound/usb/midi2.c > index a27e244650c8..4109c82adff6 100644 > --- a/sound/usb/midi2.c > +++ b/sound/usb/midi2.c > @@ -302,7 +302,8 @@ static int alloc_midi_urbs(struct snd_usb_midi2_endpoint *ep) > ctx->urb = usb_alloc_urb(0, GFP_KERNEL); > if (!ctx->urb) { > dev_err(&ep->dev->dev, "URB alloc failed\n"); > - return -ENOMEM; > + err = -ENOMEM; > + goto err_free_all; > } > ctx->ep = ep; > buffer = usb_alloc_coherent(ep->dev, len, GFP_KERNEL, > @@ -310,7 +311,8 @@ static int alloc_midi_urbs(struct snd_usb_midi2_endpoint *ep) > if (!buffer) { > dev_err(&ep->dev->dev, > "URB buffer alloc failed (size %d)\n", len); > - return -ENOMEM; > + err = -ENOMEM; > + goto err_free_cur_urb; > } > if (ep->interval) > usb_fill_int_urb(ctx->urb, ep->dev, ep->pipe, > @@ -322,13 +324,22 @@ static int alloc_midi_urbs(struct snd_usb_midi2_endpoint *ep) > if (err < 0) { > dev_err(&ep->dev->dev, "invalid MIDI EP %x\n", > endpoint); > - return err; > + goto err_free_cur_dma; > } > ctx->urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; > ep->num_urbs++; > } > ep->urb_free = ep->urb_free_mask = GENMASK(ep->num_urbs - 1, 0); > return 0; > + > +err_free_cur_dma: > + usb_free_coherent(ep->dev, len, buffer, ctx->urb->transfer_dma); > +err_free_cur_urb: > + usb_free_urb(ctx->urb); > + ctx->urb = NULL; > +err_free_all: > + free_midi_urbs(ep); > + return err; > } > > static struct snd_usb_midi2_endpoint * > -- > 2.34.1 >