From dc3ae213662a6771329c37c20e1fca6febaabf24 Mon Sep 17 00:00:00 2001
From: Alexandre Oliva <lxoliva@fsfla.org>
Date: Fri, 22 Aug 2014 22:11:21 +0000
Subject: loongson2 cpufreq: unregister on init failure

If the loongson2_cpufreq module fails to init, e.g. because
any of the cpufreq_register functions fail, it must unregister
so that the module is unloaded successfully and no misinitialized
device remains in the udev device list.  Fixed.

Signed-off-by: Alexandre Oliva <lxoliva@fsfla.org>
---
diff --git a/drivers/cpufreq/loongson2_cpufreq.c b/drivers/cpufreq/loongson2_cpufreq.c
index d4add86..f1dc611 100644
--- a/drivers/cpufreq/loongson2_cpufreq.c
+++ b/drivers/cpufreq/loongson2_cpufreq.c
@@ -162,20 +162,32 @@ static int __init cpufreq_init(void)
 	/* Register platform stuff */
 	ret = platform_driver_register(&platform_driver);
 	if (ret)
-		return ret;
+		goto err_return;
 
 	pr_info("cpufreq: Loongson-2F CPU frequency driver.\n");
 
-	cpufreq_register_notifier(&loongson2_cpufreq_notifier_block,
-				  CPUFREQ_TRANSITION_NOTIFIER);
+	ret = cpufreq_register_notifier(&loongson2_cpufreq_notifier_block,
+					CPUFREQ_TRANSITION_NOTIFIER);
+	if (ret)
+		goto err_platform_driver_unregister;
 
 	ret = cpufreq_register_driver(&loongson2_cpufreq_driver);
+	if (ret)
+		goto err_cpufreq_unregister_notifier;
 
-	if (!ret && !nowait) {
+	if (!nowait) {
 		saved_cpu_wait = cpu_wait;
 		cpu_wait = loongson2_cpu_wait;
 	}
 
+	return 0;
+
+ err_cpufreq_unregister_notifier:
+	cpufreq_unregister_notifier(&loongson2_cpufreq_notifier_block,
+				    CPUFREQ_TRANSITION_NOTIFIER);
+ err_platform_driver_unregister:
+	platform_driver_unregister(&platform_driver);
+ err_return:
 	return ret;
 }
 
--
cgit v0.9.0.2
