]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cpuidle: Fail cpuidle device registration if there is one already
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 19 Sep 2025 11:22:20 +0000 (13:22 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Nov 2025 20:34:06 +0000 (15:34 -0500)
[ Upstream commit 7b1b7961170e4fcad488755e5ffaaaf9bd527e8f ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/cpuidle/cpuidle.c

index 9e418aec17550e87fa257c23c6f4ebff0e3661f5..0e1bbc966135d90f578fe284a94fe57d4b922309 100644 (file)
@@ -631,8 +631,14 @@ static void __cpuidle_device_init(struct cpuidle_device *dev)
 static int __cpuidle_register_device(struct cpuidle_device *dev)
 {
        struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
+       unsigned int cpu = dev->cpu;
        int i, ret;
 
+       if (per_cpu(cpuidle_devices, cpu)) {
+               pr_info("CPU%d: cpuidle device already registered\n", cpu);
+               return -EEXIST;
+       }
+
        if (!try_module_get(drv->owner))
                return -EINVAL;
 
@@ -644,7 +650,7 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
                        dev->states_usage[i].disable |= CPUIDLE_STATE_DISABLED_BY_USER;
        }
 
-       per_cpu(cpuidle_devices, dev->cpu) = dev;
+       per_cpu(cpuidle_devices, cpu) = dev;
        list_add(&dev->device_list, &cpuidle_detected_devices);
 
        ret = cpuidle_coupled_register_device(dev);