cpuidle: Introduce __cpuidle_unregister_device()
authorDaniel Lezcano <daniel.lezcano@linaro.org>
Wed, 12 Jun 2013 13:08:53 +0000 (15:08 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 15 Jul 2013 00:09:47 +0000 (02:09 +0200)
To reduce code duplication related to the unregistration of cpuidle
devices, introduce __cpuidle_unregister_device() and move all of the
unregistration code to that function.

[rjw: Changelog]
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpuidle/cpuidle.c

index 4deed977f2094db0058cb480f1911e3c38e41b1d..d78c6d89272f047e83e4f69ca2b07cbbc28731a5 100644 (file)
@@ -42,8 +42,6 @@ void disable_cpuidle(void)
        off = 1;
 }
 
-static int __cpuidle_register_device(struct cpuidle_device *dev);
-
 /**
  * cpuidle_play_dead - cpu off-lining
  *
@@ -357,6 +355,15 @@ void cpuidle_disable_device(struct cpuidle_device *dev)
 
 EXPORT_SYMBOL_GPL(cpuidle_disable_device);
 
+static void __cpuidle_unregister_device(struct cpuidle_device *dev)
+{
+       struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
+
+       list_del(&dev->device_list);
+       per_cpu(cpuidle_devices, dev->cpu) = NULL;
+       module_put(drv->owner);
+}
+
 /**
  * __cpuidle_register_device - internal register function called before register
  * and enable routines
@@ -374,24 +381,15 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
 
        per_cpu(cpuidle_devices, dev->cpu) = dev;
        list_add(&dev->device_list, &cpuidle_detected_devices);
-       ret = cpuidle_add_sysfs(dev);
-       if (ret)
-               goto err_sysfs;
 
        ret = cpuidle_coupled_register_device(dev);
-       if (ret)
-               goto err_coupled;
+       if (ret) {
+               __cpuidle_unregister_device(dev);
+               return ret;
+       }
 
        dev->registered = 1;
        return 0;
-
-err_coupled:
-       cpuidle_remove_sysfs(dev);
-err_sysfs:
-       list_del(&dev->device_list);
-       per_cpu(cpuidle_devices, dev->cpu) = NULL;
-       module_put(drv->owner);
-       return ret;
 }
 
 /**
@@ -407,22 +405,30 @@ int cpuidle_register_device(struct cpuidle_device *dev)
 
        mutex_lock(&cpuidle_lock);
 
-       if ((ret = __cpuidle_register_device(dev))) {
-               mutex_unlock(&cpuidle_lock);
-               return ret;
-       }
+       ret = __cpuidle_register_device(dev);
+       if (ret)
+               goto out_unlock;
+
+       ret = cpuidle_add_sysfs(dev);
+       if (ret)
+               goto out_unregister;
 
        ret = cpuidle_enable_device(dev);
-       if (ret) {
-               mutex_unlock(&cpuidle_lock);
-               return ret;
-       }
+       if (ret)
+               goto out_sysfs;
 
        cpuidle_install_idle_handler();
 
+out_unlock:
        mutex_unlock(&cpuidle_lock);
 
-       return 0;
+       return ret;
+
+out_sysfs:
+       cpuidle_remove_sysfs(dev);
+out_unregister:
+       __cpuidle_unregister_device(dev);
+       goto out_unlock;
 }
 
 EXPORT_SYMBOL_GPL(cpuidle_register_device);
@@ -433,8 +439,6 @@ EXPORT_SYMBOL_GPL(cpuidle_register_device);
  */
 void cpuidle_unregister_device(struct cpuidle_device *dev)
 {
-       struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
-
        if (dev->registered == 0)
                return;
 
@@ -443,14 +447,12 @@ void cpuidle_unregister_device(struct cpuidle_device *dev)
        cpuidle_disable_device(dev);
 
        cpuidle_remove_sysfs(dev);
-       list_del(&dev->device_list);
-       per_cpu(cpuidle_devices, dev->cpu) = NULL;
+
+       __cpuidle_unregister_device(dev);
 
        cpuidle_coupled_unregister_device(dev);
 
        cpuidle_resume_and_unlock();
-
-       module_put(drv->owner);
 }
 
 EXPORT_SYMBOL_GPL(cpuidle_unregister_device);