All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the probe function
@ 2020-12-19 10:17 ` Christophe JAILLET
  0 siblings, 0 replies; 15+ messages in thread
From: Christophe JAILLET @ 2020-12-19 10:17 UTC (permalink / raw)
  To: mmayer, bcm-kernel-feedback-list, rjw, viresh.kumar, f.fainelli
  Cc: linux-pm, linux-arm-kernel, linux-kernel, kernel-janitors,
	Christophe JAILLET

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;
 }
 
 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;
 
-	priv = platform_get_drvdata(pdev);
-	iounmap(priv->base);
-	iounmap(priv->avs_intr_base);
+	brcm_avs_prepare_uninit(pdev);
 
 	return 0;
 }
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2020-12-28  5:49 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the probe function Viresh Kumar
2020-12-22  4:47   ` [PATCH] cpufreq: brcmstb-avs-cpufreq: Fix some resource leaks in the error handling path of the 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

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.