cpufreq: loongson2: Unregister platform_driver on failure
authorYuan Can <yuancan@huawei.com>
Wed, 16 Oct 2024 09:06:15 +0000 (17:06 +0800)
committerViresh Kumar <viresh.kumar@linaro.org>
Wed, 16 Oct 2024 09:50:21 +0000 (15:20 +0530)
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>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
drivers/cpufreq/loongson2_cpufreq.c

index 6a8e978..ed1a6db 100644 (file)
@@ -148,7 +148,9 @@ static int __init cpufreq_init(void)
 
        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;
        }