Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp153337ybi; Fri, 24 May 2019 01:35:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpqmpRUp1cRRdGI/IQb5VFfeXYF2vlvZZnIIgSUBhHsZ1ZHtiCjUoOrtGQ6QNR/yz6Jv/C X-Received: by 2002:a63:6647:: with SMTP id a68mr86512064pgc.292.1558686916777; Fri, 24 May 2019 01:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558686916; cv=none; d=google.com; s=arc-20160816; b=oJWgQHZSioma36znCy51lREiSUuTBO6tW+6dUM4YF+l8C2KlbmU5ax/zUHnOHqQxTr mF4e+xNPyS/nyJCyldyCKHKJgzbwE6vtCaNxoMwKciCRFbyb5GaJ/7H9hEb9iSSZvOPH VdX+nQg3jHwQwm84Wre5ANWK2L2Tt6CrLD6zt1npOnkmxknIt0x7L7eP8YWwtA81BDsB F1Qj7PFfeH5bqNrPPk42ApgWWSbfhgh6Piwq4rNn9Rwz/gtqGSpOMQgOJPpM5EG9Ic7Q cNxbLAodFchNDwUEuocpQXXjMvuZf+SU0eF/VLdma7mHAPib2NYF71JWU1QF7osYAf0p 0xMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=vkCEueUAPlP/apgkFiyHjF374bXH/u7KlllgHip5zNw=; b=NtM3oIE0aNoCsBnL1odf9Bf03lnQeAekFdmqO8GlUHGZ62K8EsY8jJR/7l5lNwYOxZ 3MN5TifU0VNZQPWSza9GkUSv4aB+GmJylehUGlAMuAtx4gH7kC9eIlucsNZFFCHihUff cRZRnuj1osbVE9mjYvp9CC1gpIakN74sVByZ5MhqQPcQTn9LLp1Yn9r2hpgWZQz8XOnn 1fBcrol/fGnemhk8oZUFP16F0GLALD7NzrqDwbhqPQ+iJuAWxxGVMNAPF0QvQSst+zMC uDxEK7Aip1pXSu4ZQ5Arxr8PgsR1KBXArrZbEu09CcxRgBLFtagdk7aAVeJrWTy14P9K YGqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b="axT/Z4Pe"; 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=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 192si3032913pfz.42.2019.05.24.01.34.58; Fri, 24 May 2019 01:35:16 -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=@nvidia.com header.s=n1 header.b="axT/Z4Pe"; 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=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389541AbfEXIdS (ORCPT + 99 others); Fri, 24 May 2019 04:33:18 -0400 Received: from hqemgate14.nvidia.com ([216.228.121.143]:15383 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389297AbfEXIdR (ORCPT ); Fri, 24 May 2019 04:33:17 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 24 May 2019 01:33:17 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Fri, 24 May 2019 01:33:17 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Fri, 24 May 2019 01:33:17 -0700 Received: from [10.21.132.148] (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 24 May 2019 08:33:15 +0000 Subject: Re: [PATCH] tegra_wm9712: Fix a memory leaking bug in tegra_wm9712_driver_probe() To: Gen Zhang , , CC: , , References: <20190524005014.GA2289@zhanggen-UX430UQ> From: Jon Hunter Message-ID: Date: Fri, 24 May 2019 09:33:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190524005014.GA2289@zhanggen-UX430UQ> X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL103.nvidia.com (172.20.187.11) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1558686797; bh=vkCEueUAPlP/apgkFiyHjF374bXH/u7KlllgHip5zNw=; h=X-PGP-Universal:Subject:To:CC:References:From:Message-ID:Date: User-Agent:MIME-Version:In-Reply-To:X-Originating-IP: X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=axT/Z4PeCAsNFCG1WqGLPh67ItaiJrqmcFul0qH19p84KXDA55OvlN4ub0AM0L0J1 teyY8/SXfwb1dxPxEpSaeXje2VopUqvGzYWk6+mU1CtAGG1BbTQiUKDfDOPhexo7mc sJEqJMze0K4TiJKqMopCFG6TfZXtJJB3DI/bIMsQbEwfnEbyjSINU0WE9lzfTnv5mY Qaagp1ceWr+Q/+ct/YMtiaxD8m+09fWb5geSwovhV7gscDHq2fl6l7Xefn60virDA1 A+SzHmxXgCnuhmFukoFr72M7KJCZUt7LN/30gwE3Wv/YePiHE6xi849yvhFBzI6nhq c27aizYhUb+2w== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/05/2019 01:50, Gen Zhang wrote: > 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. Memory allocated by devm_xxx() is automatically freed on failure so this is not correct. > Further, we should free 'machine->util_data', 'machine->codec' and > 'machine' before this function normally ends to prevent memory leaking. This is also incorrect. Why would we free all resources after successfully initialising the driver? > 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; As stated above, this is incorrect. Did you actually test this? I think you would find this would break the driver. Jon -- nvpublic