Skip to content

Commit 7b1b796

Browse files
committed
cpuidle: Fail cpuidle device registration if there is one already
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 <rafael.j.wysocki@intel.com>
1 parent 8dba0fd commit 7b1b796

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

drivers/cpuidle/cpuidle.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,14 @@ static void __cpuidle_device_init(struct cpuidle_device *dev)
635635
static int __cpuidle_register_device(struct cpuidle_device *dev)
636636
{
637637
struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
638+
unsigned int cpu = dev->cpu;
638639
int i, ret;
639640

641+
if (per_cpu(cpuidle_devices, cpu)) {
642+
pr_info("CPU%d: cpuidle device already registered\n", cpu);
643+
return -EEXIST;
644+
}
645+
640646
if (!try_module_get(drv->owner))
641647
return -EINVAL;
642648

@@ -648,7 +654,7 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
648654
dev->states_usage[i].disable |= CPUIDLE_STATE_DISABLED_BY_USER;
649655
}
650656

651-
per_cpu(cpuidle_devices, dev->cpu) = dev;
657+
per_cpu(cpuidle_devices, cpu) = dev;
652658
list_add(&dev->device_list, &cpuidle_detected_devices);
653659

654660
ret = cpuidle_coupled_register_device(dev);

0 commit comments

Comments
 (0)