Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2010710pxa; Fri, 7 Aug 2020 00:14:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyH5iCi4GsIAU78eL9oU+C2R3hfaZy7rgyKTbPyNdZCPmCoyd67cbmbC3Z1T+jfPD0TeHER X-Received: by 2002:a17:907:42cd:: with SMTP id nz21mr8122338ejb.395.1596784446053; Fri, 07 Aug 2020 00:14:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596784446; cv=none; d=google.com; s=arc-20160816; b=es/huNDq1iP2QqysEUZWHru5QNOwOOKmojR42NKbq0ASgBhTJXKVlU94A+TQpLEsE4 uX4Ze8RUsst4WZQqltXG8ks+mYODEvM/x8ZguqERP6iZEgotfOjxWq07rQ3ms/tBe092 gbDyQARO21BhhC+dUdJOZ1kIJj015L9R767kKmCGlEDfdOuu0VhGKxVDBK+wi9LfOFKf HhdZGYur0hXTadXR4i9i7Cb9uLjNFI7zQGHm8PFOYhhkcy89ssV6pOqXz2efmQa7xDRa 6vPPYL5XQkgsHlWC+pAdnGGUwoP2ByHbSwXG98sfcvmIzleDjoS1CDr2C8Qvd678yjY/ 4lGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=18qvxecOOt1L9wtX7xpsFgPRH6g+RzjyMhlNml6fgVY=; b=ljSBU/L2CRN8eCrUebLif6Y3c9B+vOgoBBv9efyitZtA/k4qTdaIWqIy66hb2q/Bn1 F4pUWP7DaiZlnZ+C9+xMWIITBd+yDrYe9ku5j4PSYUADbmGNrRF8a29ofxd/4kH5ro3F 1Oc6MWGohziEyldqHQ15koxgjYta0Qzznu1dQVIQI0IPdg57z46G2RSuf5KPckprXVwk Pbf1KptbL9b9SZWHHis5TmYcb+eF78I8bBeDxFzKa9SNxFG/loIpaiDN0Rmh763yL4GB DEtor5feYHd1Nauqjh7p2qrtkPotNxnfMwnf/wS1jqStO267aQWZtSDzHI7C3/0naA73 /zpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z7si4559104eja.692.2020.08.07.00.13.42; Fri, 07 Aug 2020 00:14:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726249AbgHGHNK (ORCPT + 99 others); Fri, 7 Aug 2020 03:13:10 -0400 Received: from spam.zju.edu.cn ([61.164.42.155]:40290 "EHLO zju.edu.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725805AbgHGHNK (ORCPT ); Fri, 7 Aug 2020 03:13:10 -0400 Received: from localhost.localdomain (unknown [210.32.144.186]) by mail-app4 (Coremail) with SMTP id cS_KCgBXznnl_ixfYKOuAA--.36381S4; Fri, 07 Aug 2020 15:12:41 +0800 (CST) From: Dinghao Liu To: dinghao.liu@zju.edu.cn, kjlu@umn.edu Cc: Jaroslav Kysela , Takashi Iwai , "Geoffrey D. Bennett" , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH] ALSA: usb-audio: Fix memleak in scarlett2_add_new_ctl Date: Fri, 7 Aug 2020 15:12:27 +0800 Message-Id: <20200807071229.9533-1-dinghao.liu@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: cS_KCgBXznnl_ixfYKOuAA--.36381S4 X-Coremail-Antispam: 1UD129KBjvdXoW7GrWUXr43WrW8ZFW7Xr18Zrb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ner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When snd_usb_mixer_add_control() fails, elem needs to be freed just like when snd_ctl_new1() fails. However, current code is returning directly and ends up leaking memory. Fixes: 9e4d5c1be21f0 ("ALSA: usb-audio: Scarlett Gen 2 mixer interface") Signed-off-by: Dinghao Liu --- sound/usb/mixer_scarlett_gen2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c index 74c00c905d24..4b2da0866cdc 100644 --- a/sound/usb/mixer_scarlett_gen2.c +++ b/sound/usb/mixer_scarlett_gen2.c @@ -964,8 +964,10 @@ static int scarlett2_add_new_ctl(struct usb_mixer_interface *mixer, strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); err = snd_usb_mixer_add_control(&elem->head, kctl); - if (err < 0) + if (err < 0) { + kfree(elem); return err; + } if (kctl_return) *kctl_return = kctl; -- 2.17.1