Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1086487lqo; Fri, 17 May 2024 10:10:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU5kqFPtDPkX8yzPLaARRmTxsPAlMOKPEOrg+XSZqktYu5pcCTrZ9bYvctKaUlsHCby6rDh/sLp8BPeXra5HR5u55vgaqaok5z4d+PtEA== X-Google-Smtp-Source: AGHT+IHe6eDvBBeSd8HJGt8Klnby+xoH6I7lYORrEu9DOyvQrCeInaCGngUDhKHteca2kvkKrpN6 X-Received: by 2002:a17:906:4f8d:b0:a59:beb2:62cc with SMTP id a640c23a62f3a-a5a2d6668b0mr1258692866b.61.1715965858518; Fri, 17 May 2024 10:10:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715965858; cv=pass; d=google.com; s=arc-20160816; b=B1C8rVCfjnxA6Mc2+2spupeLGHlXm9k70bbPeveNmSF1/PR39MeMc/Rre9CuKoaOkb lPiujTG2bg532FK1tw9Uxm4lgdOFDSc5LQ+jf6MtMlpRDgcQNGaQ9dyxqsIpNz68yNlU 9I/wjTAlfkdYa8JbGbxa2oNI+8nWrcVkkiK9oMCywmwkeSAZYqnOXXywlGrl25poJHsH H6lGx9k+uli34OTeA/AhyxsENeuSa8SNcxbSVsfeLJBOwY5lOBo8IbMlTMCQGLoqKxMz QdoGDY61BFxr3uYvx4CKid1ytImKG7wqvH8S2cg4BvR6a4QAbXl+Vzy2TtSwwJ0EpXhf OBig== 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=dDj4uFMrmhKzYSh39UgL2iN+N33zW/zRmcdvFGlj4ic=; fh=vhbG3+hjJjiCxgaz9nGhtWXTFADa5gzebY/tNWJn/eo=; b=izVeYslezAMtBthk4LMnGHYmcmy2DyzJ8xV9jqZIZta/lZyknFUQZzxvO4QSJA/vkf zAjbejzX8mDXmbwxB4ZtsBq3yYypinvPe65NMMTMyLm0O0JUIprKSPnF/5onD12jRQRG SEllre+WIu9leJcTXq43OG3mRUzTZE44K3hjlDqa9EFxcxWElQSKP2FcHQeVUu/a+X20 OSuZ1dw8jdY6WoFwkwjrda4+OGEl24xzlngJMWaYwFP/8DdyQ/G4x3nn3uFpQZ9oVa0c 5P2pTkmJ4wylRGEhqkgBApELlU6MDKzCitTYSQ79U7uMdqr2kkipq2JX6Tblw38hy3Mj nemw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KrFkxNyy; 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-182380-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182380-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5cdc77c8a9si258946566b.337.2024.05.17.10.10.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 10:10:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182380-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KrFkxNyy; 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-182380-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182380-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 427C01F244F7 for ; Fri, 17 May 2024 17:10:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F7BD13DB98; Fri, 17 May 2024 17:10:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KrFkxNyy" Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 26D8C13D8B8; Fri, 17 May 2024 17:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715965850; cv=none; b=LWWqpZwCuHDmYE/3xS3Dcsq22ybF4th4nY9q95DPCJL7C1Pct95ugIC6TiLC06HtBSWqcorxGe/G8ndXCx/DzcYiOqpcvNw3cAuGQFpuzXJvsbJwtD3G6HqSAmdvqkKKQlUGw8eg0yMDOot47PUqO4weWejMIySKBke8iUqCQLs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715965850; c=relaxed/simple; bh=OkDC481zFr3zxzpw+em2PUv7vlhq7LknWjI47ro8VnY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=TiFSQMezRvpFE+utRVF9juOFVaRYNnUwga25Qe75vML4hBYOdQIv5KOV9zKpljTN8dGcvkCcVC0IN/6OuBZLRy1fBX48W/LXlpJo5DTTsIVP/g8GjPwvb87XAgV5oj+r27QBIjrbkMmFNjsxTJjJAZbL47XEZ/rJp/UwJN2JEJM= 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=KrFkxNyy; arc=none smtp.client-ip=209.85.215.169 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-pg1-f169.google.com with SMTP id 41be03b00d2f7-60585faa69fso1054595a12.1; Fri, 17 May 2024 10:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715965848; x=1716570648; 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=dDj4uFMrmhKzYSh39UgL2iN+N33zW/zRmcdvFGlj4ic=; b=KrFkxNyyqA8x0RzMZ2kttotWxG9c8Yo72oiDbriBsqo3FgfuWjjRXrNc7iJgNKJY7x hmy7JXNsgM21JRUNabRSK5qXkiAmgzZa7kW3gXD7Kr16+BrZmJz+Erlr0V/cNab4zgP2 nwaRqxEdnY8pTxcY3U0EdJvqZas5i0fSpYjzlogKFjMtpk2Puoxe9nolvEkYXCV6rkjF rvG0TCztyLivDB4twQydSFVf3pxvBkgwc2U0N3RZVcM+qtculf+0h/OkwhYGbtT65v1e 4m2FSsmu9QgIlelcODnBUzXkalOq6QMBDqPjvLcoh35gjb5w+CxDlWFCU1h3XLjYn8uk E56w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715965848; x=1716570648; 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=dDj4uFMrmhKzYSh39UgL2iN+N33zW/zRmcdvFGlj4ic=; b=S755/ZTNKiD2uRtqsIi5qIdPE6d7JEPAFQ11w8157FtZGRZLyRGJClBaWgeiZAz3MF 47b+LKrtR7r0sekKYEbObf+EpknIOM4tjHqlmjGI02xcAYoooTH/ijeMNi2K4x7CJ9Fh ek+mcU6VNyapjtN45IM9EM7xzIdazznS9gQfqpm7GmT+niFB4NbmLBxQ42RFafoxRW6D i9znte8tA5J7lI30zRrVBZg2cRJGpRuOmLIEEF921r7/bb0UMBlGZNe1MzNgsvVVFA2q OwQJCm3ZqKo0yOddqS2Y17HMNApADqVTJZX9vvoLW3kVHenjy/68v0Cqc/7wB+v/25aZ KtHA== X-Forwarded-Encrypted: i=1; AJvYcCVnSaIpj4/dP6FGC4sUz6UQXsljsY2oSWyAkEiosONe/YoWkmxWHpodMxVeeIVN8Jlp5Kt3PVtTqtqB1bNNbnXdDjrNZ3j6byaKNPruVSHUrfmjRKG5qtifXiO6lbmhhf0TvVr1pWHSMXA= X-Gm-Message-State: AOJu0Yw5ozNlUJuL83Idqd63a8yc1TUKUZ35CDgEiR0FY/6CB123J2Cz MYR52wvy50gDS6EGvNDfWJSaCLwmdNM3VU5ayVOVeNdOpdNhNeuO0hP101eY1R0= X-Received: by 2002:a17:902:d4d0:b0:1ea:691b:3692 with SMTP id d9443c01a7336-1eefa139e6fmr376856575ad.17.1715965848337; Fri, 17 May 2024 10:10:48 -0700 (PDT) Received: from [192.168.50.95] ([118.32.98.101]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0bf31000sm159213325ad.145.2024.05.17.10.10.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 May 2024 10:10:47 -0700 (PDT) Message-ID: Date: Sat, 18 May 2024 02:10:44 +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> Content-Language: en-US From: Yunseong Kim In-Reply-To: <8734qg260i.wl-tiwai@suse.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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()? In the first patch, I was making a misunderstanding Now that you mention it, I can see where it's freeing! It helped me a lot in analyzing the driver code. Please let me know if I've misunderstood anything. 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 >>