Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

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
Loading
Loading
Loading
Loading
+82 −63
Original line number Diff line number Diff line
@@ -72,25 +72,21 @@ 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
 * framework. It relies on core code to parse the idle states
 * 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_device *dev;

	for_each_possible_cpu(cpu) {

	drv = kmemdup(&arm_idle_driver, sizeof(*drv), GFP_KERNEL);
		if (!drv) {
			ret = -ENOMEM;
			goto out_fail;
		}
	if (!drv)
		return -ENOMEM;

	drv->cpumask = (struct cpumask *)cpumask_of(cpu);

@@ -124,7 +120,7 @@ static int __init arm_idle_init(void)
	 * failure is a HW misconfiguration/breakage (-ENXIO).
	 */
	if (ret == -ENXIO)
			continue;
		return 0;

	if (ret) {
		pr_err("CPU %d failed to init idle CPU ops\n", cpu);
@@ -145,7 +141,6 @@ static int __init arm_idle_init(void)
		       cpu);
		goto out_kfree_dev;
	}
	}

	return 0;

@@ -155,6 +150,30 @@ static int __init arm_idle_init(void)
	cpuidle_unregister_driver(drv);
out_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:
	while (--cpu >= 0) {
		dev = per_cpu(cpuidle_devices, cpu);