diff mbox series

cpufreq: loongson2: Unregister platform_driver on failure

Message ID 20241015131337.20159-1-yuancan@huawei.com (mailing list archive)
State Superseded
Headers show
Series cpufreq: loongson2: Unregister platform_driver on failure | expand

Commit Message

Yuan Can Oct. 15, 2024, 1:13 p.m. UTC
When cpufreq_register_driver() returns error, the cpufreq_init() returns
without unregister platform_driver, fix by add missing
platform_driver_unregister() when cpufreq_register_driver() failed.

Fixes: f8ede0f700f5 ("MIPS: Loongson 2F: Add CPU frequency scaling support")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
 drivers/cpufreq/loongson2_cpufreq.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Viresh Kumar Oct. 16, 2024, 5:59 a.m. UTC | #1
On 15-10-24, 21:13, Yuan Can wrote:
> When cpufreq_register_driver() returns error, the cpufreq_init() returns
> without unregister platform_driver, fix by add missing
> platform_driver_unregister() when cpufreq_register_driver() failed.
> 
> Fixes: f8ede0f700f5 ("MIPS: Loongson 2F: Add CPU frequency scaling support")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
>  drivers/cpufreq/loongson2_cpufreq.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/cpufreq/loongson2_cpufreq.c b/drivers/cpufreq/loongson2_cpufreq.c
> index 6a8e97896d38..1291db067559 100644
> --- a/drivers/cpufreq/loongson2_cpufreq.c
> +++ b/drivers/cpufreq/loongson2_cpufreq.c
> @@ -153,6 +153,9 @@ static int __init cpufreq_init(void)
>  		cpu_wait = loongson2_cpu_wait;
>  	}
>  
> +	if (ret)
> +		platform_driver_unregister(&platform_driver);
> +
>  	return ret;

diff --git a/drivers/cpufreq/loongson2_cpufreq.c b/drivers/cpufreq/loongson2_cpufreq.c
index 6a8e97896d38..6f8f647efded 100644
--- a/drivers/cpufreq/loongson2_cpufreq.c
+++ b/drivers/cpufreq/loongson2_cpufreq.c
@@ -147,8 +147,9 @@ static int __init cpufreq_init(void)
                                  CPUFREQ_TRANSITION_NOTIFIER);
 
        ret = cpufreq_register_driver(&loongson2_cpufreq_driver);
-
-       if (!ret && !nowait) {
+       if (ret) {
+               platform_driver_unregister(&platform_driver);
+       } else if (!nowait) {
                saved_cpu_wait = cpu_wait;
                cpu_wait = loongson2_cpu_wait;
        }

Maybe a bit like this instead ?
diff mbox series

Patch

diff --git a/drivers/cpufreq/loongson2_cpufreq.c b/drivers/cpufreq/loongson2_cpufreq.c
index 6a8e97896d38..1291db067559 100644
--- a/drivers/cpufreq/loongson2_cpufreq.c
+++ b/drivers/cpufreq/loongson2_cpufreq.c
@@ -153,6 +153,9 @@  static int __init cpufreq_init(void)
 		cpu_wait = loongson2_cpu_wait;
 	}
 
+	if (ret)
+		platform_driver_unregister(&platform_driver);
+
 	return ret;
 }