Commit 077f893b authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

Merge branch 'acpi-pm' into linux-next

* acpi-pm:
  ACPI / PM: Fix potential problem in acpi_device_get_power()
parents 6912897d 75eb2d13
...@@ -145,27 +145,36 @@ int acpi_device_get_power(struct acpi_device *device, int *state) ...@@ -145,27 +145,36 @@ int acpi_device_get_power(struct acpi_device *device, int *state)
} }
/* /*
* Get the device's power state either directly (via _PSC) or * Get the device's power state from power resources settings and _PSC,
* indirectly (via power resources). * if available.
*/ */
if (device->power.flags.power_resources) {
int error = acpi_power_get_inferred_state(device, &result);
if (error)
return error;
}
if (device->power.flags.explicit_get) { if (device->power.flags.explicit_get) {
acpi_handle handle = device->handle;
unsigned long long psc; unsigned long long psc;
acpi_status status = acpi_evaluate_integer(device->handle, acpi_status status;
"_PSC", NULL, &psc);
status = acpi_evaluate_integer(handle, "_PSC", NULL, &psc);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -ENODEV; return -ENODEV;
result = psc; /*
} * The power resources settings may indicate a power state
/* The test below covers ACPI_STATE_UNKNOWN too. */ * shallower than the actual power state of the device.
if (result <= ACPI_STATE_D2) { *
; /* Do nothing. */ * Moreover, on systems predating ACPI 4.0, if the device
} else if (device->power.flags.power_resources) { * doesn't depend on any power resources and _PSC returns 3,
int error = acpi_power_get_inferred_state(device, &result); * that means "power off". We need to maintain compatibility
if (error) * with those systems.
return error; */
} else if (result == ACPI_STATE_D3_HOT) { if (psc > result && psc < ACPI_STATE_D3_COLD)
result = ACPI_STATE_D3; result = psc;
else if (result == ACPI_STATE_UNKNOWN)
result = psc > ACPI_STATE_D2 ? ACPI_STATE_D3_COLD : psc;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment