All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Ferre <nicolas.ferre@microchip.com>
To: Claudiu Beznea <claudiu.beznea@microchip.com>, <sre@kernel.org>,
	<alexandre.belloni@bootlin.com>,
	<ludovic.desroches@microchip.com>
Cc: <linux-pm@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, kernel test robot <lkp@intel.com>,
	"Dan Carpenter" <dan.carpenter@oracle.com>
Subject: Re: [PATCH] power: reset: at91-reset: free resources on exit path
Date: Wed, 31 Mar 2021 10:18:41 +0200	[thread overview]
Message-ID: <b18fc346-498d-4c6f-7f06-a6148a17d216@microchip.com> (raw)
In-Reply-To: <20210209110109.906034-1-claudiu.beznea@microchip.com>

On 09/02/2021 at 12:01, Claudiu Beznea wrote:
> Free resources on exit path (failure path of probe and remove).

I'm not sure we can use this driver as a module anyway.

Otherwise, it looks fine, but isn't it possible to use devm_of_iomap(), 
even in loop, and avoid having to deal with exit path?

> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
>   drivers/power/reset/at91-reset.c | 25 ++++++++++++++++++++-----
>   1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/power/reset/at91-reset.c b/drivers/power/reset/at91-reset.c
> index 3ff9d93a5226..2ff7833153b6 100644
> --- a/drivers/power/reset/at91-reset.c
> +++ b/drivers/power/reset/at91-reset.c
> @@ -206,7 +206,8 @@ static int __init at91_reset_probe(struct platform_device *pdev)
>   			if (!reset->ramc_base[idx]) {
>   				dev_err(&pdev->dev, "Could not map ram controller address\n");
>   				of_node_put(np);
> -				return -ENODEV;
> +				ret = -ENODEV;
> +				goto unmap;
>   			}
>   			idx++;
>   		}
> @@ -218,13 +219,15 @@ static int __init at91_reset_probe(struct platform_device *pdev)
>   	reset->args = (u32)match->data;
>   
>   	reset->sclk = devm_clk_get(&pdev->dev, NULL);
> -	if (IS_ERR(reset->sclk))
> -		return PTR_ERR(reset->sclk);
> +	if (IS_ERR(reset->sclk)) {
> +		ret = PTR_ERR(reset->sclk);
> +		goto unmap;
> +	}
>   
>   	ret = clk_prepare_enable(reset->sclk);
>   	if (ret) {
>   		dev_err(&pdev->dev, "Could not enable slow clock\n");
> -		return ret;
> +		goto unmap;
>   	}
>   
>   	platform_set_drvdata(pdev, reset);
> @@ -239,21 +242,33 @@ static int __init at91_reset_probe(struct platform_device *pdev)
>   	ret = register_restart_handler(&reset->nb);
>   	if (ret) {
>   		clk_disable_unprepare(reset->sclk);
> -		return ret;
> +		goto unmap;
>   	}
>   
>   	at91_reset_status(pdev, reset->rstc_base);
>   
>   	return 0;
> +
> +unmap:
> +	iounmap(reset->rstc_base);
> +	for (idx = 0; idx < ARRAY_SIZE(reset->ramc_base); idx++)
> +		iounmap(reset->ramc_base[idx]);

But if we keep this loop, I have the feeling that some kind of 
"of_node_put()" is needed as well.

> +
> +	return ret;
>   }
>   
>   static int __exit at91_reset_remove(struct platform_device *pdev)
>   {
>   	struct at91_reset *reset = platform_get_drvdata(pdev);
> +	int idx;
>   
>   	unregister_restart_handler(&reset->nb);
>   	clk_disable_unprepare(reset->sclk);
>   
> +	iounmap(reset->rstc_base);
> +	for (idx = 0; idx < ARRAY_SIZE(reset->ramc_base); idx++)
> +		iounmap(reset->ramc_base[idx]);

Ditto

> +
>   	return 0;
>   }
>   
> 


-- 
Nicolas Ferre

WARNING: multiple messages have this Message-ID (diff)
From: Nicolas Ferre <nicolas.ferre@microchip.com>
To: Claudiu Beznea <claudiu.beznea@microchip.com>, <sre@kernel.org>,
	<alexandre.belloni@bootlin.com>,
	<ludovic.desroches@microchip.com>
Cc: <linux-pm@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, kernel test robot <lkp@intel.com>,
	"Dan Carpenter" <dan.carpenter@oracle.com>
Subject: Re: [PATCH] power: reset: at91-reset: free resources on exit path
Date: Wed, 31 Mar 2021 10:18:41 +0200	[thread overview]
Message-ID: <b18fc346-498d-4c6f-7f06-a6148a17d216@microchip.com> (raw)
In-Reply-To: <20210209110109.906034-1-claudiu.beznea@microchip.com>

On 09/02/2021 at 12:01, Claudiu Beznea wrote:
> Free resources on exit path (failure path of probe and remove).

I'm not sure we can use this driver as a module anyway.

Otherwise, it looks fine, but isn't it possible to use devm_of_iomap(), 
even in loop, and avoid having to deal with exit path?

> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
>   drivers/power/reset/at91-reset.c | 25 ++++++++++++++++++++-----
>   1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/power/reset/at91-reset.c b/drivers/power/reset/at91-reset.c
> index 3ff9d93a5226..2ff7833153b6 100644
> --- a/drivers/power/reset/at91-reset.c
> +++ b/drivers/power/reset/at91-reset.c
> @@ -206,7 +206,8 @@ static int __init at91_reset_probe(struct platform_device *pdev)
>   			if (!reset->ramc_base[idx]) {
>   				dev_err(&pdev->dev, "Could not map ram controller address\n");
>   				of_node_put(np);
> -				return -ENODEV;
> +				ret = -ENODEV;
> +				goto unmap;
>   			}
>   			idx++;
>   		}
> @@ -218,13 +219,15 @@ static int __init at91_reset_probe(struct platform_device *pdev)
>   	reset->args = (u32)match->data;
>   
>   	reset->sclk = devm_clk_get(&pdev->dev, NULL);
> -	if (IS_ERR(reset->sclk))
> -		return PTR_ERR(reset->sclk);
> +	if (IS_ERR(reset->sclk)) {
> +		ret = PTR_ERR(reset->sclk);
> +		goto unmap;
> +	}
>   
>   	ret = clk_prepare_enable(reset->sclk);
>   	if (ret) {
>   		dev_err(&pdev->dev, "Could not enable slow clock\n");
> -		return ret;
> +		goto unmap;
>   	}
>   
>   	platform_set_drvdata(pdev, reset);
> @@ -239,21 +242,33 @@ static int __init at91_reset_probe(struct platform_device *pdev)
>   	ret = register_restart_handler(&reset->nb);
>   	if (ret) {
>   		clk_disable_unprepare(reset->sclk);
> -		return ret;
> +		goto unmap;
>   	}
>   
>   	at91_reset_status(pdev, reset->rstc_base);
>   
>   	return 0;
> +
> +unmap:
> +	iounmap(reset->rstc_base);
> +	for (idx = 0; idx < ARRAY_SIZE(reset->ramc_base); idx++)
> +		iounmap(reset->ramc_base[idx]);

But if we keep this loop, I have the feeling that some kind of 
"of_node_put()" is needed as well.

> +
> +	return ret;
>   }
>   
>   static int __exit at91_reset_remove(struct platform_device *pdev)
>   {
>   	struct at91_reset *reset = platform_get_drvdata(pdev);
> +	int idx;
>   
>   	unregister_restart_handler(&reset->nb);
>   	clk_disable_unprepare(reset->sclk);
>   
> +	iounmap(reset->rstc_base);
> +	for (idx = 0; idx < ARRAY_SIZE(reset->ramc_base); idx++)
> +		iounmap(reset->ramc_base[idx]);

Ditto

> +
>   	return 0;
>   }
>   
> 


-- 
Nicolas Ferre

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-03-31  8:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 11:01 [PATCH] power: reset: at91-reset: free resources on exit path Claudiu Beznea
2021-02-09 11:01 ` Claudiu Beznea
2021-03-31  8:18 ` Nicolas Ferre [this message]
2021-03-31  8:18   ` Nicolas Ferre
2021-04-01 14:42   ` Claudiu.Beznea
2021-04-01 14:42     ` Claudiu.Beznea
2021-04-01 14:50     ` Claudiu.Beznea
2021-04-01 14:50       ` Claudiu.Beznea
2021-04-02  7:32     ` Nicolas Ferre
2021-04-02  7:32       ` Nicolas Ferre

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=b18fc346-498d-4c6f-7f06-a6148a17d216@microchip.com \
    --to=nicolas.ferre@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=claudiu.beznea@microchip.com \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=ludovic.desroches@microchip.com \
    --cc=sre@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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.