* [PATCH v3 0/2] ACPI: processor: idle: Optimize acpi idle driver registration
@ 2025-07-28 7:06 Huisong Li
2025-07-28 7:06 ` [PATCH v3 1/2] ACPI: processor: idle: Fix memory leak when register cpuidle device failed Huisong Li
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Huisong Li @ 2025-07-28 7:06 UTC (permalink / raw)
To: rafael, lenb
Cc: linux-acpi, linux-kernel, linuxarm, jonathan.cameron, zhanjie9,
zhenglifeng1, yubowen8, liuyonglong, lihuisong
This series fix a memory leak issue and optimize the registration of
acpi idle driver to enhance its readability.
---
changelog:
v3:
* use a separate patch to fix memory leak.
* change the return value of the new function to void.
* change log level to debug on failure path.
v2:
* register cpuidle driver in advance when all of the CPUs have been
brought up.
https://patchwork.kernel.org/project/linux-acpi/patch/20250723121034.3685996-1-lihuisong@huawei.com/
v1:
https://patchwork.kernel.org/project/linux-acpi/patch/20250619061327.1674384-1-lihuisong@huawei.com/
Huisong Li (2):
ACPI: processor: idle: Fix memory leak when register cpuidle device
failed
ACPI: processor: idle: Optimize acpi idle driver registration
drivers/acpi/processor_driver.c | 3 ++
drivers/acpi/processor_idle.c | 67 ++++++++++++++++++++++-----------
include/acpi/processor.h | 8 ++++
3 files changed, 55 insertions(+), 23 deletions(-)
--
2.33.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 1/2] ACPI: processor: idle: Fix memory leak when register cpuidle device failed
2025-07-28 7:06 [PATCH v3 0/2] ACPI: processor: idle: Optimize acpi idle driver registration Huisong Li
@ 2025-07-28 7:06 ` Huisong Li
2025-08-22 19:27 ` Rafael J. Wysocki
2025-07-28 7:06 ` [PATCH v3 2/2] ACPI: processor: idle: Optimize acpi idle driver registration Huisong Li
2025-08-19 11:07 ` [PATCH v3 0/2] " lihuisong (C)
2 siblings, 1 reply; 7+ messages in thread
From: Huisong Li @ 2025-07-28 7:06 UTC (permalink / raw)
To: rafael, lenb
Cc: linux-acpi, linux-kernel, linuxarm, jonathan.cameron, zhanjie9,
zhenglifeng1, yubowen8, liuyonglong, lihuisong
The cpuidle device's memory has been leaked when register cpuidle
device failed in acpi_processor_power_init().
Fixes: 3d339dcbb56d ("cpuidle / ACPI : move cpuidle_device field out of the acpi_processor_power structure")
Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
drivers/acpi/processor_idle.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 2c2dc559e0f8..031738390f2d 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -1405,6 +1405,8 @@ int acpi_processor_power_init(struct acpi_processor *pr)
if (retval) {
if (acpi_processor_registered == 0)
cpuidle_unregister_driver(&acpi_idle_driver);
+ kfree(dev);
+ per_cpu(acpi_cpuidle_device, pr->id) = NULL;
return retval;
}
acpi_processor_registered++;
--
2.33.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 2/2] ACPI: processor: idle: Optimize acpi idle driver registration
2025-07-28 7:06 [PATCH v3 0/2] ACPI: processor: idle: Optimize acpi idle driver registration Huisong Li
2025-07-28 7:06 ` [PATCH v3 1/2] ACPI: processor: idle: Fix memory leak when register cpuidle device failed Huisong Li
@ 2025-07-28 7:06 ` Huisong Li
2025-08-23 16:13 ` Rafael J. Wysocki
2025-08-19 11:07 ` [PATCH v3 0/2] " lihuisong (C)
2 siblings, 1 reply; 7+ messages in thread
From: Huisong Li @ 2025-07-28 7:06 UTC (permalink / raw)
To: rafael, lenb
Cc: linux-acpi, linux-kernel, linuxarm, jonathan.cameron, zhanjie9,
zhenglifeng1, yubowen8, liuyonglong, lihuisong
Currently, the acpi idle driver is registered from within a CPU
hotplug callback. Although this didn't cause any functional issues,
this is questionable and confusing. And it is better to register
the cpuidle driver when all of the CPUs have been brought up.
So add a new function to initialize acpi_idle_driver based on the
power management information of an available CPU and register cpuidle
driver in acpi_processor_driver_init().
Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
drivers/acpi/processor_driver.c | 3 ++
drivers/acpi/processor_idle.c | 65 +++++++++++++++++++++------------
include/acpi/processor.h | 8 ++++
3 files changed, 53 insertions(+), 23 deletions(-)
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 65e779be64ff..bc9f58a02c1d 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -263,6 +263,8 @@ static int __init acpi_processor_driver_init(void)
if (result < 0)
return result;
+ acpi_processor_register_idle_driver();
+
result = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
"acpi/cpu-drv:online",
acpi_soft_cpu_online, NULL);
@@ -301,6 +303,7 @@ static void __exit acpi_processor_driver_exit(void)
cpuhp_remove_state_nocalls(hp_online);
cpuhp_remove_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD);
+ acpi_processor_unregister_idle_driver();
driver_unregister(&acpi_processor_driver);
}
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 031738390f2d..c71802d42e8a 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -1360,7 +1360,48 @@ int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
return 0;
}
-static int acpi_processor_registered;
+void acpi_processor_register_idle_driver(void)
+{
+ struct acpi_processor *pr;
+ int ret = -ENODEV;
+ int cpu;
+
+ /*
+ * Acpi idle driver is used by all possible CPUs.
+ * Install the idle handler by the processor power info of one in them.
+ * Note that we use previously set idle handler will be used on
+ * platforms that only support C1.
+ */
+ for_each_cpu(cpu, (struct cpumask *)cpu_possible_mask) {
+ pr = per_cpu(processors, cpu);
+ if (!pr)
+ continue;
+
+ ret = acpi_processor_get_power_info(pr);
+ if (!ret) {
+ pr->flags.power_setup_done = 1;
+ acpi_processor_setup_cpuidle_states(pr);
+ break;
+ }
+ }
+
+ if (ret) {
+ pr_debug("No ACPI power information from any CPUs.\n");
+ return;
+ }
+
+ ret = cpuidle_register_driver(&acpi_idle_driver);
+ if (ret) {
+ pr_debug("register %s failed.\n", acpi_idle_driver.name);
+ return;
+ }
+ pr_debug("%s registered with cpuidle.\n", acpi_idle_driver.name);
+}
+
+void acpi_processor_unregister_idle_driver(void)
+{
+ cpuidle_unregister_driver(&acpi_idle_driver);
+}
int acpi_processor_power_init(struct acpi_processor *pr)
{
@@ -1375,22 +1416,7 @@ int acpi_processor_power_init(struct acpi_processor *pr)
if (!acpi_processor_get_power_info(pr))
pr->flags.power_setup_done = 1;
- /*
- * Install the idle handler if processor power management is supported.
- * Note that we use previously set idle handler will be used on
- * platforms that only support C1.
- */
if (pr->flags.power) {
- /* Register acpi_idle_driver if not already registered */
- if (!acpi_processor_registered) {
- acpi_processor_setup_cpuidle_states(pr);
- retval = cpuidle_register_driver(&acpi_idle_driver);
- if (retval)
- return retval;
- pr_debug("%s registered with cpuidle\n",
- acpi_idle_driver.name);
- }
-
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev)
return -ENOMEM;
@@ -1403,13 +1429,10 @@ int acpi_processor_power_init(struct acpi_processor *pr)
*/
retval = cpuidle_register_device(dev);
if (retval) {
- if (acpi_processor_registered == 0)
- cpuidle_unregister_driver(&acpi_idle_driver);
kfree(dev);
per_cpu(acpi_cpuidle_device, pr->id) = NULL;
return retval;
}
- acpi_processor_registered++;
}
return 0;
}
@@ -1423,10 +1446,6 @@ int acpi_processor_power_exit(struct acpi_processor *pr)
if (pr->flags.power) {
cpuidle_unregister_device(dev);
- acpi_processor_registered--;
- if (acpi_processor_registered == 0)
- cpuidle_unregister_driver(&acpi_idle_driver);
-
kfree(dev);
}
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index d0eccbd920e5..1249f5e81d92 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -423,6 +423,8 @@ int acpi_processor_power_init(struct acpi_processor *pr);
int 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);
+void acpi_processor_unregister_idle_driver(void);
#else
static inline int acpi_processor_power_init(struct acpi_processor *pr)
{
@@ -443,6 +445,12 @@ static inline int acpi_processor_hotplug(struct acpi_processor *pr)
{
return -ENODEV;
}
+static void acpi_processor_register_idle_driver(void)
+{
+}
+static void acpi_processor_unregister_idle_driver(void)
+{
+}
#endif /* CONFIG_ACPI_PROCESSOR_IDLE */
/* in processor_thermal.c */
--
2.33.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 0/2] ACPI: processor: idle: Optimize acpi idle driver registration
2025-07-28 7:06 [PATCH v3 0/2] ACPI: processor: idle: Optimize acpi idle driver registration Huisong Li
2025-07-28 7:06 ` [PATCH v3 1/2] ACPI: processor: idle: Fix memory leak when register cpuidle device failed Huisong Li
2025-07-28 7:06 ` [PATCH v3 2/2] ACPI: processor: idle: Optimize acpi idle driver registration Huisong Li
@ 2025-08-19 11:07 ` lihuisong (C)
2 siblings, 0 replies; 7+ messages in thread
From: lihuisong (C) @ 2025-08-19 11:07 UTC (permalink / raw)
To: rafael, lenb
Cc: linux-acpi, linux-kernel, linuxarm, jonathan.cameron, zhanjie9,
zhenglifeng1, yubowen8, liuyonglong
Kindly ping for review.
在 2025/7/28 15:06, Huisong Li 写道:
> This series fix a memory leak issue and optimize the registration of
> acpi idle driver to enhance its readability.
>
> ---
> changelog:
> v3:
> * use a separate patch to fix memory leak.
> * change the return value of the new function to void.
> * change log level to debug on failure path.
> v2:
> * register cpuidle driver in advance when all of the CPUs have been
> brought up.
> https://patchwork.kernel.org/project/linux-acpi/patch/20250723121034.3685996-1-lihuisong@huawei.com/
> v1:
> https://patchwork.kernel.org/project/linux-acpi/patch/20250619061327.1674384-1-lihuisong@huawei.com/
>
> Huisong Li (2):
> ACPI: processor: idle: Fix memory leak when register cpuidle device
> failed
> ACPI: processor: idle: Optimize acpi idle driver registration
>
> drivers/acpi/processor_driver.c | 3 ++
> drivers/acpi/processor_idle.c | 67 ++++++++++++++++++++++-----------
> include/acpi/processor.h | 8 ++++
> 3 files changed, 55 insertions(+), 23 deletions(-)
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 1/2] ACPI: processor: idle: Fix memory leak when register cpuidle device failed
2025-07-28 7:06 ` [PATCH v3 1/2] ACPI: processor: idle: Fix memory leak when register cpuidle device failed Huisong Li
@ 2025-08-22 19:27 ` Rafael J. Wysocki
0 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2025-08-22 19:27 UTC (permalink / raw)
To: Huisong Li
Cc: rafael, lenb, linux-acpi, linux-kernel, linuxarm,
jonathan.cameron, zhanjie9, zhenglifeng1, yubowen8, liuyonglong
On Mon, Jul 28, 2025 at 9:06 AM Huisong Li <lihuisong@huawei.com> wrote:
>
> The cpuidle device's memory has been leaked when register cpuidle
> device failed in acpi_processor_power_init().
>
> Fixes: 3d339dcbb56d ("cpuidle / ACPI : move cpuidle_device field out of the acpi_processor_power structure")
> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> ---
> drivers/acpi/processor_idle.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
> index 2c2dc559e0f8..031738390f2d 100644
> --- a/drivers/acpi/processor_idle.c
> +++ b/drivers/acpi/processor_idle.c
> @@ -1405,6 +1405,8 @@ int acpi_processor_power_init(struct acpi_processor *pr)
> if (retval) {
> if (acpi_processor_registered == 0)
> cpuidle_unregister_driver(&acpi_idle_driver);
> + kfree(dev);
> + per_cpu(acpi_cpuidle_device, pr->id) = NULL;
> return retval;
> }
> acpi_processor_registered++;
> --
Applied as 6.18 material with minor adjustments, thanks!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] ACPI: processor: idle: Optimize acpi idle driver registration
2025-07-28 7:06 ` [PATCH v3 2/2] ACPI: processor: idle: Optimize acpi idle driver registration Huisong Li
@ 2025-08-23 16:13 ` Rafael J. Wysocki
2025-08-25 6:05 ` lihuisong (C)
0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2025-08-23 16:13 UTC (permalink / raw)
To: Huisong Li
Cc: rafael, lenb, linux-acpi, linux-kernel, linuxarm,
jonathan.cameron, zhanjie9, zhenglifeng1, yubowen8, liuyonglong
On Mon, Jul 28, 2025 at 9:06 AM Huisong Li <lihuisong@huawei.com> wrote:
>
> Currently, the acpi idle driver is registered from within a CPU
> hotplug callback. Although this didn't cause any functional issues,
> this is questionable and confusing. And it is better to register
> the cpuidle driver when all of the CPUs have been brought up.
>
> So add a new function to initialize acpi_idle_driver based on the
> power management information of an available CPU and register cpuidle
> driver in acpi_processor_driver_init().
>
> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> ---
> drivers/acpi/processor_driver.c | 3 ++
> drivers/acpi/processor_idle.c | 65 +++++++++++++++++++++------------
> include/acpi/processor.h | 8 ++++
> 3 files changed, 53 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
> index 65e779be64ff..bc9f58a02c1d 100644
> --- a/drivers/acpi/processor_driver.c
> +++ b/drivers/acpi/processor_driver.c
> @@ -263,6 +263,8 @@ static int __init acpi_processor_driver_init(void)
> if (result < 0)
> return result;
>
> + acpi_processor_register_idle_driver();
> +
> result = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
> "acpi/cpu-drv:online",
> acpi_soft_cpu_online, NULL);
> @@ -301,6 +303,7 @@ static void __exit acpi_processor_driver_exit(void)
>
> cpuhp_remove_state_nocalls(hp_online);
> cpuhp_remove_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD);
> + acpi_processor_unregister_idle_driver();
> driver_unregister(&acpi_processor_driver);
> }
>
> diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
> index 031738390f2d..c71802d42e8a 100644
> --- a/drivers/acpi/processor_idle.c
> +++ b/drivers/acpi/processor_idle.c
> @@ -1360,7 +1360,48 @@ int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
> return 0;
> }
>
> -static int acpi_processor_registered;
> +void acpi_processor_register_idle_driver(void)
> +{
> + struct acpi_processor *pr;
> + int ret = -ENODEV;
> + int cpu;
> +
> + /*
> + * Acpi idle driver is used by all possible CPUs.
> + * Install the idle handler by the processor power info of one in them.
> + * Note that we use previously set idle handler will be used on
> + * platforms that only support C1.
> + */
> + for_each_cpu(cpu, (struct cpumask *)cpu_possible_mask) {
> + pr = per_cpu(processors, cpu);
> + if (!pr)
> + continue;
> +
> + ret = acpi_processor_get_power_info(pr);
> + if (!ret) {
> + pr->flags.power_setup_done = 1;
> + acpi_processor_setup_cpuidle_states(pr);
> + break;
> + }
> + }
> +
> + if (ret) {
> + pr_debug("No ACPI power information from any CPUs.\n");
> + return;
> + }
> +
> + ret = cpuidle_register_driver(&acpi_idle_driver);
> + if (ret) {
> + pr_debug("register %s failed.\n", acpi_idle_driver.name);
> + return;
> + }
> + pr_debug("%s registered with cpuidle.\n", acpi_idle_driver.name);
> +}
> +
> +void acpi_processor_unregister_idle_driver(void)
> +{
> + cpuidle_unregister_driver(&acpi_idle_driver);
> +}
>
> int acpi_processor_power_init(struct acpi_processor *pr)
> {
> @@ -1375,22 +1416,7 @@ int acpi_processor_power_init(struct acpi_processor *pr)
> if (!acpi_processor_get_power_info(pr))
> pr->flags.power_setup_done = 1;
>
> - /*
> - * Install the idle handler if processor power management is supported.
> - * Note that we use previously set idle handler will be used on
> - * platforms that only support C1.
> - */
> if (pr->flags.power) {
> - /* Register acpi_idle_driver if not already registered */
> - if (!acpi_processor_registered) {
> - acpi_processor_setup_cpuidle_states(pr);
> - retval = cpuidle_register_driver(&acpi_idle_driver);
> - if (retval)
> - return retval;
> - pr_debug("%s registered with cpuidle\n",
> - acpi_idle_driver.name);
> - }
> -
> dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> if (!dev)
> return -ENOMEM;
> @@ -1403,13 +1429,10 @@ int acpi_processor_power_init(struct acpi_processor *pr)
> */
> retval = cpuidle_register_device(dev);
> if (retval) {
> - if (acpi_processor_registered == 0)
> - cpuidle_unregister_driver(&acpi_idle_driver);
> kfree(dev);
> per_cpu(acpi_cpuidle_device, pr->id) = NULL;
> return retval;
> }
> - acpi_processor_registered++;
> }
> return 0;
> }
> @@ -1423,10 +1446,6 @@ int acpi_processor_power_exit(struct acpi_processor *pr)
>
> if (pr->flags.power) {
> cpuidle_unregister_device(dev);
> - acpi_processor_registered--;
> - if (acpi_processor_registered == 0)
> - cpuidle_unregister_driver(&acpi_idle_driver);
> -
> kfree(dev);
> }
>
> diff --git a/include/acpi/processor.h b/include/acpi/processor.h
> index d0eccbd920e5..1249f5e81d92 100644
> --- a/include/acpi/processor.h
> +++ b/include/acpi/processor.h
> @@ -423,6 +423,8 @@ int acpi_processor_power_init(struct acpi_processor *pr);
> int 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);
> +void acpi_processor_unregister_idle_driver(void);
> #else
> static inline int acpi_processor_power_init(struct acpi_processor *pr)
> {
> @@ -443,6 +445,12 @@ static inline int acpi_processor_hotplug(struct acpi_processor *pr)
> {
> return -ENODEV;
> }
> +static void acpi_processor_register_idle_driver(void)
> +{
> +}
> +static void acpi_processor_unregister_idle_driver(void)
> +{
> +}
> #endif /* CONFIG_ACPI_PROCESSOR_IDLE */
>
> /* in processor_thermal.c */
> --
Applied as 6.18 material, thanks!
While at it, in the future, please always spell ACPI in capitals in
patch subjects, changelogs and code comments.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] ACPI: processor: idle: Optimize acpi idle driver registration
2025-08-23 16:13 ` Rafael J. Wysocki
@ 2025-08-25 6:05 ` lihuisong (C)
0 siblings, 0 replies; 7+ messages in thread
From: lihuisong (C) @ 2025-08-25 6:05 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: lenb, linux-acpi, linux-kernel, linuxarm, jonathan.cameron,
zhanjie9, zhenglifeng1, yubowen8, liuyonglong, lihuisong
在 2025/8/24 0:13, Rafael J. Wysocki 写道:
> On Mon, Jul 28, 2025 at 9:06 AM Huisong Li <lihuisong@huawei.com> wrote:
>> Currently, the acpi idle driver is registered from within a CPU
>> hotplug callback. Although this didn't cause any functional issues,
>> this is questionable and confusing. And it is better to register
>> the cpuidle driver when all of the CPUs have been brought up.
>>
>> So add a new function to initialize acpi_idle_driver based on the
>> power management information of an available CPU and register cpuidle
>> driver in acpi_processor_driver_init().
>>
>> Signed-off-by: Huisong Li <lihuisong@huawei.com>
>> ---
>> drivers/acpi/processor_driver.c | 3 ++
>> drivers/acpi/processor_idle.c | 65 +++++++++++++++++++++------------
>> include/acpi/processor.h | 8 ++++
>> 3 files changed, 53 insertions(+), 23 deletions(-)
>>
>> diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
>> index 65e779be64ff..bc9f58a02c1d 100644
>> --- a/drivers/acpi/processor_driver.c
>> +++ b/drivers/acpi/processor_driver.c
>> @@ -263,6 +263,8 @@ static int __init acpi_processor_driver_init(void)
>> if (result < 0)
>> return result;
>>
>> + acpi_processor_register_idle_driver();
>> +
>> result = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
>> "acpi/cpu-drv:online",
>> acpi_soft_cpu_online, NULL);
>> @@ -301,6 +303,7 @@ static void __exit acpi_processor_driver_exit(void)
>>
>> cpuhp_remove_state_nocalls(hp_online);
>> cpuhp_remove_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD);
>> + acpi_processor_unregister_idle_driver();
>> driver_unregister(&acpi_processor_driver);
>> }
>>
>> diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
>> index 031738390f2d..c71802d42e8a 100644
>> --- a/drivers/acpi/processor_idle.c
>> +++ b/drivers/acpi/processor_idle.c
>> @@ -1360,7 +1360,48 @@ int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
>> return 0;
>> }
>>
>> -static int acpi_processor_registered;
>> +void acpi_processor_register_idle_driver(void)
>> +{
>> + struct acpi_processor *pr;
>> + int ret = -ENODEV;
>> + int cpu;
>> +
>> + /*
>> + * Acpi idle driver is used by all possible CPUs.
>> + * Install the idle handler by the processor power info of one in them.
>> + * Note that we use previously set idle handler will be used on
>> + * platforms that only support C1.
>> + */
>> + for_each_cpu(cpu, (struct cpumask *)cpu_possible_mask) {
>> + pr = per_cpu(processors, cpu);
>> + if (!pr)
>> + continue;
>> +
>> + ret = acpi_processor_get_power_info(pr);
>> + if (!ret) {
>> + pr->flags.power_setup_done = 1;
>> + acpi_processor_setup_cpuidle_states(pr);
>> + break;
>> + }
>> + }
>> +
>> + if (ret) {
>> + pr_debug("No ACPI power information from any CPUs.\n");
>> + return;
>> + }
>> +
>> + ret = cpuidle_register_driver(&acpi_idle_driver);
>> + if (ret) {
>> + pr_debug("register %s failed.\n", acpi_idle_driver.name);
>> + return;
>> + }
>> + pr_debug("%s registered with cpuidle.\n", acpi_idle_driver.name);
>> +}
>> +
>> +void acpi_processor_unregister_idle_driver(void)
>> +{
>> + cpuidle_unregister_driver(&acpi_idle_driver);
>> +}
>>
>> int acpi_processor_power_init(struct acpi_processor *pr)
>> {
>> @@ -1375,22 +1416,7 @@ int acpi_processor_power_init(struct acpi_processor *pr)
>> if (!acpi_processor_get_power_info(pr))
>> pr->flags.power_setup_done = 1;
>>
>> - /*
>> - * Install the idle handler if processor power management is supported.
>> - * Note that we use previously set idle handler will be used on
>> - * platforms that only support C1.
>> - */
>> if (pr->flags.power) {
>> - /* Register acpi_idle_driver if not already registered */
>> - if (!acpi_processor_registered) {
>> - acpi_processor_setup_cpuidle_states(pr);
>> - retval = cpuidle_register_driver(&acpi_idle_driver);
>> - if (retval)
>> - return retval;
>> - pr_debug("%s registered with cpuidle\n",
>> - acpi_idle_driver.name);
>> - }
>> -
>> dev = kzalloc(sizeof(*dev), GFP_KERNEL);
>> if (!dev)
>> return -ENOMEM;
>> @@ -1403,13 +1429,10 @@ int acpi_processor_power_init(struct acpi_processor *pr)
>> */
>> retval = cpuidle_register_device(dev);
>> if (retval) {
>> - if (acpi_processor_registered == 0)
>> - cpuidle_unregister_driver(&acpi_idle_driver);
>> kfree(dev);
>> per_cpu(acpi_cpuidle_device, pr->id) = NULL;
>> return retval;
>> }
>> - acpi_processor_registered++;
>> }
>> return 0;
>> }
>> @@ -1423,10 +1446,6 @@ int acpi_processor_power_exit(struct acpi_processor *pr)
>>
>> if (pr->flags.power) {
>> cpuidle_unregister_device(dev);
>> - acpi_processor_registered--;
>> - if (acpi_processor_registered == 0)
>> - cpuidle_unregister_driver(&acpi_idle_driver);
>> -
>> kfree(dev);
>> }
>>
>> diff --git a/include/acpi/processor.h b/include/acpi/processor.h
>> index d0eccbd920e5..1249f5e81d92 100644
>> --- a/include/acpi/processor.h
>> +++ b/include/acpi/processor.h
>> @@ -423,6 +423,8 @@ int acpi_processor_power_init(struct acpi_processor *pr);
>> int 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);
>> +void acpi_processor_unregister_idle_driver(void);
>> #else
>> static inline int acpi_processor_power_init(struct acpi_processor *pr)
>> {
>> @@ -443,6 +445,12 @@ static inline int acpi_processor_hotplug(struct acpi_processor *pr)
>> {
>> return -ENODEV;
>> }
>> +static void acpi_processor_register_idle_driver(void)
>> +{
>> +}
>> +static void acpi_processor_unregister_idle_driver(void)
>> +{
>> +}
>> #endif /* CONFIG_ACPI_PROCESSOR_IDLE */
>>
>> /* in processor_thermal.c */
>> --
> Applied as 6.18 material, thanks!
>
> While at it, in the future, please always spell ACPI in capitals in
> patch subjects, changelogs and code comments.
Get it. Thanks.
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-08-25 6:05 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-28 7:06 [PATCH v3 0/2] ACPI: processor: idle: Optimize acpi idle driver registration Huisong Li
2025-07-28 7:06 ` [PATCH v3 1/2] ACPI: processor: idle: Fix memory leak when register cpuidle device failed Huisong Li
2025-08-22 19:27 ` Rafael J. Wysocki
2025-07-28 7:06 ` [PATCH v3 2/2] ACPI: processor: idle: Optimize acpi idle driver registration Huisong Li
2025-08-23 16:13 ` Rafael J. Wysocki
2025-08-25 6:05 ` lihuisong (C)
2025-08-19 11:07 ` [PATCH v3 0/2] " lihuisong (C)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).