All of lore.kernel.org
 help / color / mirror / Atom feed
From: Viresh Kumar <viresh.kumar@linaro.org>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: mmayer@broadcom.com, bcm-kernel-feedback-list@broadcom.com,
	rjw@rjwysocki.net, f.fainelli@gmail.com,
	linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the probe function
Date: Tue, 22 Dec 2020 10:05:05 +0530	[thread overview]
Message-ID: <20201222043505.rq3cmajc3mxv3p2z@vireshk-i7> (raw)
In-Reply-To: <20201219101751.181783-1-christophe.jaillet@wanadoo.fr>

On 19-12-20, 11:17, Christophe JAILLET wrote:
> If 'cpufreq_register_driver()' fails, we must release the resources
> allocated in 'brcm_avs_prepare_init()' as already done in the remove
> function.
> 
> To do that, introduce a new function 'brcm_avs_prepare_uninit()' in order
> to avoid code duplication. This also makes the code more readable (IMHO).
> 
> Fixes: de322e085995 ("cpufreq: brcmstb-avs-cpufreq: AVS CPUfreq driver for Broadcom STB SoCs")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> I'm not sure that the existing error handling in the remove function is
> correct and/or needed.
> ---
>  drivers/cpufreq/brcmstb-avs-cpufreq.c | 25 ++++++++++++++++++++-----
>  1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> index 3e31e5d28b79..750ca7cfccb0 100644
> --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
> +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> @@ -597,6 +597,16 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
>  	return ret;
>  }
>  
> +static void brcm_avs_prepare_uninit(struct platform_device *pdev)
> +{
> +	struct private_data *priv;
> +
> +	priv = platform_get_drvdata(pdev);
> +
> +	iounmap(priv->avs_intr_base);
> +	iounmap(priv->base);
> +}
> +
>  static int brcm_avs_cpufreq_init(struct cpufreq_policy *policy)
>  {
>  	struct cpufreq_frequency_table *freq_table;
> @@ -732,21 +742,26 @@ static int brcm_avs_cpufreq_probe(struct platform_device *pdev)
>  
>  	brcm_avs_driver.driver_data = pdev;
>  
> -	return cpufreq_register_driver(&brcm_avs_driver);
> +	ret = cpufreq_register_driver(&brcm_avs_driver);
> +	if (ret)
> +		goto err_uninit;
> +
> +	return 0;
> +
> +err_uninit:
> +	brcm_avs_prepare_uninit(pdev);
> +	return ret;

Maybe rewrite as:

	ret = cpufreq_register_driver(&brcm_avs_driver);
	if (ret)
                brcm_avs_prepare_uninit(pdev);
	return ret;

>  }
>  
>  static int brcm_avs_cpufreq_remove(struct platform_device *pdev)
>  {
> -	struct private_data *priv;
>  	int ret;
>  
>  	ret = cpufreq_unregister_driver(&brcm_avs_driver);
>  	if (ret)
>  		return ret;

Instead of returning here, it can be just WARN_ON(ret); and then go on and free
the resources and this needs to be done in a separate patch.

>  
> -	priv = platform_get_drvdata(pdev);
> -	iounmap(priv->base);
> -	iounmap(priv->avs_intr_base);
> +	brcm_avs_prepare_uninit(pdev);
>  
>  	return 0;
>  }

-- 
viresh

WARNING: multiple messages have this Message-ID (diff)
From: Viresh Kumar <viresh.kumar@linaro.org>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: f.fainelli@gmail.com, linux-pm@vger.kernel.org,
	kernel-janitors@vger.kernel.org, rjw@rjwysocki.net,
	linux-kernel@vger.kernel.org,
	bcm-kernel-feedback-list@broadcom.com, mmayer@broadcom.com,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the
Date: Tue, 22 Dec 2020 04:47:05 +0000	[thread overview]
Message-ID: <20201222043505.rq3cmajc3mxv3p2z@vireshk-i7> (raw)
In-Reply-To: <20201219101751.181783-1-christophe.jaillet@wanadoo.fr>

On 19-12-20, 11:17, Christophe JAILLET wrote:
> If 'cpufreq_register_driver()' fails, we must release the resources
> allocated in 'brcm_avs_prepare_init()' as already done in the remove
> function.
> 
> To do that, introduce a new function 'brcm_avs_prepare_uninit()' in order
> to avoid code duplication. This also makes the code more readable (IMHO).
> 
> Fixes: de322e085995 ("cpufreq: brcmstb-avs-cpufreq: AVS CPUfreq driver for Broadcom STB SoCs")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> I'm not sure that the existing error handling in the remove function is
> correct and/or needed.
> ---
>  drivers/cpufreq/brcmstb-avs-cpufreq.c | 25 ++++++++++++++++++++-----
>  1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> index 3e31e5d28b79..750ca7cfccb0 100644
> --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
> +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> @@ -597,6 +597,16 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
>  	return ret;
>  }
>  
> +static void brcm_avs_prepare_uninit(struct platform_device *pdev)
> +{
> +	struct private_data *priv;
> +
> +	priv = platform_get_drvdata(pdev);
> +
> +	iounmap(priv->avs_intr_base);
> +	iounmap(priv->base);
> +}
> +
>  static int brcm_avs_cpufreq_init(struct cpufreq_policy *policy)
>  {
>  	struct cpufreq_frequency_table *freq_table;
> @@ -732,21 +742,26 @@ static int brcm_avs_cpufreq_probe(struct platform_device *pdev)
>  
>  	brcm_avs_driver.driver_data = pdev;
>  
> -	return cpufreq_register_driver(&brcm_avs_driver);
> +	ret = cpufreq_register_driver(&brcm_avs_driver);
> +	if (ret)
> +		goto err_uninit;
> +
> +	return 0;
> +
> +err_uninit:
> +	brcm_avs_prepare_uninit(pdev);
> +	return ret;

Maybe rewrite as:

	ret = cpufreq_register_driver(&brcm_avs_driver);
	if (ret)
                brcm_avs_prepare_uninit(pdev);
	return ret;

>  }
>  
>  static int brcm_avs_cpufreq_remove(struct platform_device *pdev)
>  {
> -	struct private_data *priv;
>  	int ret;
>  
>  	ret = cpufreq_unregister_driver(&brcm_avs_driver);
>  	if (ret)
>  		return ret;

Instead of returning here, it can be just WARN_ON(ret); and then go on and free
the resources and this needs to be done in a separate patch.

>  
> -	priv = platform_get_drvdata(pdev);
> -	iounmap(priv->base);
> -	iounmap(priv->avs_intr_base);
> +	brcm_avs_prepare_uninit(pdev);
>  
>  	return 0;
>  }

-- 
viresh

WARNING: multiple messages have this Message-ID (diff)
From: Viresh Kumar <viresh.kumar@linaro.org>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: f.fainelli@gmail.com, linux-pm@vger.kernel.org,
	kernel-janitors@vger.kernel.org, rjw@rjwysocki.net,
	linux-kernel@vger.kernel.org,
	bcm-kernel-feedback-list@broadcom.com, mmayer@broadcom.com,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the probe function
Date: Tue, 22 Dec 2020 10:05:05 +0530	[thread overview]
Message-ID: <20201222043505.rq3cmajc3mxv3p2z@vireshk-i7> (raw)
In-Reply-To: <20201219101751.181783-1-christophe.jaillet@wanadoo.fr>

On 19-12-20, 11:17, Christophe JAILLET wrote:
> If 'cpufreq_register_driver()' fails, we must release the resources
> allocated in 'brcm_avs_prepare_init()' as already done in the remove
> function.
> 
> To do that, introduce a new function 'brcm_avs_prepare_uninit()' in order
> to avoid code duplication. This also makes the code more readable (IMHO).
> 
> Fixes: de322e085995 ("cpufreq: brcmstb-avs-cpufreq: AVS CPUfreq driver for Broadcom STB SoCs")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> I'm not sure that the existing error handling in the remove function is
> correct and/or needed.
> ---
>  drivers/cpufreq/brcmstb-avs-cpufreq.c | 25 ++++++++++++++++++++-----
>  1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> index 3e31e5d28b79..750ca7cfccb0 100644
> --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
> +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> @@ -597,6 +597,16 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
>  	return ret;
>  }
>  
> +static void brcm_avs_prepare_uninit(struct platform_device *pdev)
> +{
> +	struct private_data *priv;
> +
> +	priv = platform_get_drvdata(pdev);
> +
> +	iounmap(priv->avs_intr_base);
> +	iounmap(priv->base);
> +}
> +
>  static int brcm_avs_cpufreq_init(struct cpufreq_policy *policy)
>  {
>  	struct cpufreq_frequency_table *freq_table;
> @@ -732,21 +742,26 @@ static int brcm_avs_cpufreq_probe(struct platform_device *pdev)
>  
>  	brcm_avs_driver.driver_data = pdev;
>  
> -	return cpufreq_register_driver(&brcm_avs_driver);
> +	ret = cpufreq_register_driver(&brcm_avs_driver);
> +	if (ret)
> +		goto err_uninit;
> +
> +	return 0;
> +
> +err_uninit:
> +	brcm_avs_prepare_uninit(pdev);
> +	return ret;

Maybe rewrite as:

	ret = cpufreq_register_driver(&brcm_avs_driver);
	if (ret)
                brcm_avs_prepare_uninit(pdev);
	return ret;

>  }
>  
>  static int brcm_avs_cpufreq_remove(struct platform_device *pdev)
>  {
> -	struct private_data *priv;
>  	int ret;
>  
>  	ret = cpufreq_unregister_driver(&brcm_avs_driver);
>  	if (ret)
>  		return ret;

Instead of returning here, it can be just WARN_ON(ret); and then go on and free
the resources and this needs to be done in a separate patch.

>  
> -	priv = platform_get_drvdata(pdev);
> -	iounmap(priv->base);
> -	iounmap(priv->avs_intr_base);
> +	brcm_avs_prepare_uninit(pdev);
>  
>  	return 0;
>  }

-- 
viresh

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

  parent reply	other threads:[~2020-12-22  4:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-19 10:17 [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the probe function Christophe JAILLET
2020-12-19 10:17 ` Christophe JAILLET
2020-12-19 10:17 ` [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the prob Christophe JAILLET
2020-12-21 23:00 ` [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the probe function Florian Fainelli
2020-12-21 23:00   ` Florian Fainelli
2020-12-21 23:00   ` [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the Florian Fainelli
2020-12-22  4:35 ` Viresh Kumar [this message]
2020-12-22  4:47   ` Viresh Kumar
2020-12-22  4:35   ` [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the probe function Viresh Kumar
2020-12-27 17:22   ` Christophe JAILLET
2020-12-27 17:22     ` Christophe JAILLET
2020-12-27 17:22     ` [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the Christophe JAILLET
2020-12-28  5:37     ` [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the probe function Viresh Kumar
2020-12-28  5:49       ` [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the Viresh Kumar
2020-12-28  5:37       ` [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the probe function Viresh Kumar

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=20201222043505.rq3cmajc3mxv3p2z@vireshk-i7 \
    --to=viresh.kumar@linaro.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=f.fainelli@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mmayer@broadcom.com \
    --cc=rjw@rjwysocki.net \
    /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.