Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp493837pxa; Wed, 19 Aug 2020 07:11:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtpP1a/KeZXYY1idDBSsnoNJ+6gYreYi4f2iNdSlkPcIiEMqVuVNs6YPuWlvFpfuGJYR0O X-Received: by 2002:aa7:db44:: with SMTP id n4mr24948761edt.158.1597846263008; Wed, 19 Aug 2020 07:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597846263; cv=none; d=google.com; s=arc-20160816; b=Ker80HEmLfvYAmEjZQyD04vU/a+bgsVxFyu1nVOvQy/QtN8c7TaD7CTtB4qeM7vp9x hqxISrBzBDj/+ZcMgg5Y8/Wp+x7zLH5N7tEcxoUeUhxevDTK1Srr4HTYLgkiSIjmQphq dBeujT7d3dGYAFPS330nE7SalbpBkFrwgogG/phvQUxLPAl4T9iNMDPwcWT1vSs3MHUe 1xi2sUaG0kFMHQTz+5f3n+DsJ/cKiz5mWBWopwcQ57gNgFlHicHWmgTX4/fFh0ZP5GHJ g67s80sQUzpuCbu7oCPvYFMCAAiXAZJ8Dq57yeOdeaXHbWUUpLCpf6R7nqcIqD7Ee4Iu e3OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=wiFMPP71KENz6R6xgkUH85B0IByInlD946QZFDQ/90M=; b=0JZaxO4x35VxieUbOvCFFjOlPS94hTrL0nhIv3Uk5ogo4a/VFxuTnKmxejFTfJo5LE mFMV1Ewd6WyJage2fVZTJXNKTe6mkCEBbyk1MFetv9hZyzpih9h5LuLzawHOP7UfiUM0 5388k8coVnOsLNYG29c+X0myaSXMIDjw/mQS3TW/KMGHGt4P9yaJtiWiqMcquk1f610E wc7oUyxP+UzIORTpcGBIx13ssZR44/px78h7VaFvW6rwmKR+5sI1PmpX9T3nuFq+PkqG OP8RTq2AMDkKs6jbqT9jXXq4EBPBfZy+SvSZNPROOVTlFFbxC9CCsaokrJXNYsUkAYs0 iXVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vxuxv61v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si8049746edx.132.2020.08.19.07.10.38; Wed, 19 Aug 2020 07:11:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vxuxv61v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727773AbgHSOKD (ORCPT + 99 others); Wed, 19 Aug 2020 10:10:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:60990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726971AbgHSOJ7 (ORCPT ); Wed, 19 Aug 2020 10:09:59 -0400 Received: from dragon (unknown [80.251.214.228]) (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 28E45204FD; Wed, 19 Aug 2020 14:09:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597846199; bh=In5ktcVArsKzAgL094eAzOG9AV78RIA0HS0QwxilghY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vxuxv61vOKbl4FMNhYbl9exlmUtZMi3X2eawLCShnhs9vzDfwgzlJ8tWZjw8BxFyH +cTpUlRdHCu/7n5igw1bC/0pb134Au/9eSSoeaMtuXhvJAdMb7A2I6t0aV14FBNOr4 HFXA0sXDCrRihMZH2Gu4mBVGfVBwZmx7sn+lgMJQ= Date: Wed, 19 Aug 2020 22:09:43 +0800 From: Shawn Guo To: peng.fan@nxp.com Cc: sboyd@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, abel.vesa@nxp.com, kernel@pengutronix.de, linux-imx@nxp.com, Anson.Huang@nxp.com, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] clk: imx: imx8m: avoid memory leak Message-ID: <20200819140939.GG7114@dragon> References: <1595926999-14934-1-git-send-email-peng.fan@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1595926999-14934-1-git-send-email-peng.fan@nxp.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 28, 2020 at 05:03:18PM +0800, peng.fan@nxp.com wrote: > From: Peng Fan > > Use devm_kzalloc() to avoid memory leak when probe fail. > > Signed-off-by: Peng Fan > --- > > V2: > Add () to functions in commit log > > drivers/clk/imx/clk-imx8mm.c | 3 +-- > drivers/clk/imx/clk-imx8mn.c | 15 +++++---------- > drivers/clk/imx/clk-imx8mp.c | 2 +- > drivers/clk/imx/clk-imx8mq.c | 3 +-- > 4 files changed, 8 insertions(+), 15 deletions(-) > > diff --git a/drivers/clk/imx/clk-imx8mm.c b/drivers/clk/imx/clk-imx8mm.c > index b793264c21c6..b43dbe305e7a 100644 > --- a/drivers/clk/imx/clk-imx8mm.c > +++ b/drivers/clk/imx/clk-imx8mm.c > @@ -306,8 +306,7 @@ static int imx8mm_clocks_probe(struct platform_device *pdev) > void __iomem *base; > int ret, i; > > - clk_hw_data = kzalloc(struct_size(clk_hw_data, hws, > - IMX8MM_CLK_END), GFP_KERNEL); > + clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MM_CLK_END), GFP_KERNEL); > if (WARN_ON(!clk_hw_data)) > return -ENOMEM; > > diff --git a/drivers/clk/imx/clk-imx8mn.c b/drivers/clk/imx/clk-imx8mn.c > index 213cc37b3173..4189f7f6980e 100644 > --- a/drivers/clk/imx/clk-imx8mn.c > +++ b/drivers/clk/imx/clk-imx8mn.c > @@ -299,8 +299,7 @@ static int imx8mn_clocks_probe(struct platform_device *pdev) > void __iomem *base; > int ret, i; > > - clk_hw_data = kzalloc(struct_size(clk_hw_data, hws, > - IMX8MN_CLK_END), GFP_KERNEL); > + clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MN_CLK_END), GFP_KERNEL); > if (WARN_ON(!clk_hw_data)) > return -ENOMEM; > > @@ -318,10 +317,8 @@ static int imx8mn_clocks_probe(struct platform_device *pdev) > np = of_find_compatible_node(NULL, NULL, "fsl,imx8mn-anatop"); > base = of_iomap(np, 0); > of_node_put(np); > - if (WARN_ON(!base)) { > - ret = -ENOMEM; > - goto unregister_hws; > - } > + if (WARN_ON(!base)) > + return -ENOMEM; > > hws[IMX8MN_AUDIO_PLL1_REF_SEL] = imx_clk_hw_mux("audio_pll1_ref_sel", base + 0x0, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels)); > hws[IMX8MN_AUDIO_PLL2_REF_SEL] = imx_clk_hw_mux("audio_pll2_ref_sel", base + 0x14, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels)); > @@ -407,10 +404,8 @@ static int imx8mn_clocks_probe(struct platform_device *pdev) > > np = dev->of_node; > base = devm_platform_ioremap_resource(pdev, 0); > - if (WARN_ON(IS_ERR(base))) { > - ret = PTR_ERR(base); > - goto unregister_hws; > - } > + if (WARN_ON(IS_ERR(base))) > + return PTR_ERR(base); How is this related to devm_kzalloc() change? Shawn > > /* CORE */ > hws[IMX8MN_CLK_A53_DIV] = imx8m_clk_hw_composite_core("arm_a53_div", imx8mn_a53_sels, base + 0x8000); > diff --git a/drivers/clk/imx/clk-imx8mp.c b/drivers/clk/imx/clk-imx8mp.c > index ca747712400f..f6ec7b2b8038 100644 > --- a/drivers/clk/imx/clk-imx8mp.c > +++ b/drivers/clk/imx/clk-imx8mp.c > @@ -447,7 +447,7 @@ static int imx8mp_clocks_probe(struct platform_device *pdev) > return PTR_ERR(ccm_base); > } > > - clk_hw_data = kzalloc(struct_size(clk_hw_data, hws, IMX8MP_CLK_END), GFP_KERNEL); > + clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MP_CLK_END), GFP_KERNEL); > if (WARN_ON(!clk_hw_data)) { > iounmap(anatop_base); > return -ENOMEM; > diff --git a/drivers/clk/imx/clk-imx8mq.c b/drivers/clk/imx/clk-imx8mq.c > index a64aace213c2..0106a33c24a4 100644 > --- a/drivers/clk/imx/clk-imx8mq.c > +++ b/drivers/clk/imx/clk-imx8mq.c > @@ -288,8 +288,7 @@ static int imx8mq_clocks_probe(struct platform_device *pdev) > void __iomem *base; > int err, i; > > - clk_hw_data = kzalloc(struct_size(clk_hw_data, hws, > - IMX8MQ_CLK_END), GFP_KERNEL); > + clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, IMX8MQ_CLK_END), GFP_KERNEL); > if (WARN_ON(!clk_hw_data)) > return -ENOMEM; > > -- > 2.16.4 >