@@ -647,14 +647,27 @@ static void dpm_async_resume_children(struct device *dev, async_func_t func)
647647 /*
648648 * Start processing "async" children of the device unless it's been
649649 * started already for them.
650- *
651- * This could have been done for the device's "async" consumers too, but
652- * they either need to wait for their parents or the processing has
653- * already started for them after their parents were processed.
654650 */
655651 device_for_each_child (dev , func , dpm_async_with_cleanup );
656652}
657653
654+ static void dpm_async_resume_subordinate (struct device * dev , async_func_t func )
655+ {
656+ struct device_link * link ;
657+ int idx ;
658+
659+ dpm_async_resume_children (dev , func );
660+
661+ idx = device_links_read_lock ();
662+
663+ /* Start processing the device's "async" consumers. */
664+ list_for_each_entry_rcu (link , & dev -> links .consumers , s_node )
665+ if (READ_ONCE (link -> status ) != DL_STATE_DORMANT )
666+ dpm_async_with_cleanup (link -> consumer , func );
667+
668+ device_links_read_unlock (idx );
669+ }
670+
658671static void dpm_clear_async_state (struct device * dev )
659672{
660673 reinit_completion (& dev -> power .completion );
@@ -663,7 +676,14 @@ static void dpm_clear_async_state(struct device *dev)
663676
664677static bool dpm_root_device (struct device * dev )
665678{
666- return !dev -> parent ;
679+ lockdep_assert_held (& dpm_list_mtx );
680+
681+ /*
682+ * Since this function is required to run under dpm_list_mtx, the
683+ * list_empty() below will only return true if the device's list of
684+ * consumers is actually empty before calling it.
685+ */
686+ return !dev -> parent && list_empty (& dev -> links .suppliers );
667687}
668688
669689static void async_resume_noirq (void * data , async_cookie_t cookie );
@@ -752,7 +772,7 @@ static void device_resume_noirq(struct device *dev, pm_message_t state, bool asy
752772 pm_dev_err (dev , state , async ? " async noirq" : " noirq" , error );
753773 }
754774
755- dpm_async_resume_children (dev , async_resume_noirq );
775+ dpm_async_resume_subordinate (dev , async_resume_noirq );
756776}
757777
758778static void async_resume_noirq (void * data , async_cookie_t cookie )
@@ -895,7 +915,7 @@ static void device_resume_early(struct device *dev, pm_message_t state, bool asy
895915 pm_dev_err (dev , state , async ? " async early" : " early" , error );
896916 }
897917
898- dpm_async_resume_children (dev , async_resume_early );
918+ dpm_async_resume_subordinate (dev , async_resume_early );
899919}
900920
901921static void async_resume_early (void * data , async_cookie_t cookie )
@@ -1071,7 +1091,7 @@ static void device_resume(struct device *dev, pm_message_t state, bool async)
10711091 pm_dev_err (dev , state , async ? " async" : "" , error );
10721092 }
10731093
1074- dpm_async_resume_children (dev , async_resume );
1094+ dpm_async_resume_subordinate (dev , async_resume );
10751095}
10761096
10771097static void async_resume (void * data , async_cookie_t cookie )
@@ -1095,7 +1115,6 @@ void dpm_resume(pm_message_t state)
10951115 ktime_t starttime = ktime_get ();
10961116
10971117 trace_suspend_resume (TPS ("dpm_resume" ), state .event , true);
1098- might_sleep ();
10991118
11001119 pm_transition = state ;
11011120 async_error = 0 ;
@@ -1198,7 +1217,6 @@ void dpm_complete(pm_message_t state)
11981217 struct list_head list ;
11991218
12001219 trace_suspend_resume (TPS ("dpm_complete" ), state .event , true);
1201- might_sleep ();
12021220
12031221 INIT_LIST_HEAD (& list );
12041222 mutex_lock (& dpm_list_mtx );
@@ -1258,10 +1276,15 @@ static bool dpm_leaf_device(struct device *dev)
12581276 return false;
12591277 }
12601278
1261- return true;
1279+ /*
1280+ * Since this function is required to run under dpm_list_mtx, the
1281+ * list_empty() below will only return true if the device's list of
1282+ * consumers is actually empty before calling it.
1283+ */
1284+ return list_empty (& dev -> links .consumers );
12621285}
12631286
1264- static void dpm_async_suspend_parent (struct device * dev , async_func_t func )
1287+ static bool dpm_async_suspend_parent (struct device * dev , async_func_t func )
12651288{
12661289 guard (mutex )(& dpm_list_mtx );
12671290
@@ -1273,11 +1296,31 @@ static void dpm_async_suspend_parent(struct device *dev, async_func_t func)
12731296 * deleted before it.
12741297 */
12751298 if (!device_pm_initialized (dev ))
1276- return ;
1299+ return false ;
12771300
12781301 /* Start processing the device's parent if it is "async". */
12791302 if (dev -> parent )
12801303 dpm_async_with_cleanup (dev -> parent , func );
1304+
1305+ return true;
1306+ }
1307+
1308+ static void dpm_async_suspend_superior (struct device * dev , async_func_t func )
1309+ {
1310+ struct device_link * link ;
1311+ int idx ;
1312+
1313+ if (!dpm_async_suspend_parent (dev , func ))
1314+ return ;
1315+
1316+ idx = device_links_read_lock ();
1317+
1318+ /* Start processing the device's "async" suppliers. */
1319+ list_for_each_entry_rcu (link , & dev -> links .suppliers , c_node )
1320+ if (READ_ONCE (link -> status ) != DL_STATE_DORMANT )
1321+ dpm_async_with_cleanup (link -> supplier , func );
1322+
1323+ device_links_read_unlock (idx );
12811324}
12821325
12831326static void dpm_async_suspend_complete_all (struct list_head * device_list )
@@ -1417,7 +1460,7 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state, bool asy
14171460 if (error || async_error )
14181461 return error ;
14191462
1420- dpm_async_suspend_parent (dev , async_suspend_noirq );
1463+ dpm_async_suspend_superior (dev , async_suspend_noirq );
14211464
14221465 return 0 ;
14231466}
@@ -1614,7 +1657,7 @@ static int device_suspend_late(struct device *dev, pm_message_t state, bool asyn
16141657 if (error || async_error )
16151658 return error ;
16161659
1617- dpm_async_suspend_parent (dev , async_suspend_late );
1660+ dpm_async_suspend_superior (dev , async_suspend_late );
16181661
16191662 return 0 ;
16201663}
@@ -1906,7 +1949,7 @@ static int device_suspend(struct device *dev, pm_message_t state, bool async)
19061949 if (error || async_error )
19071950 return error ;
19081951
1909- dpm_async_suspend_parent (dev , async_suspend );
1952+ dpm_async_suspend_superior (dev , async_suspend );
19101953
19111954 return 0 ;
19121955}
@@ -2129,7 +2172,6 @@ int dpm_prepare(pm_message_t state)
21292172 int error = 0 ;
21302173
21312174 trace_suspend_resume (TPS ("dpm_prepare" ), state .event , true);
2132- might_sleep ();
21332175
21342176 /*
21352177 * Give a chance for the known devices to complete their probes, before
0 commit comments