diff mbox

[2/4] cpuidle - sysfs : move kobj initialization in the syfs file

Message ID 1349907691-6002-3-git-send-email-daniel.lezcano@linaro.org
State Accepted
Commit e45a00d679a788217f35ee4214a32d6d1924160b
Headers show

Commit Message

Daniel Lezcano Oct. 10, 2012, 10:21 p.m. UTC
Move the kobj initialization and completion in the sysfs.c
and encapsulate the code more.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/cpuidle/cpuidle.c |    4 ----
 drivers/cpuidle/sysfs.c   |    7 +++++--
 2 files changed, 5 insertions(+), 6 deletions(-)

Comments

Rafael J. Wysocki Oct. 17, 2012, 5:46 a.m. UTC | #1
On Thursday 11 of October 2012 00:21:29 Daniel Lezcano wrote:
> Move the kobj initialization and completion in the sysfs.c
> and encapsulate the code more.
> 
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

I like this one too and I'm going to take it for v3.8 as well.

Thanks,
Rafael


> ---
>  drivers/cpuidle/cpuidle.c |    4 ----
>  drivers/cpuidle/sysfs.c   |    7 +++++--
>  2 files changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
> index 07c6637..7cf8388 100644
> --- a/drivers/cpuidle/cpuidle.c
> +++ b/drivers/cpuidle/cpuidle.c
> @@ -399,8 +399,6 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
>  	if (!try_module_get(cpuidle_driver->owner))
>  		return -EINVAL;
>  
> -	init_completion(&dev->kobj_unregister);
> -
>  	per_cpu(cpuidle_devices, dev->cpu) = dev;
>  	list_add(&dev->device_list, &cpuidle_detected_devices);
>  	ret = cpuidle_add_sysfs(dev);
> @@ -416,7 +414,6 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
>  
>  err_coupled:
>  	cpuidle_remove_sysfs(dev);
> -	wait_for_completion(&dev->kobj_unregister);
>  err_sysfs:
>  	list_del(&dev->device_list);
>  	per_cpu(cpuidle_devices, dev->cpu) = NULL;
> @@ -470,7 +467,6 @@ void cpuidle_unregister_device(struct cpuidle_device *dev)
>  
>  	cpuidle_remove_sysfs(dev);
>  	list_del(&dev->device_list);
> -	wait_for_completion(&dev->kobj_unregister);
>  	per_cpu(cpuidle_devices, dev->cpu) = NULL;
>  
>  	cpuidle_coupled_unregister_device(dev);
> diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
> index 84e6285..ed87399 100644
> --- a/drivers/cpuidle/sysfs.c
> +++ b/drivers/cpuidle/sysfs.c
> @@ -374,8 +374,8 @@ int cpuidle_add_state_sysfs(struct cpuidle_device *device)
>  		kobj->state_usage = &device->states_usage[i];
>  		init_completion(&kobj->kobj_unregister);
>  
> -		ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle, &device->kobj,
> -					   "state%d", i);
> +		ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle,
> +					   &device->kobj, "state%d", i);
>  		if (ret) {
>  			kfree(kobj);
>  			goto error_state;
> @@ -413,6 +413,8 @@ int cpuidle_add_sysfs(struct cpuidle_device *dev)
>  	struct device *cpu_dev = get_cpu_device((unsigned long)dev->cpu);
>  	int error;
>  
> +	init_completion(&dev->kobj_unregister);
> +
>  	error = kobject_init_and_add(&dev->kobj, &ktype_cpuidle, &cpu_dev->kobj,
>  				     "cpuidle");
>  	if (!error)
> @@ -427,4 +429,5 @@ int cpuidle_add_sysfs(struct cpuidle_device *dev)
>  void cpuidle_remove_sysfs(struct cpuidle_device *dev)
>  {
>  	kobject_put(&dev->kobj);
> +	wait_for_completion(&dev->kobj_unregister);
>  }
>
diff mbox

Patch

diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 07c6637..7cf8388 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -399,8 +399,6 @@  static int __cpuidle_register_device(struct cpuidle_device *dev)
 	if (!try_module_get(cpuidle_driver->owner))
 		return -EINVAL;
 
-	init_completion(&dev->kobj_unregister);
-
 	per_cpu(cpuidle_devices, dev->cpu) = dev;
 	list_add(&dev->device_list, &cpuidle_detected_devices);
 	ret = cpuidle_add_sysfs(dev);
@@ -416,7 +414,6 @@  static int __cpuidle_register_device(struct cpuidle_device *dev)
 
 err_coupled:
 	cpuidle_remove_sysfs(dev);
-	wait_for_completion(&dev->kobj_unregister);
 err_sysfs:
 	list_del(&dev->device_list);
 	per_cpu(cpuidle_devices, dev->cpu) = NULL;
@@ -470,7 +467,6 @@  void cpuidle_unregister_device(struct cpuidle_device *dev)
 
 	cpuidle_remove_sysfs(dev);
 	list_del(&dev->device_list);
-	wait_for_completion(&dev->kobj_unregister);
 	per_cpu(cpuidle_devices, dev->cpu) = NULL;
 
 	cpuidle_coupled_unregister_device(dev);
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index 84e6285..ed87399 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -374,8 +374,8 @@  int cpuidle_add_state_sysfs(struct cpuidle_device *device)
 		kobj->state_usage = &device->states_usage[i];
 		init_completion(&kobj->kobj_unregister);
 
-		ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle, &device->kobj,
-					   "state%d", i);
+		ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle,
+					   &device->kobj, "state%d", i);
 		if (ret) {
 			kfree(kobj);
 			goto error_state;
@@ -413,6 +413,8 @@  int cpuidle_add_sysfs(struct cpuidle_device *dev)
 	struct device *cpu_dev = get_cpu_device((unsigned long)dev->cpu);
 	int error;
 
+	init_completion(&dev->kobj_unregister);
+
 	error = kobject_init_and_add(&dev->kobj, &ktype_cpuidle, &cpu_dev->kobj,
 				     "cpuidle");
 	if (!error)
@@ -427,4 +429,5 @@  int cpuidle_add_sysfs(struct cpuidle_device *dev)
 void cpuidle_remove_sysfs(struct cpuidle_device *dev)
 {
 	kobject_put(&dev->kobj);
+	wait_for_completion(&dev->kobj_unregister);
 }