Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1066788ybl; Wed, 14 Aug 2019 10:10:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRu38g64Ka4IzipZYhwYhenbsGmfXAaJgtBCeaPxUwomjhD0yvqyQh4ZQcfC79+QiOEdvF X-Received: by 2002:aa7:8619:: with SMTP id p25mr982070pfn.220.1565802605305; Wed, 14 Aug 2019 10:10:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565802605; cv=none; d=google.com; s=arc-20160816; b=ztSbK+m9AhaxjIUYHcc1c+nW87iNVHFafR1mv/3futaPwvM/GMcxJadWFWxCYi3zxp em/5zZBs6O594roPJ8gaaQ1WA4+wLG7l+qGZUDMtWG5AojTUMGJc5L4ICEAumq3oMZa+ xbUp7eFgCIfSll6BjsE4wn2t8onCRibQa5QPOgff1iXt3oUDAb9WLcBmR5ER1UBIZ2et +OKWI6eNUS2dDLpjJb+VbOYFrWXto7hj02ufbIdxM/Y17Y39aeIDYCzkdVnkPUCYx1yw kum6U/DZZw16cctg8EwHpuioLKGfN3Hjc/5EG7BdKiBjbX+dy2glrWjwGk9p852f2ZKO HVDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8MnkGF2Rax7q9jrYyI4GBXHHpGuDn5RSumeGKG0meK8=; b=pMxb6JPABevW38iXR3xIXFAmriy0xQFi8QHM1DguZGYScsMdTnUyQikBSEG8UtwzB2 8b2zLAqfAjmVwchyWuWa9pJPQssuBMj3Ql3AMgsrd6zfYzGCdpDZjeI36LfavotJyF9Z Ne8vLzRk8GJ+9n2bsiJdC4eUQrQYa7gWeT86mlIIFNtG4hVc29u5m0idwUzX4IXFzoc4 vT4t5aoZmwytnu6XoXbYn2088/BdoZMklGLzw0OckpFxfW8q7fEC36UEvbi/L1IbKaiG tDKWLN7CIcljvlQrjMa7Boa/2ddgDRKfTpq0cHA6dyZZ/TnEuxJ8yqcwlUR2ZPrc4v2I AVtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sqXsTYJ+; 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 w10si153484pgs.529.2019.08.14.10.09.49; Wed, 14 Aug 2019 10:10:05 -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; dkim=pass header.i=@kernel.org header.s=default header.b=sqXsTYJ+; 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 S1729107AbfHNRHW (ORCPT + 99 others); Wed, 14 Aug 2019 13:07:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:56832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727815AbfHNRHU (ORCPT ); Wed, 14 Aug 2019 13:07:20 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 075402186A; Wed, 14 Aug 2019 17:07:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802439; bh=Cot4NZC9zpqgEWzvcE10GWPQszsfudXCBDIx+BzIz9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sqXsTYJ+8N9qqTxbeCyKUura3dS9MpuTdSty/PV+IrOo5spnG3JzKU0zJYTpyfBOZ NB+UdMVgSMnyd+ZdxjS5bim9EMULaQprGlTBrhvUnVDMbO3LDCMEsY1CCFXIBt8VnV JLSz402v6MjCbnmQuP7wBS+TM35XmYAEWFgZGv8Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenwen Wang , Takashi Iwai Subject: [PATCH 5.2 127/144] ALSA: hiface: fix multiple memory leak bugs Date: Wed, 14 Aug 2019 19:01:23 +0200 Message-Id: <20190814165805.249493983@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165759.466811854@linuxfoundation.org> References: <20190814165759.466811854@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wenwen Wang commit 3d92aa45fbfd7319e3a19f4ec59fd32b3862b723 upstream. 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'. Fixes: a91c3fb2f842 ("Add M2Tech hiFace USB-SPDIF driver") Signed-off-by: Wenwen Wang Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/usb/hiface/pcm.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/sound/usb/hiface/pcm.c +++ b/sound/usb/hiface/pcm.c @@ -600,14 +600,13 @@ int hiface_pcm_init(struct hiface_chip * ret = hiface_pcm_init_urb(&rt->out_urbs[i], chip, OUT_EP, hiface_pcm_out_urb_handler); if (ret < 0) - return ret; + goto error; } ret = snd_pcm_new(chip->card, "USB-SPDIF Audio", 0, 1, 0, &pcm); if (ret < 0) { - kfree(rt); dev_err(&chip->dev->dev, "Cannot create pcm instance\n"); - return ret; + goto error; } pcm->private_data = rt; @@ -620,4 +619,10 @@ int hiface_pcm_init(struct hiface_chip * chip->pcm = rt; return 0; + +error: + for (i = 0; i < PCM_N_URBS; i++) + kfree(rt->out_urbs[i].buffer); + kfree(rt); + return ret; }