@@ -570,7 +570,6 @@ static int device_resume(struct device *dev, pm_message_t state, bool async)
570570 pm_callback_t callback = NULL ;
571571 char * info = NULL ;
572572 int error = 0 ;
573- bool put = false;
574573
575574 TRACE_DEVICE (dev );
576575 TRACE_RESUME (0 );
@@ -591,7 +590,6 @@ static int device_resume(struct device *dev, pm_message_t state, bool async)
591590 goto Unlock ;
592591
593592 pm_runtime_enable (dev );
594- put = true;
595593
596594 if (dev -> pm_domain ) {
597595 info = "power domain " ;
@@ -646,9 +644,6 @@ static int device_resume(struct device *dev, pm_message_t state, bool async)
646644
647645 TRACE_RESUME (error );
648646
649- if (put )
650- pm_runtime_put_sync (dev );
651-
652647 return error ;
653648}
654649
@@ -762,6 +757,8 @@ static void device_complete(struct device *dev, pm_message_t state)
762757 }
763758
764759 device_unlock (dev );
760+
761+ pm_runtime_put_sync (dev );
765762}
766763
767764/**
@@ -1015,7 +1012,7 @@ int dpm_suspend_end(pm_message_t state)
10151012
10161013 error = dpm_suspend_noirq (state );
10171014 if (error ) {
1018- dpm_resume_early (state );
1015+ dpm_resume_early (resume_event ( state ) );
10191016 return error ;
10201017 }
10211018
@@ -1062,12 +1059,16 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
10621059 if (async_error )
10631060 goto Complete ;
10641061
1065- pm_runtime_get_noresume (dev );
1062+ /*
1063+ * If a device configured to wake up the system from sleep states
1064+ * has been suspended at run time and there's a resume request pending
1065+ * for it, this is equivalent to the device signaling wakeup, so the
1066+ * system suspend operation should be aborted.
1067+ */
10661068 if (pm_runtime_barrier (dev ) && device_may_wakeup (dev ))
10671069 pm_wakeup_event (dev , 0 );
10681070
10691071 if (pm_wakeup_pending ()) {
1070- pm_runtime_put_sync (dev );
10711072 async_error = - EBUSY ;
10721073 goto Complete ;
10731074 }
@@ -1133,12 +1134,10 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
11331134 Complete :
11341135 complete_all (& dev -> power .completion );
11351136
1136- if (error ) {
1137- pm_runtime_put_sync (dev );
1137+ if (error )
11381138 async_error = error ;
1139- } else if (dev -> power .is_suspended ) {
1139+ else if (dev -> power .is_suspended )
11401140 __pm_runtime_disable (dev , false);
1141- }
11421141
11431142 return error ;
11441143}
@@ -1234,6 +1233,14 @@ static int device_prepare(struct device *dev, pm_message_t state)
12341233 if (dev -> power .syscore )
12351234 return 0 ;
12361235
1236+ /*
1237+ * If a device's parent goes into runtime suspend at the wrong time,
1238+ * it won't be possible to resume the device. To prevent this we
1239+ * block runtime suspend here, during the prepare phase, and allow
1240+ * it again during the complete phase.
1241+ */
1242+ pm_runtime_get_noresume (dev );
1243+
12371244 device_lock (dev );
12381245
12391246 dev -> power .wakeup_path = device_may_wakeup (dev );
0 commit comments