ACPI: processor: idle: Fix and cleanup
Subsystems (2)
Rafael J. Wysocki
maintainercover 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!
Rafael J. Wysocki
maintainerPATCH 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).
---
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(structif (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);
Rafael J. Wysocki
maintainerRe: [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 toacpi_processor_driver_init()andacpi_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 callingacpi_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")Signed-off-by Rafael J. Wysocki <[email protected]>---
Commit
7a8c994cbb2dis 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(structif (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);
lihuisong (C)
Acked-byRe: [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 toacpi_processor_driver_init()andacpi_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 callingacpi_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")Signed-off-by Rafael J. Wysocki <[email protected]>---
Commit
7a8c994cbb2dis 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(structif (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);
Rafael J. Wysocki
maintainerPATCH 2/2 ACPI: processor: idle: Redefine two functions as void
In reply to Rafael J. WysockiFrom: 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_drivcpuidle_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 );
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()andacpi_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.
Signed-off-by Rafael J. Wysocki <[email protected]>
LGTM,
Quoted 3 lines
Quoted 12 lines · Rafael J. Wysocki
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!