From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (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 55BD313D8BA for ; Fri, 17 May 2024 17:10:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.211.166.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715965851; cv=none; b=E+CCvexN5c2qwLoYdnOOJzG/DOf3qiuccfI2KCkwzEuxBzNWfjdgCmrRaUt6DJwGSS3KNq53+FyMEHLU8h9HgkyjtB5iKH96Tn6gMaWLTniWx1fYomnmF6GpIlzHgDG4P4xv5XL6UJVz3BjVEbzR77XEobahkIEAe1u9jaTY+ww= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715965851; c=relaxed/simple; bh=OkDC481zFr3zxzpw+em2PUv7vlhq7LknWjI47ro8VnY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=dWgm4OYhysTunRrWfRLa7RZl9ntXKJOlhinBS0igMnpiU0LBfegeEnWGFq/NH/QB1CjDt62y3NnftNmHqG9yg6/d152eDx57TBVZBS0prEXhwlij0VMUWLjSZcic/mwS8sZmOMQxiyxCPZfRDNaMzkmHmHjNfSiUEi0yzHtVMFI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nFoV8i/k; arc=none smtp.client-ip=140.211.166.136 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nFoV8i/k" Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id D7BDA6067D for ; Fri, 17 May 2024 17:10:49 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org X-Spam-Flag: NO X-Spam-Score: -2.099 X-Spam-Level: Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id yEsZVYV8QR-b for ; Fri, 17 May 2024 17:10:49 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2607:f8b0:4864:20::633; helo=mail-pl1-x633.google.com; envelope-from=yskelg@gmail.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 2F3C36067A Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 2F3C36067A Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=nFoV8i/k Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by smtp3.osuosl.org (Postfix) with ESMTPS id 2F3C36067A for ; Fri, 17 May 2024 17:10:49 +0000 (UTC) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1ed012c1afbso6925075ad.1 for ; Fri, 17 May 2024 10:10:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715965848; x=1716570648; darn=lists.linuxfoundation.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=nFoV8i/k9xNRQZ0akNyQ82KC4wGfuoauLXD+ey0x/Zkb/NL6/OrqbbDAA6W34Phw02 yK475gauQ1R07XNN7lDo1IAMKLWD5gfwrbHNJeUzqfK7WFcFDWzHpCAsgHcPueLq/17o ZtnYAa96YRINEz+DW2HVdhg7/AKcNixe56pxt74Xhaij23WQpQosuk73qx1/ESEQCkL4 QmjDj2YfSZOiYWblKNWtoZt2VDQuunIETrt8UAEKVbHUjt5dcpISNt0r7brRKfqCLENc BDB4v6T7SlKwhJd859nGmiZhyWP5T83mUZRsCEziPf3MKWQRv7oDvEIwORsOFjwM2b8M Tafw== 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=Xsbq76xF0RqBqVkAQnrtyF0Ului4j1AgfFzVQ9OvIQt9bR2sgDdL/1g5m8VNB7B23Q ZwX2GdqoFpe58B+LhBvBmxaJPfdjza/JMOPeBOOdbuayGUNVw2GTUsP56iXPbn/ZvBjP pEePz6Z7mib0IEFS3RKo1yndxGItzKlgFiMAXxNZaQGegcRC2WEessj17N6ntE56af1t UxDUNgu6yhbdcl3MphtKvTXL8cityGYhGT7eB6PLxjcqavp69jdZ64dFuLNQGMT90WpD AA5BomM9mq2i4HnIdkMQds/r6zbQdIbVRpq2zl0xU+Te0qOyrF2FkIVbUWJmN/KfV5+I p1Sg== X-Forwarded-Encrypted: i=1; AJvYcCXt+0KFqeMu/cflCY/YBLFCmOIQ0QNjF2IWJXIoNQ7BJroPqqYG6Aqtb0xYiWcqmzWV9t3Ls0TYIyuDW6VCl22+tunLr2kcZCHgM1mIB8ZWOD0NnntkYcbaUfUCQ/0l X-Gm-Message-State: AOJu0YxS3OHDMYbZ8J1nbPlZB6y/d0gzr+o5J6Syk72Tq7skb3SG6931 ek1Qz+mA75gHMtPh67QoI/xWC9K9UpPuwiytG0GlKZvJAWygW/V9 X-Google-Smtp-Source: AGHT+IHf7EzDobBuG28rhBGM/jrbz7z2TmfK7/0FLrxUx9ilsRJHlu782DHm4IF+5lQiJWvjS7MVjA== 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-mentees@lists.linux.dev 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 >>