Skip to content

Commit 587024b

Browse files
committed
ACPI: power: Use u8 as the power resource state data type
Use u8 as the data type for representing the state of an ACPI power resource. It is s not necessary to use int for that and because subsequent changes are going to use ACPI_POWER_RESOURCE_STATE_UNKNOWN, it is better to adjust the data type so that the "unknown" state is represented by the "all ones" value. While at it, clean up acpi_power_get_state() somewhat. No intentional functional impact. Tested-by: Dave Olsthoorn <dave@bewaar.me> Tested-by: Shujun Wang <wsj20369@163.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent e4ada4c commit 587024b

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

drivers/acpi/power.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,11 @@ int acpi_extract_power_resources(union acpi_object *package, unsigned int start,
182182
return err;
183183
}
184184

185-
static int acpi_power_get_state(acpi_handle handle, int *state)
185+
static int acpi_power_get_state(acpi_handle handle, u8 *state)
186186
{
187187
acpi_status status = AE_OK;
188188
unsigned long long sta = 0;
189+
u8 cur_state;
189190

190191
if (!handle || !state)
191192
return -EINVAL;
@@ -194,25 +195,24 @@ static int acpi_power_get_state(acpi_handle handle, int *state)
194195
if (ACPI_FAILURE(status))
195196
return -ENODEV;
196197

197-
*state = (sta & 0x01)?ACPI_POWER_RESOURCE_STATE_ON:
198-
ACPI_POWER_RESOURCE_STATE_OFF;
198+
cur_state = sta & ACPI_POWER_RESOURCE_STATE_ON;
199199

200200
acpi_handle_debug(handle, "Power resource is %s\n",
201-
*state ? "on" : "off");
201+
cur_state ? "on" : "off");
202202

203+
*state = cur_state;
203204
return 0;
204205
}
205206

206-
static int acpi_power_get_list_state(struct list_head *list, int *state)
207+
static int acpi_power_get_list_state(struct list_head *list, u8 *state)
207208
{
208209
struct acpi_power_resource_entry *entry;
209-
int cur_state;
210+
u8 cur_state = ACPI_POWER_RESOURCE_STATE_OFF;
210211

211212
if (!list || !state)
212213
return -EINVAL;
213214

214215
/* The state of the list is 'on' IFF all resources are 'on'. */
215-
cur_state = 0;
216216
list_for_each_entry(entry, list, node) {
217217
struct acpi_power_resource *resource = entry->resource;
218218
acpi_handle handle = resource->device.handle;
@@ -592,7 +592,7 @@ int acpi_power_wakeup_list_init(struct list_head *list, int *system_level_p)
592592
struct acpi_power_resource *resource = entry->resource;
593593
acpi_handle handle = resource->device.handle;
594594
int result;
595-
int state;
595+
u8 state;
596596

597597
mutex_lock(&resource->resource_lock);
598598

@@ -789,8 +789,8 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev)
789789

790790
int acpi_power_get_inferred_state(struct acpi_device *device, int *state)
791791
{
792+
u8 list_state = ACPI_POWER_RESOURCE_STATE_OFF;
792793
int result = 0;
793-
int list_state = 0;
794794
int i = 0;
795795

796796
if (!device || !state)
@@ -919,7 +919,8 @@ struct acpi_device *acpi_add_power_resource(acpi_handle handle)
919919
union acpi_object acpi_object;
920920
struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object };
921921
acpi_status status;
922-
int state, result = -ENODEV;
922+
int result;
923+
u8 state;
923924

924925
acpi_bus_get_device(handle, &device);
925926
if (device)
@@ -979,7 +980,8 @@ void acpi_resume_power_resources(void)
979980
mutex_lock(&power_resource_list_lock);
980981

981982
list_for_each_entry(resource, &acpi_power_resource_list, list_node) {
982-
int result, state;
983+
int result;
984+
u8 state;
983985

984986
mutex_lock(&resource->resource_lock);
985987

@@ -1012,7 +1014,8 @@ static void acpi_power_turn_off_if_unused(struct acpi_power_resource *resource,
10121014
if (resource->users > 0)
10131015
return;
10141016
} else {
1015-
int result, state;
1017+
int result;
1018+
u8 state;
10161019

10171020
result = acpi_power_get_state(resource->device.handle, &state);
10181021
if (result || state == ACPI_POWER_RESOURCE_STATE_OFF)

0 commit comments

Comments
 (0)