[PATCH v6 02/10] cpufreq: mediatek: Add platform_device_unregister when driver exit

Rex-BC Chen posted 10 patches 2 years, 4 months ago
There is a newer version of this series
[PATCH v6 02/10] cpufreq: mediatek: Add platform_device_unregister when driver exit
Posted by Rex-BC Chen 2 years, 4 months ago
We register the platform device when driver inits. However, we do not
unregister it when driver exits.
To resolve this, we declare the platform data to be a global static
variable and rename it to be "cpufreq_pdev".
With this global variable, we can do platform_device_unregister() when
driver exits.

Signed-off-by: Rex-BC Chen <rex-bc.chen@mediatek.com>
---
 drivers/cpufreq/mediatek-cpufreq.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
index 901042e9a240..d15cbef4a72e 100644
--- a/drivers/cpufreq/mediatek-cpufreq.c
+++ b/drivers/cpufreq/mediatek-cpufreq.c
@@ -43,6 +43,8 @@ struct mtk_cpu_dvfs_info {
 	int pre_vproc;
 };
 
+static struct platform_device *cpufreq_pdev;
+
 static LIST_HEAD(dvfs_info_list);
 
 static struct mtk_cpu_dvfs_info *mtk_cpu_dvfs_info_lookup(int cpu)
@@ -578,7 +580,6 @@ static int __init mtk_cpufreq_driver_init(void)
 {
 	struct device_node *np;
 	const struct of_device_id *match;
-	struct platform_device *pdev;
 	int err;
 
 	np = of_find_node_by_path("/");
@@ -602,11 +603,11 @@ static int __init mtk_cpufreq_driver_init(void)
 	 * and the device registration codes are put here to handle defer
 	 * probing.
 	 */
-	pdev = platform_device_register_simple("mtk-cpufreq", -1, NULL, 0);
-	if (IS_ERR(pdev)) {
+	cpufreq_pdev = platform_device_register_simple("mtk-cpufreq", -1, NULL, 0);
+	if (IS_ERR(cpufreq_pdev)) {
 		pr_err("failed to register mtk-cpufreq platform device\n");
 		platform_driver_unregister(&mtk_cpufreq_platdrv);
-		return PTR_ERR(pdev);
+		return PTR_ERR(cpufreq_pdev);
 	}
 
 	return 0;
@@ -615,6 +616,7 @@ module_init(mtk_cpufreq_driver_init)
 
 static void __exit mtk_cpufreq_driver_exit(void)
 {
+	platform_device_unregister(cpufreq_pdev);
 	platform_driver_unregister(&mtk_cpufreq_platdrv);
 }
 module_exit(mtk_cpufreq_driver_exit)
-- 
2.18.0
Re: [PATCH v6 02/10] cpufreq: mediatek: Add platform_device_unregister when driver exit
Posted by Viresh Kumar 2 years, 4 months ago
On 05-05-22, 19:52, Rex-BC Chen wrote:
> We register the platform device when driver inits. However, we do not
> unregister it when driver exits.
> To resolve this, we declare the platform data to be a global static
> variable and rename it to be "cpufreq_pdev".
> With this global variable, we can do platform_device_unregister() when
> driver exits.
> 
> Signed-off-by: Rex-BC Chen <rex-bc.chen@mediatek.com>
> ---
>  drivers/cpufreq/mediatek-cpufreq.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)

Applied. Thanks.

-- 
viresh
Re: [PATCH v6 02/10] cpufreq: mediatek: Add platform_device_unregister when driver exit
Posted by AngeloGioacchino Del Regno 2 years, 4 months ago
Il 05/05/22 13:52, Rex-BC Chen ha scritto:
> We register the platform device when driver inits. However, we do not
> unregister it when driver exits.
> To resolve this, we declare the platform data to be a global static
> variable and rename it to be "cpufreq_pdev".
> With this global variable, we can do platform_device_unregister() when
> driver exits.
> 
> Signed-off-by: Rex-BC Chen <rex-bc.chen@mediatek.com>

Hello Rex,
this commit needs a Fixes: tag.

Cheers,
Angelo
Re: [PATCH v6 02/10] cpufreq: mediatek: Add platform_device_unregister when driver exit
Posted by Rex-BC Chen 2 years, 4 months ago
On Thu, 2022-05-05 at 17:04 +0200, AngeloGioacchino Del Regno wrote:
> Il 05/05/22 13:52, Rex-BC Chen ha scritto:
> > We register the platform device when driver inits. However, we do
> > not
> > unregister it when driver exits.
> > To resolve this, we declare the platform data to be a global static
> > variable and rename it to be "cpufreq_pdev".
> > With this global variable, we can do platform_device_unregister()
> > when
> > driver exits.
> > 
> > Signed-off-by: Rex-BC Chen <rex-bc.chen@mediatek.com>
> 
> Hello Rex,
> this commit needs a Fixes: tag.
> 
> Cheers,
> Angelo
> 

Hello Angelo,

Thanks for the reminder.
I will add "Fixes: 501c574f4e3a ("cpufreq: mediatek: Add support of
cpufreq to MT2701/MT7623 SoC")"

BRs,
Rex