Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1359134lqo; Fri, 17 May 2024 23:00:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVOAuJU/Ql/v9V8iBiMfzAA6yJoMalnyM9Bgjt1KY5jaFknAzsqqa3ybLg5S5gybZNnf2a5ELam7L+HoFsS0dgcSESNgerKSliOzSCLcQ== X-Google-Smtp-Source: AGHT+IEdIZ1kc6nEpyJ9j5i/KNe/yWG+zE0ldSkTCyDzyEUVBGYt4NwW6/4jpvd1Ukilz1fWCQ9T X-Received: by 2002:a05:6214:2f0b:b0:6a0:d290:693b with SMTP id 6a1803df08f44-6a168235d5dmr291555866d6.50.1716012055037; Fri, 17 May 2024 23:00:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716012055; cv=pass; d=google.com; s=arc-20160816; b=vRkOsoU0/3HVz8hRjw0iKEdOeVm+aBrOQn5afR7cEWeDjW+qipqb+01cK9EvwhbPfQ jrhxjzG/drduRk1ITI8dab7iZwrKn0Y4QjA5vCrU6ILhJD9D2GZZbHiUUGbIt81cyW2N C6x+1amPzUjd5MJtdszfOpTSfdH++IiZcb+KxXVsnWTKk6Zk733b/uZ+pdB7gkgW53rr 3gvwNYAu1dciabCsPi0IkKpYvzO/49BWnO9W4zPWxa/lMlVZH1BYMkSwTMj021o6Ki1A rZehBvojGutbRRBx65kXkkyxD7eGcHybImDd/OtalY6dsuM/uLlXTvJnkuRxCwzgd925 2DUQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=S2UEI9fgxAaUwQb09cLy2ONzt7BSkEaSUgAIAN/09lw=; fh=3cPt4GKr0WCKR/Z5OkBW2xTX2VxEwq3c2c+CFzQ8Pm4=; b=H6kDOyOAYQDgSXVZdqZZXL9FM9B6Pt1P1llZyQw4bxrk+9cuX3ffFIjJgtPNqdk8JE DeV1PkgXLs9tDWAo6ngpeAkek6KL6IEWfqNsYY/9JcZlB8/oNoW4plbOdH7f5SnNg8wb IOr5wjQBWx7u7p0DnoXo89yBw+3tICDznCWT2qh9rKTCsIMyAgUavgn3ogjTXzFReHg1 JpmKEKk2RHa/ffbUC0I36M27sS7k2djRGJ2paruReCgIBSMWaDyQ/jKhegIrARoeQ3l4 PwgGKJ2H/ycvq2g4nhOP2FE/wpFCcFqjMeTnUVmtPQlGp4QX1NMUeDly2YLozYpjt+J8 mpiw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DgiT0S2y; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-182780-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182780-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f29bff3si61563576d6.194.2024.05.17.23.00.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 23:00:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182780-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DgiT0S2y; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-182780-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182780-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B032B1C2147B for ; Sat, 18 May 2024 06:00:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0327B661; Sat, 18 May 2024 06:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DgiT0S2y" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B1005228; Sat, 18 May 2024 06:00:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716012046; cv=none; b=iIg2boWPnmcGZkjzLcRVRYhZ0US/yHAwCz3vteM8S6khNlEtmsqewR1PAC/K96mtD6N5uEzdkhtSpl79uFmVPTseQoyxGSbi645FhIeyFH5VB2vwQ404qXK7w8wNEYMZt6KOqpCN9xqHl54mL+ARwxu1b6sd+6H6KlPy47rEdk4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716012046; c=relaxed/simple; bh=iPVwY+FLQJN/2C/In5skBXJrWKGZ7CLLiR6TcZqpUcs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MMJWliqVHjXqkrDWwOFGGMXJzMB06FfXKZCP7vPC09shYJaEcISo52YgJ+WBU71qUKNeMLScdTwqSyfrFBwxebY+JAQND+Z3G5bcROiSSN5eRLigwVzTy5ajUUr4J2zMwU+4GEj/lXKZgqMSUKCeNeLF9jVkQor+BqyQFxNA0CM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DgiT0S2y; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1e3c3aa8938so28730445ad.1; Fri, 17 May 2024 23:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716012045; x=1716616845; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=S2UEI9fgxAaUwQb09cLy2ONzt7BSkEaSUgAIAN/09lw=; b=DgiT0S2yccUDXBXB+LDR5k3KJH1lc7g9AeABGFcuzYSjeIDhzEIWAvQE/h2NOGNzKc Mh/W88ioNbRaD26ei/z53xSdMsMBekyc0N3DXSmd9GySlHsFZDOq1rwSVhPM8Pkonppa GB/2PsO11f1ssmLNBd3mJ+zIh+RMQHfb3fUbeUp5tAg3PsQgJP4aZpXypyb0eSnlA6d5 mFk8SoyMGTfPSecjPVGu4fkJeSQJhT2qSRNMwhfbnURlRurXH1h8DTAnFYZYu5rhoj7s GC3PADa5nvYIuJHVh8Xqkmo4QW+G2H5H0AD1tPiUBDeQWPNLBY/pUhn+AzcAG8IxxqDL Po5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716012045; x=1716616845; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S2UEI9fgxAaUwQb09cLy2ONzt7BSkEaSUgAIAN/09lw=; b=B60vTpR13SJjmirLoo1IB0JKoEjorI3coIWFZC7PCYjfMwEvopgTPJvcNXPgDXMq94 ike0HcNmFAtuyZ+SDpqiLi0MfDvpn3YzPobGkjpL7ZEaCG86fqCASnWHQPl9RoYZKirN S9ZFX42r4Mn1b9A6iYNYSfyrvWrZZI6WAUch2wR8DwOF7kkr16oZTy3IfSGb8de0DZWs MpRhR9SbQRxAerDw9+vcJBFnkIRcB8LYTMWO7aVwd4PiwHQpTR15QHuuVpZWJovKfYWO CL9niB2eO/6zak6X9eRpA6+wnxV/s4U/sE23BOWfJ4vAAA7zk5Cj1Cy0WJaga41h6U5s W6/g== X-Forwarded-Encrypted: i=1; AJvYcCWePG8ZmdzEXLJ+PNC13WwWCS9xGFWwnouSrIR9lCunQzhf4ms0c9fidrlHkrrEkEvB/WhZp5duxyXTXYWMjFgxkRl6tJPgzl7ugtSdAdgeQb5pw+Ukn8LVGaC2TeaMxmnsGDb9D2rROQY= X-Gm-Message-State: AOJu0YzI9Lrhtwi7meT5tcdVM7DNXOiBFJxUfocRPBH4/72zAoO0CgVQ ywt/+XXRUVhQVNty8ScdrhIOZjbpYhjm+ikQTHTU9F6/DVDEe16u X-Received: by 2002:a17:903:24d:b0:1de:f91:3cf3 with SMTP id d9443c01a7336-1ef43f4d284mr244213975ad.55.1716012044866; Fri, 17 May 2024 23:00:44 -0700 (PDT) Received: from [192.168.50.95] ([118.32.98.101]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c136838sm167030095ad.232.2024.05.17.23.00.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 May 2024 23:00:44 -0700 (PDT) Message-ID: Date: Sat, 18 May 2024 15:00:41 +0900 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] line6: add midibuf init failure handling in line6_init_midi() To: Takashi Iwai Cc: Jaroslav Kysela , skhan@linuxfoundation.org, Bjorn Helgaas , linux-kernel-mentees@lists.linuxfoundation.org, Austin Kim , shjy180909@gmail.com, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240516174737.415912-1-yskelg@gmail.com> <8734qg260i.wl-tiwai@suse.de> <871q608gz7.wl-tiwai@suse.de> Content-Language: en-US From: Yunseong Kim In-Reply-To: <871q608gz7.wl-tiwai@suse.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 5/18/24 2:51 오전, Takashi Iwai wrote: > On Fri, 17 May 2024 19:10:44 +0200, > Yunseong Kim wrote: >> >> On 5/17/24 5:32 오후, Takashi Iwai wrote: >>> 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. >>> >>> >>> thanks, >>> >>> Takashi >> >> Thanks for the review Takashi. >> >> I have one question: >> >> line6_midibuf_destroy() have no NULL check for the memory to free. >> >> If line6midi->midibuf_in is in this->buf = NULL from >> line6_midibuf_init() with memory allocation failed, >> won't the free(NULL) when accessed by snd_line6_midi_free() to >> line6_midibuf_destroy()? > > free(NULL) is fine, it's defined to be noop. > Many codes just call free() unconditionally for that, as it reduces > the code size. > > > thanks, > > Takashi Thak you Takashi, I've been studying the kfree behavior in detail since you mentioned it, so thanks for advicing the details. Warm Regards, Yunseong Kim >> >>>> --- >>>> 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 >>>>