Skip to contentSkip to conversation

ACPI: processor: idle: Fix and cleanup

PATCH In review Rafael J. Wysocki 3 participants 7 messages Sep 18, 2025 – Sep 22, 2025

Subsystems (2)
lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

cover ACPI: processor: idle: Fix and cleanup

Hi All,

One of the recent changes forgot to update a cpuidle driver check in the ACPI processor driver, so fix this (first patch).

In addition, redefine two functions whose return values are ignored as void (second patch).

Thanks!

author maintainer
#1 lore raw

PATCH 1/2 ACPI: processor: Update cpuidle driver check in __acpi_processor_start()

From: Rafael J. Wysocki <[email protected]>

Commit 7a8c994cbb2d ("ACPI: processor: idle: Optimize ACPI idle driver registration") moved the ACPI idle driver registration to acpi_processor_driver_init() and acpi_processor_power_init() does not register an idle driver any more, so the cpuidle driver check in __acpi_processor_start() needs to be updated to avoid calling acpi_processor_power_init() without a cpuidle driver (in which case the registration of the cpuidle device in that function would fail anyway).

Fixes 7a8c994cbb2d ("ACPI: processor: idle: Optimize ACPI idle driver registration")

---

Commit 7a8c994cbb2d is only in linux-next at this point.

---
 drivers/acpi/processor_driver.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/processor_driver.c +1 -1
@@ -166,7 +166,7 @@ static int __acpi_processor_start(struct
 	if (result && !IS_ENABLED(CONFIG_ACPI_CPU_FREQ_PSS))
 		dev_dbg(&device->dev, "CPPC data invalid or not present\n");
 
-	if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
+	if (cpuidle_get_driver() == &acpi_idle_driver)
 		acpi_processor_power_init(pr);
 
 	acpi_pss_perf_init(pr);
author maintainer
#2 lore raw

Re: [PATCH v1 1/2] ACPI: processor: Update cpuidle driver check in __acpi_processor_start()

Quoted 11 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 7a8c994cbb2d ("ACPI: processor: idle: Optimize ACPI idle driver registration") moved the ACPI idle driver registration to acpi_processor_driver_init() and acpi_processor_power_init() does not register an idle driver any more, so the cpuidle driver check in __acpi_processor_start() needs to be updated to avoid calling acpi_processor_power_init() without a cpuidle driver (in which case the registration of the cpuidle device in that function would fail anyway).

It's worse, it won't just fail, it'll lead to a NULL pointer dereference in __cpuidle_register_device().

I'll update the changelog while applying the patch.

Quoted 25 lines
Fixes 7a8c994cbb2d ("ACPI: processor: idle: Optimize ACPI idle driver registration")

---

Commit 7a8c994cbb2d is only in linux-next at this point.

---
 drivers/acpi/processor_driver.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/processor_driver.c +1 -1
@@ -166,7 +166,7 @@ static int __acpi_processor_start(struct
        if (result && !IS_ENABLED(CONFIG_ACPI_CPU_FREQ_PSS))
                dev_dbg(&device->dev, "CPPC data invalid or not present\n");
 
-       if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
+       if (cpuidle_get_driver() == &acpi_idle_driver)
                acpi_processor_power_init(pr);
 
        acpi_pss_perf_init(pr);
Acked-by
#3 lore raw

Re: [PATCH v1 1/2] ACPI: processor: Update cpuidle driver check in __acpi_processor_start()

Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 7a8c994cbb2d ("ACPI: processor: idle: Optimize ACPI idle driver registration") moved the ACPI idle driver registration to acpi_processor_driver_init() and acpi_processor_power_init() does not register an idle driver any more, so the cpuidle driver check in __acpi_processor_start() needs to be updated to avoid calling acpi_processor_power_init() without a cpuidle driver (in which case the registration of the cpuidle device in that function would fail anyway).

Quoted 4 lines

It's worse, it won't just fail, it'll lead to a NULL pointer dereference in __cpuidle_register_device().

I'll update the changelog while applying the patch.

Yeah, thanks for fixing it.

Quoted 26 lines
Quoted 26 lines
Fixes 7a8c994cbb2d ("ACPI: processor: idle: Optimize ACPI idle driver registration")

---

Commit 7a8c994cbb2d is only in linux-next at this point.

---
  drivers/acpi/processor_driver.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/processor_driver.c +1 -1
@@ -166,7 +166,7 @@ static int __acpi_processor_start(struct
         if (result && !IS_ENABLED(CONFIG_ACPI_CPU_FREQ_PSS))
                 dev_dbg(&device->dev, "CPPC data invalid or not present\n");
 
-       if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
+       if (cpuidle_get_driver() == &acpi_idle_driver)
                 acpi_processor_power_init(pr);
 
         acpi_pss_perf_init(pr);
author maintainer
#4 lore raw

PATCH 2/2 ACPI: processor: idle: Redefine two functions as void

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Notice that acpi_processor_power_init() and acpi_processor_power_exit() don't need to return any values because their callers don't check them anyway, so redefine those functions as void.

While at it, rearrange the code in acpi_processor_power_init() to reduce the indentation level, get rid of a redundant local variable in that function, and rephrase a code comment in it.

No intentional functional impact.

---
 drivers/acpi/processor_idle.c |   47 +++++++++++++++++++-----------------------
 include/acpi/processor.h      |    4 +--
 2 files changed, 24 insertions(+), 27 deletions(-)
drivers/acpi/processor_idle.c +22 -25
@@ -1137,47 +1137,45 @@ void acpi_processor_unregister_idle_driv
 	cpuidle_unregister_driver(&acpi_idle_driver);
 }
 
-int acpi_processor_power_init(struct acpi_processor *pr)
+void acpi_processor_power_init(struct acpi_processor *pr)
 {
-	int retval;
 	struct cpuidle_device *dev;
 
 	if (disabled_by_idle_boot_param())
-		return 0;
+		return;
 
 	acpi_processor_cstate_first_run_checks();
 
 	if (!acpi_processor_get_power_info(pr))
 		pr->flags.power_setup_done = 1;
 
-	if (pr->flags.power) {
-		dev = kzalloc(sizeof(*dev), GFP_KERNEL);
-		if (!dev)
-			return -ENOMEM;
-		per_cpu(acpi_cpuidle_device, pr->id) = dev;
-
-		acpi_processor_setup_cpuidle_dev(pr, dev);
-
-		/* Register per-cpu cpuidle_device. Cpuidle driver
-		 * must already be registered before registering device
-		 */
-		retval = cpuidle_register_device(dev);
-		if (retval) {
-
-			per_cpu(acpi_cpuidle_device, pr->id) = NULL;
-			kfree(dev);
-			return retval;
-		}
+	if (!pr->flags.power)
+		return;
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return;
+
+	per_cpu(acpi_cpuidle_device, pr->id) = dev;
+
+	acpi_processor_setup_cpuidle_dev(pr, dev);
+
+	/*
+	 * Register a cpuidle device for this CPU.  The cpuidle driver using
+	 * this device is expected to be registered.
+	 */
+	if (cpuidle_register_device(dev)) {
+		per_cpu(acpi_cpuidle_device, pr->id) = NULL;
+		kfree(dev);
 	}
-	return 0;
 }
 
-int acpi_processor_power_exit(struct acpi_processor *pr)
+void acpi_processor_power_exit(struct acpi_processor *pr)
 {
 	struct cpuidle_device *dev = per_cpu(acpi_cpuidle_device, pr->id);
 
 	if (disabled_by_idle_boot_param())
-		return 0;
+		return;
 
 	if (pr->flags.power) {
 		cpuidle_unregister_device(dev);
@@ -1185,7 +1183,6 @@ int acpi_processor_power_exit(struct acp
 	}
 
 	pr->flags.power_setup_done = 0;
-	return 0;
 }
 
 MODULE_IMPORT_NS("ACPI_PROCESSOR_IDLE");
include/acpi/processor.h +2 -2
@@ -419,8 +419,8 @@ static inline void acpi_processor_thrott
 /* in processor_idle.c */
 extern struct cpuidle_driver acpi_idle_driver;
 #ifdef CONFIG_ACPI_PROCESSOR_IDLE
-int acpi_processor_power_init(struct acpi_processor *pr);
-int acpi_processor_power_exit(struct acpi_processor *pr);
+void acpi_processor_power_init(struct acpi_processor *pr);
+void acpi_processor_power_exit(struct acpi_processor *pr);
 int acpi_processor_power_state_has_changed(struct acpi_processor *pr);
 int acpi_processor_hotplug(struct acpi_processor *pr);
 void acpi_processor_register_idle_driver(void);
Acked-by on v1 2/2
#5 lore raw

Re: [PATCH v1 2/2] ACPI: processor: idle: Redefine two functions as void

Quoted 6 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Notice that acpi_processor_power_init() and acpi_processor_power_exit() don't need to return any values because their callers don't check them anyway, so redefine those functions as void.

Quoted 7 lines

While at it, rearrange the code in acpi_processor_power_init() to reduce the indentation level, get rid of a redundant local variable in that function, and rephrase a code comment in it.

No intentional functional impact.

LGTM,

Quoted 3 lines