[CPUFREQ] Refactor locking in cpufreq_add_dev

Simplify this by moving the unlocking out of the error
paths into the exit path.

Signed-off-by: Dave Jones <davej@codemonkey.org.uk>
This commit is contained in:
Dave Jones 2008-03-05 14:07:34 -05:00
parent 905d77cd95
commit 4570911811
1 changed files with 11 additions and 23 deletions

View File

@ -799,7 +799,6 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
ret = cpufreq_driver->init(policy); ret = cpufreq_driver->init(policy);
if (ret) { if (ret) {
dprintk("initialization failed\n"); dprintk("initialization failed\n");
unlock_policy_rwsem_write(cpu);
goto err_out; goto err_out;
} }
policy->user_policy.min = policy->cpuinfo.min_freq; policy->user_policy.min = policy->cpuinfo.min_freq;
@ -822,7 +821,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
/* check for existing affected CPUs. They may not be aware /* check for existing affected CPUs. They may not be aware
* of it due to CPU Hotplug. * of it due to CPU Hotplug.
*/ */
managed_policy = cpufreq_cpu_get(j); managed_policy = cpufreq_cpu_get(j); // FIXME: Where is this released? What about error paths?
if (unlikely(managed_policy)) { if (unlikely(managed_policy)) {
/* Set proper policy_cpu */ /* Set proper policy_cpu */
@ -841,14 +840,11 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
ret = sysfs_create_link(&sys_dev->kobj, ret = sysfs_create_link(&sys_dev->kobj,
&managed_policy->kobj, &managed_policy->kobj,
"cpufreq"); "cpufreq");
if (ret) { if (ret)
unlock_policy_rwsem_write(cpu);
goto err_out_driver_exit; goto err_out_driver_exit;
}
cpufreq_debug_enable_ratelimit(); cpufreq_debug_enable_ratelimit();
ret = 0; ret = 0;
unlock_policy_rwsem_write(cpu);
goto err_out_driver_exit; /* call driver->exit() */ goto err_out_driver_exit; /* call driver->exit() */
} }
} }
@ -858,33 +854,26 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
/* prepare interface data */ /* prepare interface data */
ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, &sys_dev->kobj, ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, &sys_dev->kobj,
"cpufreq"); "cpufreq");
if (ret) { if (ret)
unlock_policy_rwsem_write(cpu);
goto err_out_driver_exit; goto err_out_driver_exit;
}
/* set up files for this cpu device */ /* set up files for this cpu device */
drv_attr = cpufreq_driver->attr; drv_attr = cpufreq_driver->attr;
while ((drv_attr) && (*drv_attr)) { while ((drv_attr) && (*drv_attr)) {
ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
if (ret) { if (ret)
unlock_policy_rwsem_write(cpu);
goto err_out_driver_exit; goto err_out_driver_exit;
}
drv_attr++; drv_attr++;
} }
if (cpufreq_driver->get){ if (cpufreq_driver->get) {
ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
if (ret) { if (ret)
unlock_policy_rwsem_write(cpu);
goto err_out_driver_exit; goto err_out_driver_exit;
}
} }
if (cpufreq_driver->target){ if (cpufreq_driver->target) {
ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
if (ret) { if (ret)
unlock_policy_rwsem_write(cpu);
goto err_out_driver_exit; goto err_out_driver_exit;
}
} }
spin_lock_irqsave(&cpufreq_driver_lock, flags); spin_lock_irqsave(&cpufreq_driver_lock, flags);
@ -906,10 +895,8 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
cpu_sys_dev = get_cpu_sysdev(j); cpu_sys_dev = get_cpu_sysdev(j);
ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj, ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj,
"cpufreq"); "cpufreq");
if (ret) { if (ret)
unlock_policy_rwsem_write(cpu);
goto err_out_unregister; goto err_out_unregister;
}
} }
policy->governor = NULL; /* to assure that the starting sequence is policy->governor = NULL; /* to assure that the starting sequence is
@ -949,6 +936,7 @@ err_out_driver_exit:
cpufreq_driver->exit(policy); cpufreq_driver->exit(policy);
err_out: err_out:
unlock_policy_rwsem_write(cpu);
kfree(policy); kfree(policy);
nomem_out: nomem_out: