Commit 7943bfae authored by Leo Yan's avatar Leo Yan Committed by Rafael J. Wysocki

ARM: cpuidle: Refactor rollback operations if init fails

If init fails, we need execute two levels rollback operations: the first
level is for the failed CPU rollback operations, the second level is to
iterate all succeeded CPUs to cancel their registration; currently the
code uses one function to finish these two levels rollback operations.

This commit is to refactor rollback operations, so it adds a new
function arm_idle_init_cpu() to encapsulate one specified CPU driver
registration and rollback the first level operations; and use function
arm_idle_init() to iterate all CPUs and finish the second level's
rollback operations.
Suggested-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: default avatarLeo Yan <leo.yan@linaro.org>
Acked-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 0f87855d
...@@ -72,79 +72,74 @@ static const struct of_device_id arm_idle_state_match[] __initconst = { ...@@ -72,79 +72,74 @@ static const struct of_device_id arm_idle_state_match[] __initconst = {
}; };
/* /*
* arm_idle_init * arm_idle_init_cpu
* *
* Registers the arm specific cpuidle driver with the cpuidle * Registers the arm specific cpuidle driver with the cpuidle
* framework. It relies on core code to parse the idle states * framework. It relies on core code to parse the idle states
* and initialize them using driver data structures accordingly. * and initialize them using driver data structures accordingly.
*/ */
static int __init arm_idle_init(void) static int __init arm_idle_init_cpu(int cpu)
{ {
int cpu, ret; int ret;
struct cpuidle_driver *drv; struct cpuidle_driver *drv;
struct cpuidle_device *dev; struct cpuidle_device *dev;
for_each_possible_cpu(cpu) { drv = kmemdup(&arm_idle_driver, sizeof(*drv), GFP_KERNEL);
if (!drv)
return -ENOMEM;
drv = kmemdup(&arm_idle_driver, sizeof(*drv), GFP_KERNEL); drv->cpumask = (struct cpumask *)cpumask_of(cpu);
if (!drv) {
ret = -ENOMEM; /*
goto out_fail; * Initialize idle states data, starting at index 1. This
} * driver is DT only, if no DT idle states are detected (ret
* == 0) let the driver initialization fail accordingly since
drv->cpumask = (struct cpumask *)cpumask_of(cpu); * there is no reason to initialize the idle driver if only
* wfi is supported.
/* */
* Initialize idle states data, starting at index 1. This ret = dt_init_idle_driver(drv, arm_idle_state_match, 1);
* driver is DT only, if no DT idle states are detected (ret if (ret <= 0) {
* == 0) let the driver initialization fail accordingly since ret = ret ? : -ENODEV;
* there is no reason to initialize the idle driver if only goto out_kfree_drv;
* wfi is supported. }
*/
ret = dt_init_idle_driver(drv, arm_idle_state_match, 1); ret = cpuidle_register_driver(drv);
if (ret <= 0) { if (ret) {
ret = ret ? : -ENODEV; pr_err("Failed to register cpuidle driver\n");
goto out_kfree_drv; goto out_kfree_drv;
} }
ret = cpuidle_register_driver(drv); /*
if (ret) { * Call arch CPU operations in order to initialize
pr_err("Failed to register cpuidle driver\n"); * idle states suspend back-end specific data
goto out_kfree_drv; */
} ret = arm_cpuidle_init(cpu);
/* /*
* Call arch CPU operations in order to initialize * Skip the cpuidle device initialization if the reported
* idle states suspend back-end specific data * failure is a HW misconfiguration/breakage (-ENXIO).
*/ */
ret = arm_cpuidle_init(cpu); if (ret == -ENXIO)
return 0;
/*
* Skip the cpuidle device initialization if the reported if (ret) {
* failure is a HW misconfiguration/breakage (-ENXIO). pr_err("CPU %d failed to init idle CPU ops\n", cpu);
*/ goto out_unregister_drv;
if (ret == -ENXIO) }
continue;
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (ret) { if (!dev) {
pr_err("CPU %d failed to init idle CPU ops\n", cpu); pr_err("Failed to allocate cpuidle device\n");
goto out_unregister_drv; ret = -ENOMEM;
} goto out_unregister_drv;
}
dev = kzalloc(sizeof(*dev), GFP_KERNEL); dev->cpu = cpu;
if (!dev) {
pr_err("Failed to allocate cpuidle device\n"); ret = cpuidle_register_device(dev);
ret = -ENOMEM; if (ret) {
goto out_unregister_drv; pr_err("Failed to register cpuidle device for CPU %d\n",
} cpu);
dev->cpu = cpu; goto out_kfree_dev;
ret = cpuidle_register_device(dev);
if (ret) {
pr_err("Failed to register cpuidle device for CPU %d\n",
cpu);
goto out_kfree_dev;
}
} }
return 0; return 0;
...@@ -155,6 +150,30 @@ static int __init arm_idle_init(void) ...@@ -155,6 +150,30 @@ static int __init arm_idle_init(void)
cpuidle_unregister_driver(drv); cpuidle_unregister_driver(drv);
out_kfree_drv: out_kfree_drv:
kfree(drv); kfree(drv);
return ret;
}
/*
* arm_idle_init - Initializes arm cpuidle driver
*
* Initializes arm cpuidle driver for all CPUs, if any CPU fails
* to register cpuidle driver then rollback to cancel all CPUs
* registeration.
*/
static int __init arm_idle_init(void)
{
int cpu, ret;
struct cpuidle_driver *drv;
struct cpuidle_device *dev;
for_each_possible_cpu(cpu) {
ret = arm_idle_init_cpu(cpu);
if (ret)
goto out_fail;
}
return 0;
out_fail: out_fail:
while (--cpu >= 0) { while (--cpu >= 0) {
dev = per_cpu(cpuidle_devices, cpu); dev = per_cpu(cpuidle_devices, cpu);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment