Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp552332ybi; Fri, 24 May 2019 07:51:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqvXGF/AqT+XYeyQUSjWpQbm4540uVCZ05nVutsOt8ucTXDpvuOHqh+5RnSsFNcKsw8X5M X-Received: by 2002:a17:902:8508:: with SMTP id bj8mr64168261plb.79.1558709468675; Fri, 24 May 2019 07:51:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558709468; cv=none; d=google.com; s=arc-20160816; b=q0mil2jBGxQFzvrFQH0zQriuf0/NSW4coE4CT2FimuE8RAYwmiSs8/c/YnNR1J54GE Z+I5gN+mXnZUReum4ABTyJytC54YH4LZd4QPtPWuXqGB3JMxVffW+rCkJsOt9V1JY4/5 Ppy/s8z+yeSEEoc3ORiru1eTRQ1APiApZHA/phEck8PdPZOj1UQLgAgJ6xIhqZVmBXUh PYCPmoLrxR2LkWYm2BvjfqhQ83RzMnQBjkuC7tqXg1Jcjz/gCwYWBiPYoavfG9Kf+ST+ ggt4kpebd++XvgcHn1k5EQzLAufyPryi7cImI8licRkGy0N5PJSps42WHuhLqeSpgwE2 2tvA== 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=0g5JbZfsE+2QT4bUSsZSJoNvEVoG7Gi9MR+1f1C9IVM=; b=XH1ttLT01pk84inTCGv5Lw/D11LU5AtCF9hPodoOu+7qAEtdME2o/z6VnsO2KU8fVK flvoKkdyWxZq+PZ2ldDLANwUC+QmTpb4UGwPyyLVFdpHgfRhpsk7yk0p+SAzg7K+KzIL SLWR4qe1U8pY+Klwc037QDDLMnefI2CFbeQ2llY2XGtgFnEV3ETJXuaP9jYtGOfFQPc7 vXAsvQhZHZf6rlIwklu1/UFUWWEfGXe9P/W6FXUPOWDRnmmDOvjgq97ob/TZcqEKuc/Q 9rt54rLuyY3R1XeaS3xjMX4G5nSOER1znsr050defu4ny+p+FwIcGd1w42WV0rVqndCV hYJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=ba489+Bm; 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 e25si4426098pfn.211.2019.05.24.07.50.51; Fri, 24 May 2019 07:51:08 -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=ba489+Bm; 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 S2404192AbfEXOri (ORCPT + 99 others); Fri, 24 May 2019 10:47:38 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:1893 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403911AbfEXOri (ORCPT ); Fri, 24 May 2019 10:47:38 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 24 May 2019 07:47:32 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 24 May 2019 07:47:37 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 24 May 2019 07:47:37 -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 14:47:35 +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> <20190524143309.GA8631@zhanggen-UX430UQ> From: Jon Hunter Message-ID: Date: Fri, 24 May 2019 15:47:34 +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: <20190524143309.GA8631@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=1558709252; bh=0g5JbZfsE+2QT4bUSsZSJoNvEVoG7Gi9MR+1f1C9IVM=; 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=ba489+BmxVdebKbeWlKfxGyqR6t2ZwGV7PlsvNZbWbUx1K+CaP9IxltJ86OrzGMPo iJHqm+bM3oBOcb1rMgvDxVk0Qq6YVAygJ/6S/Q+k3XnsuEhA3FfXtQRmykLkeD/an9 YWKWzgUDJpRiperBC8zWFwHoHro8yw8QV/qV2fPFjDMQrRN7npmMVeaYxtctasNBD+ mtdY8qYqrcH7B+Czei5YYb30TMbVqqD6VLhuV4y31skw06iGAO9ySNf9b5w9/kIc3C FfGyj68uI0ciZj9lEbd/e+lAblFBWqdlTBf6PSJIr0zFXdlfUt0CC9/zrrndbbQaZq QmIHjBOq1yaNw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/05/2019 15:33, Gen Zhang wrote: > On Fri, May 24, 2019 at 09:33:13AM +0100, Jon Hunter wrote: >> >> 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. > Thanks for your comments, Jon. But after I examined the code, I am still > confused about the usage of devm_kmalloc(). You can kindly refer to > hisi_sas_debugfs_init() in drivers/scsi/hisi_sas/hisi_sas_main.c. And > devm_kfree() is used to free a memory allocated by devm_kmalloc(). And > I found other situations similar to this in other files. > > So, I hope you can give me some guidance on this. Thanks! Please refer to the devres documentation [0]. Cheers, Jon [0] https://www.kernel.org/doc/Documentation/driver-model/devres.txt -- nvpublic