Skip to content

Commit 67464cd

Browse files
rafaeljwSasha Levin
authored andcommitted
cpuidle: Fail cpuidle device registration if there is one already
[ Upstream commit 7b1b796 ] Refuse to register a cpuidle device if the given CPU has a cpuidle device already and print a message regarding it. Without this, an attempt to register a new cpuidle device without unregistering the existing one leads to the removal of the existing cpuidle device without removing its sysfs interface. Signed-off-by: Rafael J. Wysocki <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 0bcbcb3 commit 67464cd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/cpuidle/cpuidle.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,14 @@ static void __cpuidle_device_init(struct cpuidle_device *dev)
631631
static int __cpuidle_register_device(struct cpuidle_device *dev)
632632
{
633633
struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
634+
unsigned int cpu = dev->cpu;
634635
int i, ret;
635636

637+
if (per_cpu(cpuidle_devices, cpu)) {
638+
pr_info("CPU%d: cpuidle device already registered\n", cpu);
639+
return -EEXIST;
640+
}
641+
636642
if (!try_module_get(drv->owner))
637643
return -EINVAL;
638644

@@ -644,7 +650,7 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
644650
dev->states_usage[i].disable |= CPUIDLE_STATE_DISABLED_BY_USER;
645651
}
646652

647-
per_cpu(cpuidle_devices, dev->cpu) = dev;
653+
per_cpu(cpuidle_devices, cpu) = dev;
648654
list_add(&dev->device_list, &cpuidle_detected_devices);
649655

650656
ret = cpuidle_coupled_register_device(dev);

0 commit comments

Comments
 (0)