Skip to contentSkip to conversation

PM: Fix bug in the error handling of async suspend

PATCH In review Sahitya Tummala 2 participants 2 messages Dec 7, 2016 – Dec 8, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM: Fix bug in the error handling of async suspend

If async_suspend is enabled for parent and child devices, then PM framework has to ensure that parent's async suspend gets called only after child's async suspend is done. In case if child's async suspend fails with error, then parent's async suspend must not be invoked. The current code uses async_error to ensure this but there is a problem with it in __device_suspend(). This function notifies the completion of child's async suspend before updating its error via async_error variable. As a result, parent's async suspend gets invoked even though it's child suspend has failed. Fix this bug by updating the async_error before notifying the child's completion.

---
 drivers/base/power/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/power/main.c +1 -1
index e44944f4be77..f733f50f8321 100644
@@ -1460,9 +1460,9 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
 	dpm_watchdog_clear(&wd);
 
  Complete:
-	complete_all(&dev->power.completion);
 	if (error)
 		async_error = error;
+	complete_all(&dev->power.completion);
 
 	TRACE_SUSPEND(error);
 	return error;
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
#1 lore raw
Quoted 21 lines · Sahitya Tummala

If async_suspend is enabled for parent and child devices, then PM framework has to ensure that parent's async suspend gets called only after child's async suspend is done. In case if child's async suspend fails with error, then parent's async suspend must not be invoked. The current code uses async_error to ensure this but there is a problem with it in __device_suspend(). This function notifies the completion of child's async suspend before updating its error via async_error variable. As a result, parent's async suspend gets invoked even though it's child suspend has failed. Fix this bug by updating the async_error before notifying the child's completion.

---
 drivers/base/power/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/power/main.c +0 -0
index e44944f4be77..f733f50f8321 100644

drivers/base/power/main.c static int __device_suspend(struct device *dev, pm_message_t state, bool async) · line 1468

Quoted 10 lines
drivers/base/power/main.c +1 -1
@@ -1460,9 +1460,9 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
 	dpm_watchdog_clear(&wd);
 
  Complete:
-	complete_all(&dev->power.completion);
 	if (error)
 		async_error = error;
+	complete_all(&dev->power.completion);
 
 	TRACE_SUSPEND(error);
 	return error;

Good catch!

I'm queuing this one up (with some whitespace rearrangements).

Thanks,
Rafael