Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1112695lqo; Fri, 17 May 2024 11:01:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWNjmGch/HL7VTJspOCEukIc7dyubhyUZC1JeyXtazKzqGS7vnF8jSTofsviOiiYfiLscplRilacuYWpZy8N24waIAZV5+ixkXImpsPYA== X-Google-Smtp-Source: AGHT+IEkjnFTZDOWf0pmp+UHtUCof1+RdbtAt9Ztb7pE3J+xTA/iKEmcr+xGTbT/A9fLnF8c15AW X-Received: by 2002:a17:903:41c6:b0:1e5:560d:8519 with SMTP id d9443c01a7336-1ef4255119bmr344468815ad.0.1715968897629; Fri, 17 May 2024 11:01:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715968897; cv=pass; d=google.com; s=arc-20160816; b=EuOMkUq3rt1JVv4NGn0kBci11uUCkPgnelzplP5aouPXOxnIpQWgT7xhNQTtKcciOY eVsX8qARiNQd/SGLEnUwbOF0vag2stdlDU26ti2SGwk/T7yO1iYNM/8mmL493+DI96kG lZeSG1vkGamSpEfGU6b3J4IFdrIsCHuMym+O6vaJze3unCeK7kQewryu9pQJ0qb9CR55 54YxDiXvb8d440dZ6OVPMk6cgDFJXYIcymBiv4utET/QAlaUBVD5MhgYaUmTRcHvrX0e 8yfY+r5YLQywJDH7ZEHNoNiVnv3HeEOn49zStqv1OZR3LmOuIBIZYGidEm5Ugj+kmS3O HyHw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:subject:cc:to:from :date:dkim-signature; bh=aQwkZnRCsR5uoeEa7OXOkmtJYs3avY7ZWLaVu72vbJQ=; fh=1c1TX/s3kS4BmRsyVeLEFbAl3fcGQKys+iXRdc+1INU=; b=cZBDRdabRGgVgaB0dXh7ONJdeyB9AKPIMHFAinBmxCeD/Fqa5g7UTDA+NXPa6Eu+AB av4u33VO6VB+dW3SRMSO01UBy9uZ3QEnJArYM+0LAMUEVQz0uZK37kWJlzO6meSvgK+b /UYYEI2mMVKET29qIHTz04iQeCT4pkxd0qCTeJvJDUok3WeD6dBm/UoEOaOZMcW+uXPB hlA1JUHOailUkXNfAcukfTCpHj7ZF2mDvsUj3zgnG2w2EAOqcGKEcxEtUV0y6WgeAxKg 97UduIpQOZb+Q7CUaq/EQBiPkaaZVf4Z42ui6xuy4zZQQ+r3ARu2a8VN/VSfu/mONWez JMzw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="azC3BY/A"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-182488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0b9cf211si187738995ad.74.2024.05.17.11.01.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 11:01:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="azC3BY/A"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-182488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9910128198E for ; Fri, 17 May 2024 17:56:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78A731419AD; Fri, 17 May 2024 17:44:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="azC3BY/A" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B5FD13DDCD; Fri, 17 May 2024 17:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715967869; cv=none; b=WCADOXv7sQFxzIImRGbkwb3YfkT+EyGRLl9FeBsHwiSohPTC6kAVxCGUKO6L5zlwJE+PfVDNP9/ZOConlh8YaaadN4Q5jT99jguenMLpFe6y0e4FCg123gLav4OPqVbOusTEQG0UmeP0kBbcGFHV4T80Ut/IMDPPcAHJAoN6ZJM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715967869; c=relaxed/simple; bh=Nm+T58qBk59wXpsTupEzyucDfvFB86ewSPCmThFAah8=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=cmdAFNiTDxKynyzA4mYpvLJOKHWDhXpLwXSJijLJ/Kum5rJKeL0qGDLmCuTEAZMrx57edJsqmaFNkc7+CJoisy/cvFoA8ekt44I5qBRrOtKEg0evZOI4WniKHn5C0YTyHPiackOgsgtLIGhoQ0FBZCOzITfrxaow+t+gRBrtluw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=azC3BY/A; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCFECC2BD10; Fri, 17 May 2024 17:44:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715967869; bh=Nm+T58qBk59wXpsTupEzyucDfvFB86ewSPCmThFAah8=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=azC3BY/ASdaD7ZoBeeOgbrcgSvb3Rv0u7mwIQCIdoWds8KpPU2CuJYW7tjwjBnNcR +fKze3Ck8JVYLPTffyd4qAN3/qN/UKl+O26D8Bd5fXuTwvZCfpxrRnvKaex2VYhPTb F7DAbRTBQmKzD3KOwrFuNbHUHV7/bQDEHiNpV/VKsChMEv3zKHSLDIMzv0AoqTpIus Sfun2vIremc5OU92byD4KTGZeQQmMdq7tkw53207gvxPOq3DfGSKsA9/81p0eUZ6Cn VNsv1U4rs24nhjE/uyEG+ECcSjdu72WfuLrUJzkK/Hgj3HUBOfIiB0ofURNhkLHtyf gnRQKYvetcyNw== Date: Fri, 17 May 2024 12:44:26 -0500 From: Bjorn Helgaas To: Takashi Iwai Cc: yskelg@gmail.com, Jaroslav Kysela , Takashi Iwai , skhan@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, Austin Kim , shjy180909@gmail.com, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] line6: add midibuf init failure handling in line6_init_midi() Message-ID: <20240517174426.GA2285947@bhelgaas> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8734qg260i.wl-tiwai@suse.de> On Fri, May 17, 2024 at 10:32:13AM +0200, Takashi Iwai wrote: > On Thu, 16 May 2024 19:47:38 +0200, > yskelg@gmail.com wrote: > > > > From: Yunseong Kim > > > > This patch fixes potential memory allocation failures in the > > line6_midibuf_init(). If either midibuf_in, midibuf_out allocation > > line6_midibuf_init call failed, the allocated memory for line6midi > > might have been leaked. > > > > This patch introduces an error handling label and uses goto to jump there > > in case of allocation failures. A kfree call is added to release any > > partially allocated memory before returning the error code. > > > > Signed-off-by: Yunseong Kim > > The allocated object is already freed by snd_line6_midi_free() that is > called via rawmidi private_free at its destruction. So your change > would lead to a double-free. I stand corrected, sorry that I missed that! That said, it seems unreasonably hard to verify this path to snd_line6_midi_free(). Sorry for misleading you, Yunseong. > > --- > > sound/usb/line6/midi.c | 9 +++++++-- > > 1 file changed, 7 insertions(+), 2 deletions(-) > > > > diff --git a/sound/usb/line6/midi.c b/sound/usb/line6/midi.c > > index 0838632c788e..abcf58f46673 100644 > > --- a/sound/usb/line6/midi.c > > +++ b/sound/usb/line6/midi.c > > @@ -283,13 +283,18 @@ int line6_init_midi(struct usb_line6 *line6) > > > > err = line6_midibuf_init(&line6midi->midibuf_in, MIDI_BUFFER_SIZE, 0); > > if (err < 0) > > - return err; > > + goto error; > > > > err = line6_midibuf_init(&line6midi->midibuf_out, MIDI_BUFFER_SIZE, 1); > > if (err < 0) > > - return err; > > + goto error; > > > > line6->line6midi = line6midi; > > return 0; > > + > > +error: > > + kfree(line6midi); > > + return err; > > + > > } > > EXPORT_SYMBOL_GPL(line6_init_midi); > > -- > > 2.34.1 > >