Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2457814ybm; Thu, 23 May 2019 17:52:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNUcPXK58VJqUlEb4foOoEP18ga8Mn9HLAquU4nj0gp3dcHtBd8sUntYq+tzk/22+j+i60 X-Received: by 2002:a17:902:7044:: with SMTP id h4mr20633057plt.219.1558659150093; Thu, 23 May 2019 17:52:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558659150; cv=none; d=google.com; s=arc-20160816; b=EJqUr+7p1RlCZ9VYwjn2yyGecy9eRAJLI84o/GjOzV5x5iWjhdDLAgzYDMOwCXRegL v5HNaWCBxUAJGL74TCftFvhLQDM9ghHUEZGMUGnulIQsw5X2bFNWV3ZjLt45eBUijwIV Ezy8KVWnoeoEdxY7BeSb2y4fhBeHsmvrs2+a5AYD6G4lJvRmrPPS5Vsp/pdjN8HveR9P d9fA14Cdy6ibwq5TQtOVptnsPvA2IfslFai/UUkTJXigoYgMb81qmsZJIHgRvDWlm0Sf yvi7Nbnm8uHhLpNzhqeJi144Uqcw+H0vmJOUvlYzl7JqvTVcMAq1GI92hnCTEQyazKMa sL9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=vq5OscFiBg+c2cP1NzGhhjMT3RLQCBEIhZHhvje2x5I=; b=CVeU1XCIVGmvOVPXdmVy/DD2JEmlHkPK1ieoqv0NgBxYhTrHaSVlelsJh9TM5+4usq gaqc9yWWl8Qf9Dm5gccSx93syOImvQx25wCrejAirx/KkpU7dsSEzb7dJAzpoEljiGx5 7B3k83MeS6X7o8fytGEL1ohXcdQybclDB6jtPAJ/gxNxL+TkcmDplM+v5gwzWhxq3Gk7 Zk9RsNbqW2ZUnaWzQvhFxWErHxrPwyVQk+Di5a9iMe70dadvZt8oN+sZG1zzK/5Y9fhd VHmki5yKQ75fOwOJKisbwaU5cOr0G+HNxzEElPvEmKh+TLB9wYcd3YqOGjGuHSdYLv3c 3t9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="WIkbsY/T"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5si1956134pgz.231.2019.05.23.17.52.08; Thu, 23 May 2019 17:52:30 -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=@gmail.com header.s=20161025 header.b="WIkbsY/T"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388696AbfEXAuf (ORCPT + 99 others); Thu, 23 May 2019 20:50:35 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35833 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387613AbfEXAue (ORCPT ); Thu, 23 May 2019 20:50:34 -0400 Received: by mail-pl1-f193.google.com with SMTP id p1so3437492plo.2; Thu, 23 May 2019 17:50:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=vq5OscFiBg+c2cP1NzGhhjMT3RLQCBEIhZHhvje2x5I=; b=WIkbsY/TDaVPI5z60Tn4ATxrtlgyarhuhzGl7tFy847LWwZlvijIngLI0XMBE9qCDb pSWLCeQqhHiem7oNeT9m0DChmWEfd5DeLjg5K/Sj6NBAxypME8zGxfHGd4UfxoojMpye qcRyjJropK5H1rp1yTvykFcrd2dxylvmLkk3ga1NZXe8PFOmdpzBxJTZeDuIvktKhwsR 6uOraw9mlBinMu3w9myx+pjNB1C0+JcmVS2XOdmhNikr0cZOXnvrF/B+GOMmw8o3INqg YB27G/Znkl3oBugcnN0yqr4hwZnSnvZ5NjN0ExmeabwWdmNXKpfyKgHRsGJCZagUh9M8 s4kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=vq5OscFiBg+c2cP1NzGhhjMT3RLQCBEIhZHhvje2x5I=; b=j0z5GWvCmcIavyoAIyLrAjTdnvP+wPDC/pwm2aA/fDNHTQ27qOsgn36N3epEXhZEZK T/5pToF3e8g3g6ysJoKHILhKHvSQrT2W2KjOTgNL+eXh3JyYo4GkLRX90yAKs1nGI2T8 24Bv5NPncoRdoq86Nuz3nSbgx4ddiliwlzRAukZ5DVcVbb4SwxB4gyHQgbXhIjUURl7c 0l9azxCctgSX9RxUpChbD5LgYhyi/4fFaWxBtzbo5bD99qsNj8aHAggYRRGsVvATSmVM c5zh9jcfatxAK7rZYSU/ZFDIYGGnutyyCiFaPGblW5Ou1nz11ZW57jr37us22oDxUEBW rvuw== X-Gm-Message-State: APjAAAWVgNzmn2qxJcv1gSdTgEI3cc/aYZBm7TI0ySRZer5I2YWzXjlZ V/la65x8DbQK9vxtLBk6ZziFD3uRZ20= X-Received: by 2002:a17:902:59c3:: with SMTP id d3mr30818966plj.273.1558659033669; Thu, 23 May 2019 17:50:33 -0700 (PDT) Received: from zhanggen-UX430UQ ([66.42.35.75]) by smtp.gmail.com with ESMTPSA id d4sm468985pju.19.2019.05.23.17.50.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 17:50:33 -0700 (PDT) Date: Fri, 24 May 2019 08:50:14 +0800 From: Gen Zhang To: lgirdwood@gmail.com, perex@perex.cz Cc: alsa-devel@alsa-project.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] tegra_wm9712: Fix a memory leaking bug in tegra_wm9712_driver_probe() Message-ID: <20190524005014.GA2289@zhanggen-UX430UQ> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In tegra_wm9712_driver_probe(), 'machine->codec' is allocated by platform_device_alloc(). When it is NULL, function returns ENOMEM. However, 'machine' is allocated by devm_kzalloc() before this site. Thus we should free 'machine' before function ends to prevent memory leaking. Further, we should free 'machine->util_data', 'machine->codec' and 'machine' before this function normally ends to prevent memory leaking. Signed-off-by: Gen Zhang --- diff --git a/sound/soc/tegra/tegra_wm9712.c b/sound/soc/tegra/tegra_wm9712.c index 864a334..295c41d 100644 --- a/sound/soc/tegra/tegra_wm9712.c +++ b/sound/soc/tegra/tegra_wm9712.c @@ -86,7 +86,8 @@ static int tegra_wm9712_driver_probe(struct platform_device *pdev) machine->codec = platform_device_alloc("wm9712-codec", -1); if (!machine->codec) { dev_err(&pdev->dev, "Can't allocate wm9712 platform device\n"); - return -ENOMEM; + ret = -ENOMEM; + goto codec_free; } ret = platform_device_add(machine->codec); @@ -127,6 +128,10 @@ static int tegra_wm9712_driver_probe(struct platform_device *pdev) goto asoc_utils_fini; } + tegra_asoc_utils_fini(&machine->util_data); + platform_device_del(machine->codec); + platform_device_put(machine->codec); + devm_kfree(&pdev->dev, machine); return 0; asoc_utils_fini: @@ -135,6 +140,8 @@ static int tegra_wm9712_driver_probe(struct platform_device *pdev) platform_device_del(machine->codec); codec_put: platform_device_put(machine->codec); +codec_free: + devm_kfree(&pdev->dev, machine); return ret; } ---