Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5101203ybh; Wed, 7 Aug 2019 00:26:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNU1G3MiGiAFMyX//NQsHs5hiF5zJnk6GGveGx9+6WesKYPD4Knoc8QDrA5hlq2KhUn8vB X-Received: by 2002:a63:484d:: with SMTP id x13mr6491147pgk.122.1565162769570; Wed, 07 Aug 2019 00:26:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565162769; cv=none; d=google.com; s=arc-20160816; b=C2wDG2kURu243t6p1Cld2nnCAV1THUUnD6rFnWYgKSiAkQUAg1vakg/lpZsT58XZyj frxtXvlNa+l6tMxc1FT9mj9muhYqzgT3gyxmy35iyQk+v/2dATHw5zP5MXTN67OJcy+7 X9K1nQH5TK+v14A8fdWzvjU0qC7S5YZFji1OLklHjhYDJi5Xp+r7fHdiO98G09OFT9Us mH14D8One+kDKQssCnfIyAJRDQY5JGIrFPOAJMuJDoUH9RtzJkgv5aHHyEjUsgsG5Nph CC+LUe+9Bs0S4cQ7uNVpBXZBztQaCkZhSVZLMTzAiOl+roojhP6Zf9D3L3RtAsfeq9FW QGsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=T94CjEOZ+ppEZD64E+btCqgLpEQXqeBgzSRpDf/TuAw=; b=JNb7GMReSR6/B0KAwfYBwR3B/C6N2zo87OszC1ZFHgdx8+G9zm1mPQYf3cOs7mFJnG Qq4wxfZn8KOBKxIDTQJWIfPBozEPMCckeuVCvzTMJfQcAOVuc1EIIEiFJO4Fno2gkXIO +lkt+fU1woW3o9dGrP8crXnZULxd1Qop3y6aXxVgDYG6vP1ir4Me+7tYGNUSTJ7HFktC 2VuY6xta1VTNFwhCsAL6Npt0fYH+9vIMyBurw+xFt37lxPJV1w2+UAE+WJU+yhDnGE/M jtmGi7li9NVI6cItdK/JJSL1SKdvbYqC5oSN9aSo+Opju28+UWgJiAl2kjgh5FqrVCrm 88Tg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h127si47834117pfe.44.2019.08.07.00.25.53; Wed, 07 Aug 2019 00:26:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727967AbfHGHYs (ORCPT + 99 others); Wed, 7 Aug 2019 03:24:48 -0400 Received: from ajax.cs.uga.edu ([128.192.4.6]:45480 "EHLO ajax.cs.uga.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727603AbfHGHYs (ORCPT ); Wed, 7 Aug 2019 03:24:48 -0400 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (authenticated bits=0) by ajax.cs.uga.edu (8.14.4/8.14.4) with ESMTP id x777OjeM061253 (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 7 Aug 2019 03:24:46 -0400 Received: by mail-lj1-f177.google.com with SMTP id p17so84514406ljg.1 for ; Wed, 07 Aug 2019 00:24:46 -0700 (PDT) X-Gm-Message-State: APjAAAVrxdTJLwEk/u2oDEQhAYPrFk1cLOrpvBY2j9hLEVoOlZk6OC/1 Og+v2Mhh/6r1qB8hYlh5IGXALKtrecldZkHha98= X-Received: by 2002:a2e:8999:: with SMTP id c25mr3962559lji.169.1565162685345; Wed, 07 Aug 2019 00:24:45 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Wenwen Wang Date: Wed, 7 Aug 2019 03:24:08 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] ALSA: pcm: fix multiple memory leak bugs To: Takashi Iwai Cc: "moderated list:SOUND" , Thomas Gleixner , Greg Kroah-Hartman , Allison Randal , Jaroslav Kysela , Takashi Iwai , open list , Wenwen Wang Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 7, 2019 at 3:18 AM Takashi Iwai wrote: > > On Wed, 07 Aug 2019 09:09:59 +0200, > Wenwen Wang wrote: > > > > In hiface_pcm_init(), 'rt' is firstly allocated through kzalloc(). Later > > on, hiface_pcm_init_urb() is invoked to initialize 'rt->out_urbs[i]'. In > > hiface_pcm_init_urb(), 'rt->out_urbs[i].buffer' is allocated through > > kzalloc(). However, if hiface_pcm_init_urb() fails, both 'rt' and > > 'rt->out_urbs[i].buffer' are not deallocated, leading to memory leak bugs. > > Also, 'rt->out_urbs[i].buffer' is not deallocated if snd_pcm_new() fails. > > > > To fix the above issues, free 'rt' and 'rt->out_urbs[i].buffer'. > > > > Signed-off-by: Wenwen Wang > > --- > > sound/usb/hiface/pcm.c | 8 +++++++- > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/sound/usb/hiface/pcm.c b/sound/usb/hiface/pcm.c > > index 14fc1e1..9b132aa 100644 > > --- a/sound/usb/hiface/pcm.c > > +++ b/sound/usb/hiface/pcm.c > > @@ -599,12 +599,18 @@ int hiface_pcm_init(struct hiface_chip *chip, u8 > > extra_freq) > > for (i = 0; i < PCM_N_URBS; i++) { > > ret = hiface_pcm_init_urb(&rt->out_urbs[i], chip, OUT_EP, > > hiface_pcm_out_urb_handler); > > - if (ret < 0) > > + if (ret < 0) { > > + for (; i >= 0; i--) > > + kfree(rt->out_urbs[i].buffer); > > + kfree(rt); > > return ret; > > + } > > } > > > > ret = snd_pcm_new(chip->card, "USB-SPDIF Audio", 0, 1, 0, &pcm); > > if (ret < 0) { > > + for (i = 0; i < PCM_N_URBS; i++) > > + kfree(rt->out_urbs[i].buffer); > > kfree(rt); > > dev_err(&chip->dev->dev, "Cannot create pcm instance\n"); > > return ret; > > The fixes look correct, but since we can unconditionally call kfree() > for NULL, both error paths can be unified as: > > for (i = 0; i < PCM_N_URBS; i++) > kfree(rt->out_urbs[i].buffer); > kfree(rt); > > and this would be better to be put in the common path at the end and > do "goto error" or such from both places. I will rework the patch and revise the subject line. > BTW, your patch doesn't seem cleanly applicable in anyway because the > tabs are converted to spaces. Please check the mail setup. > > Also, please try to make the subject line more unique. This is about > hiface driver, so "ALSA: hiface: xxx" should be more appropriate. I will also check my mail setup. Thanks! Wenwen