Linux-Clk Archive on lore.kernel.org
 help / color / Atom feed
From: Shawn Guo <shawnguo@kernel.org>
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
Date: Wed, 19 Aug 2020 22:09:43 +0800
Message-ID: <20200819140939.GG7114@dragon> (raw)
In-Reply-To: <1595926999-14934-1-git-send-email-peng.fan@nxp.com>

On Tue, Jul 28, 2020 at 05:03:18PM +0800, peng.fan@nxp.com wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> Use devm_kzalloc() to avoid memory leak when probe fail.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
> 
> 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
> 

      parent reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28  9:03 peng.fan
2020-07-28  9:03 ` [PATCH v2 2/2] clk: imx: imx8m: use devm_of_clk_add_hw_provider() peng.fan
2020-07-28 19:15   ` Stephen Boyd
2020-07-28 19:15 ` [PATCH v2 1/2] clk: imx: imx8m: avoid memory leak Stephen Boyd
2020-08-19 14:09 ` Shawn Guo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200819140939.GG7114@dragon \
    --to=shawnguo@kernel.org \
    --cc=Anson.Huang@nxp.com \
    --cc=abel.vesa@nxp.com \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peng.fan@nxp.com \
    --cc=s.hauer@pengutronix.de \
    --cc=sboyd@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Clk Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-clk/0 linux-clk/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-clk linux-clk/ https://lore.kernel.org/linux-clk \
		linux-clk@vger.kernel.org
	public-inbox-index linux-clk

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-clk


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git