diff options
author | Rafael J. Wysocki <rjw@sisk.pl> | 2010-09-22 16:10:57 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2010-10-16 19:57:43 -0400 |
commit | 098dff738abbeaea15fc95c4f4fdaee1e9bbea75 (patch) | |
tree | b2282f59358b4f1e8bbf9949ff1eec4c8016ca5f /drivers/base | |
parent | 074037ec79bea73edf1b1ec72fef1010e83e3cc5 (diff) |
PM: Fix potential issue with failing asynchronous suspend
There is a potential issue with the asynchronous suspend code that
a device driver suspending asynchronously may not notice that it
should back off. There are two failing scenarions, (1) when the
driver is waiting for a driver suspending synchronously to complete
and that second driver returns error code, in which case async_error
won't be set and the waiting driver will continue suspending and (2)
after the driver has called device_pm_wait_for_dev() and the waited
for driver returns error code, in which case the caller of
device_pm_wait_for_dev() will not know that there was an error and
will continue suspending.
To fix this issue make __device_suspend() set async_error, so
async_suspend() doesn't need to set it any more, and make
device_pm_wait_for_dev() return async_error, so that its callers
can check whether or not they should continue suspending.
No more changes are necessary, since device_pm_wait_for_dev() is
not used by any drivers' suspend routines.
Reported-by: Colin Cross <ccross@android.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/power/main.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 7ae6fe414c38..31b526661ec4 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c | |||
@@ -51,6 +51,8 @@ static pm_message_t pm_transition; | |||
51 | */ | 51 | */ |
52 | static bool transition_started; | 52 | static bool transition_started; |
53 | 53 | ||
54 | static int async_error; | ||
55 | |||
54 | /** | 56 | /** |
55 | * device_pm_init - Initialize the PM-related part of a device object. | 57 | * device_pm_init - Initialize the PM-related part of a device object. |
56 | * @dev: Device object being initialized. | 58 | * @dev: Device object being initialized. |
@@ -602,6 +604,7 @@ static void dpm_resume(pm_message_t state) | |||
602 | INIT_LIST_HEAD(&list); | 604 | INIT_LIST_HEAD(&list); |
603 | mutex_lock(&dpm_list_mtx); | 605 | mutex_lock(&dpm_list_mtx); |
604 | pm_transition = state; | 606 | pm_transition = state; |
607 | async_error = 0; | ||
605 | 608 | ||
606 | list_for_each_entry(dev, &dpm_list, power.entry) { | 609 | list_for_each_entry(dev, &dpm_list, power.entry) { |
607 | if (dev->power.status < DPM_OFF) | 610 | if (dev->power.status < DPM_OFF) |
@@ -831,8 +834,6 @@ static int legacy_suspend(struct device *dev, pm_message_t state, | |||
831 | return error; | 834 | return error; |
832 | } | 835 | } |
833 | 836 | ||
834 | static int async_error; | ||
835 | |||
836 | /** | 837 | /** |
837 | * device_suspend - Execute "suspend" callbacks for given device. | 838 | * device_suspend - Execute "suspend" callbacks for given device. |
838 | * @dev: Device to handle. | 839 | * @dev: Device to handle. |
@@ -887,6 +888,9 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
887 | device_unlock(dev); | 888 | device_unlock(dev); |
888 | complete_all(&dev->power.completion); | 889 | complete_all(&dev->power.completion); |
889 | 890 | ||
891 | if (error) | ||
892 | async_error = error; | ||
893 | |||
890 | return error; | 894 | return error; |
891 | } | 895 | } |
892 | 896 | ||
@@ -896,10 +900,8 @@ static void async_suspend(void *data, async_cookie_t cookie) | |||
896 | int error; | 900 | int error; |
897 | 901 | ||
898 | error = __device_suspend(dev, pm_transition, true); | 902 | error = __device_suspend(dev, pm_transition, true); |
899 | if (error) { | 903 | if (error) |
900 | pm_dev_err(dev, pm_transition, " async", error); | 904 | pm_dev_err(dev, pm_transition, " async", error); |
901 | async_error = error; | ||
902 | } | ||
903 | 905 | ||
904 | put_device(dev); | 906 | put_device(dev); |
905 | } | 907 | } |
@@ -1087,8 +1089,9 @@ EXPORT_SYMBOL_GPL(__suspend_report_result); | |||
1087 | * @dev: Device to wait for. | 1089 | * @dev: Device to wait for. |
1088 | * @subordinate: Device that needs to wait for @dev. | 1090 | * @subordinate: Device that needs to wait for @dev. |
1089 | */ | 1091 | */ |
1090 | void device_pm_wait_for_dev(struct device *subordinate, struct device *dev) | 1092 | int device_pm_wait_for_dev(struct device *subordinate, struct device *dev) |
1091 | { | 1093 | { |
1092 | dpm_wait(dev, subordinate->power.async_suspend); | 1094 | dpm_wait(dev, subordinate->power.async_suspend); |
1095 | return async_error; | ||
1093 | } | 1096 | } |
1094 | EXPORT_SYMBOL_GPL(device_pm_wait_for_dev); | 1097 | EXPORT_SYMBOL_GPL(device_pm_wait_for_dev); |