Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1078379ybl; Wed, 14 Aug 2019 10:20:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxgYPysnnijhCiMrBqbBqnHb/oAiMHAwHw2FxR55zOos4u2Cu1aTCSflJAP24KrQTvdU5bz X-Received: by 2002:a62:7503:: with SMTP id q3mr1055213pfc.151.1565803228904; Wed, 14 Aug 2019 10:20:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565803228; cv=none; d=google.com; s=arc-20160816; b=IJh3ZDuYjaPxoNgh0DkkuiFu4b0vNCTbzidjR0WgZeIekUsflySI3igMsuMd5GKAvf egsG0Y3OtEgX9uVmx26mR88mL1S6hYdL2SIJ8LLr4MVxnwRCu9OCRmBSfaYaSTBaWVS3 W/PBiaqT3aUi5PjZRtvWMi8W/fJooE29TgX6uAZiCpbWZe3RmNRaRNqjAH+pz6Folfg7 AUvn6nndevPNF+KV+4v3RSyURbsnaTNZN/2gRUls9OQG/zHXXzVvinE5S6IagxgFOjgX 6/HeZH+tFHpE8yImiB/HEHKkAktZ5mjCkoIXOpVRDEzhS/DlZZFir9K/+mlxMlTokiIL QKoQ== 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=6J39tmRcjiD4jbeHxbyTlDRBFWfxZOTLRj5GpIGbloI=; b=sgXhfhK4GvUqhk7ZU1QGfx0377XH7AV9SbYm+yjvmOF1YtNZuxaVZPOF6f/6GqD08O tWg8qaKytnAIk0k7+re63clpjDVn9rBAFUs8POdBOefOrfNCa+Tpr3vEA8iJVUoSiSc7 VIOKcpPL8V/2/TiICTXU54MppbIpsDB9wKSt62wiDrRkVsLVovsNVDy5DJz/KjguqJsl Dw9BUaMley52jt5HbbetDfongqGtWX+6J/U6pk9o3ALUcQFrEleouYixS1s7ymSiNTD6 l7kuRI1wM7GNMpEUNAmTZlhF6i1nxyQTSKGSSyZDzbn/ac0O3B/wsO/BO0cNiwi75UTE +0kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HIzztwcJ; 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 w8si191186pgp.414.2019.08.14.10.20.12; Wed, 14 Aug 2019 10:20:28 -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=HIzztwcJ; 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 S1729729AbfHNRTl (ORCPT + 99 others); Wed, 14 Aug 2019 13:19:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:34724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730592AbfHNRLZ (ORCPT ); Wed, 14 Aug 2019 13:11:25 -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 4E2382133F; Wed, 14 Aug 2019 17:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802684; bh=ZVWqXDhVYCfDqX3KEET7MUpwNtvT7KRdDULsbPhFlaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HIzztwcJzVTSzBGUQe4oSLWNVb+vxgb3kDRIaUufZ4dhbFuIB/dJnWchi/PVV4PoO pzcloS7QF4NQ5v8KSfwt+SWxPI3NQBfftJPiWHzEb0gxut2hZQSGLCVkfyb474VrWi 7i1iytTmf400WLY4gIonXNnwqU2WiVAmWjHtfuNs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenwen Wang , Takashi Iwai Subject: [PATCH 4.19 78/91] ALSA: hiface: fix multiple memory leak bugs Date: Wed, 14 Aug 2019 19:01:41 +0200 Message-Id: <20190814165753.135761925@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165748.991235624@linuxfoundation.org> References: <20190814165748.991235624@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 @@ -604,14 +604,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; @@ -624,4 +623,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; }