From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Viresh Kumar <viresh.kumar@linaro.org>
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: Sun, 27 Dec 2020 18:22:00 +0100 [thread overview]
Message-ID: <a7e1f78c-b4c9-4ef5-7ca4-94a65fefd299@wanadoo.fr> (raw)
In-Reply-To: <20201222043505.rq3cmajc3mxv3p2z@vireshk-i7>
Le 22/12/2020 à 05:35, Viresh Kumar a écrit :
> 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;
>
Personlaly, I prefer what I have proposed. Having a clear and dedicated
error handling path is more future proff, IMHO.
>> }
>>
>> 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.
Ok, I agree (see my comment below the --- in my patch).
I'll send a patch for it when the first patch will be applied, unless
you prefer if I resend as a serie.
CJ
>
>>
>> - priv = platform_get_drvdata(pdev);
>> - iounmap(priv->base);
>> - iounmap(priv->avs_intr_base);
>> + brcm_avs_prepare_uninit(pdev);
>>
>> return 0;
>> }
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-12-27 17:23 UTC|newest]
Thread overview: 5+ 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-21 23:00 ` Florian Fainelli
2020-12-22 4:35 ` Viresh Kumar
2020-12-27 17:22 ` Christophe JAILLET [this message]
2020-12-28 5:37 ` 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=a7e1f78c-b4c9-4ef5-7ca4-94a65fefd299@wanadoo.fr \
--to=christophe.jaillet@wanadoo.fr \
--cc=bcm-kernel-feedback-list@broadcom.com \
--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 \
--cc=viresh.kumar@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox