Skip to content

Commit 098dff7

Browse files
committed
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 <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]>
1 parent 074037e commit 098dff7

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

drivers/base/power/main.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ static pm_message_t pm_transition;
5151
*/
5252
static bool transition_started;
5353

54+
static int async_error;
55+
5456
/**
5557
* device_pm_init - Initialize the PM-related part of a device object.
5658
* @dev: Device object being initialized.
@@ -602,6 +604,7 @@ static void dpm_resume(pm_message_t state)
602604
INIT_LIST_HEAD(&list);
603605
mutex_lock(&dpm_list_mtx);
604606
pm_transition = state;
607+
async_error = 0;
605608

606609
list_for_each_entry(dev, &dpm_list, power.entry) {
607610
if (dev->power.status < DPM_OFF)
@@ -831,8 +834,6 @@ static int legacy_suspend(struct device *dev, pm_message_t state,
831834
return error;
832835
}
833836

834-
static int async_error;
835-
836837
/**
837838
* device_suspend - Execute "suspend" callbacks for given device.
838839
* @dev: Device to handle.
@@ -887,6 +888,9 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
887888
device_unlock(dev);
888889
complete_all(&dev->power.completion);
889890

891+
if (error)
892+
async_error = error;
893+
890894
return error;
891895
}
892896

@@ -896,10 +900,8 @@ static void async_suspend(void *data, async_cookie_t cookie)
896900
int error;
897901

898902
error = __device_suspend(dev, pm_transition, true);
899-
if (error) {
903+
if (error)
900904
pm_dev_err(dev, pm_transition, " async", error);
901-
async_error = error;
902-
}
903905

904906
put_device(dev);
905907
}
@@ -1087,8 +1089,9 @@ EXPORT_SYMBOL_GPL(__suspend_report_result);
10871089
* @dev: Device to wait for.
10881090
* @subordinate: Device that needs to wait for @dev.
10891091
*/
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)
10911093
{
10921094
dpm_wait(dev, subordinate->power.async_suspend);
1095+
return async_error;
10931096
}
10941097
EXPORT_SYMBOL_GPL(device_pm_wait_for_dev);

include/linux/pm.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ extern void __suspend_report_result(const char *function, void *fn, int ret);
559559
__suspend_report_result(__func__, fn, ret); \
560560
} while (0)
561561

562-
extern void device_pm_wait_for_dev(struct device *sub, struct device *dev);
562+
extern int device_pm_wait_for_dev(struct device *sub, struct device *dev);
563563
#else /* !CONFIG_PM_SLEEP */
564564

565565
#define device_pm_lock() do {} while (0)
@@ -572,7 +572,10 @@ static inline int dpm_suspend_start(pm_message_t state)
572572

573573
#define suspend_report_result(fn, ret) do {} while (0)
574574

575-
static inline void device_pm_wait_for_dev(struct device *a, struct device *b) {}
575+
static inline int device_pm_wait_for_dev(struct device *a, struct device *b)
576+
{
577+
return 0;
578+
}
576579
#endif /* !CONFIG_PM_SLEEP */
577580

578581
/* How to reorder dpm_list after device_move() */

0 commit comments

Comments
 (0)