[PATCH v1 2/7] ACPI: PM: Introduce acpi_device_init_power()

From: Rafael J. Wysocki

Date: Mon Aug 31 2026 - 15:22:25 EST


From: "Rafael J. Wysocki" <rafael.j.wysocki@xxxxxxxxx>

Two out of three callers of acpi_bus_init_power() need to clear
flags.power_manageable for the target device on errors, which
is somewhat cumbersome, so rename the function to
__acpi_device_init_power(), add a wrapper called
acpi_device_init_power() around it that will take care
of the flags.power_manageable clearing, and make the two
callers of acpi_bus_init_power() in question invoke that
wrapper.

While at it, clean up the declaration of local variables
in __acpi_device_init_power().

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
---
drivers/acpi/device_pm.c | 22 +++++++++++++++-------
drivers/acpi/scan.c | 5 ++---
include/acpi/acpi_bus.h | 2 +-
3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index a680e6972a8c..7fd780125177 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -169,10 +169,8 @@ int acpi_device_set_power(struct acpi_device *device, int state)
return -EINVAL;

if (device->power.state == ACPI_STATE_UNKNOWN &&
- acpi_bus_init_power(device)) {
- device->flags.power_manageable = 0;
+ acpi_device_init_power(device))
return -ENODEV;
- }

acpi_handle_debug(device->handle, "Power state change: %s -> %s\n",
acpi_power_state_string(device->power.state),
@@ -310,10 +308,9 @@ int acpi_bus_set_power(acpi_handle handle, int state)
}
EXPORT_SYMBOL(acpi_bus_set_power);

-int acpi_bus_init_power(struct acpi_device *device)
+static int __acpi_device_init_power(struct acpi_device *device)
{
- int state;
- int result;
+ int result, state;

result = acpi_device_get_power(device, &state);
if (result)
@@ -355,6 +352,17 @@ int acpi_bus_init_power(struct acpi_device *device)
return 0;
}

+int acpi_device_init_power(struct acpi_device *device)
+{
+ int ret;
+
+ ret = __acpi_device_init_power(device);
+ if (ret)
+ device->flags.power_manageable = 0;
+
+ return ret;
+}
+
/**
* acpi_device_fix_up_power - Force device with missing _PSC into D0.
* @device: Device object whose power state is to be fixed up.
@@ -417,7 +425,7 @@ int acpi_device_update_power(struct acpi_device *device, int *state_p)
int result;

if (device->power.state == ACPI_STATE_UNKNOWN) {
- result = acpi_bus_init_power(device);
+ result = __acpi_device_init_power(device);
if (!result && state_p)
*state_p = device->power.state;

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 1ad8dffc2daf..5aa3ecb000e1 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -2362,9 +2362,8 @@ static int acpi_bus_attach(struct acpi_device *device, void *first_pass)
acpi_ec_register_opregions(device);

if (device->flags.power_manageable &&
- device->power.state == ACPI_STATE_UNKNOWN &&
- acpi_bus_init_power(device))
- device->flags.power_manageable = 0;
+ device->power.state == ACPI_STATE_UNKNOWN)
+ acpi_device_init_power(device);

if (device->flags.visited)
goto ok;
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 1a45e0d521d8..b0d9057ccb8a 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -618,7 +618,7 @@ int acpi_bus_get_status(struct acpi_device *device);
int acpi_bus_set_power(acpi_handle handle, int state);
const char *acpi_power_state_string(int state);
int acpi_device_set_power(struct acpi_device *device, int state);
-int acpi_bus_init_power(struct acpi_device *device);
+int acpi_device_init_power(struct acpi_device *device);
int acpi_device_fix_up_power(struct acpi_device *device);
void acpi_device_fix_up_power_extended(struct acpi_device *adev);
void acpi_device_fix_up_power_children(struct acpi_device *adev);
--
2.51.0