@@ -710,6 +710,7 @@ static void dpm_noirq_resume_devices(pm_message_t state)
710
710
dev = to_device (dpm_noirq_list .next );
711
711
get_device (dev );
712
712
list_move_tail (& dev -> power .entry , & dpm_late_early_list );
713
+
713
714
mutex_unlock (& dpm_list_mtx );
714
715
715
716
if (!is_async (dev )) {
@@ -724,8 +725,9 @@ static void dpm_noirq_resume_devices(pm_message_t state)
724
725
}
725
726
}
726
727
727
- mutex_lock (& dpm_list_mtx );
728
728
put_device (dev );
729
+
730
+ mutex_lock (& dpm_list_mtx );
729
731
}
730
732
mutex_unlock (& dpm_list_mtx );
731
733
async_synchronize_full ();
@@ -849,6 +851,7 @@ void dpm_resume_early(pm_message_t state)
849
851
dev = to_device (dpm_late_early_list .next );
850
852
get_device (dev );
851
853
list_move_tail (& dev -> power .entry , & dpm_suspended_list );
854
+
852
855
mutex_unlock (& dpm_list_mtx );
853
856
854
857
if (!is_async (dev )) {
@@ -862,8 +865,10 @@ void dpm_resume_early(pm_message_t state)
862
865
pm_dev_err (dev , state , " early" , error );
863
866
}
864
867
}
865
- mutex_lock ( & dpm_list_mtx );
868
+
866
869
put_device (dev );
870
+
871
+ mutex_lock (& dpm_list_mtx );
867
872
}
868
873
mutex_unlock (& dpm_list_mtx );
869
874
async_synchronize_full ();
@@ -1026,7 +1031,12 @@ void dpm_resume(pm_message_t state)
1026
1031
}
1027
1032
if (!list_empty (& dev -> power .entry ))
1028
1033
list_move_tail (& dev -> power .entry , & dpm_prepared_list );
1034
+
1035
+ mutex_unlock (& dpm_list_mtx );
1036
+
1029
1037
put_device (dev );
1038
+
1039
+ mutex_lock (& dpm_list_mtx );
1030
1040
}
1031
1041
mutex_unlock (& dpm_list_mtx );
1032
1042
async_synchronize_full ();
@@ -1104,14 +1114,16 @@ void dpm_complete(pm_message_t state)
1104
1114
get_device (dev );
1105
1115
dev -> power .is_prepared = false;
1106
1116
list_move (& dev -> power .entry , & list );
1117
+
1107
1118
mutex_unlock (& dpm_list_mtx );
1108
1119
1109
1120
trace_device_pm_callback_start (dev , "" , state .event );
1110
1121
device_complete (dev , state );
1111
1122
trace_device_pm_callback_end (dev , 0 );
1112
1123
1113
- mutex_lock (& dpm_list_mtx );
1114
1124
put_device (dev );
1125
+
1126
+ mutex_lock (& dpm_list_mtx );
1115
1127
}
1116
1128
list_splice (& list , & dpm_list );
1117
1129
mutex_unlock (& dpm_list_mtx );
@@ -1296,17 +1308,21 @@ static int dpm_noirq_suspend_devices(pm_message_t state)
1296
1308
error = device_suspend_noirq (dev );
1297
1309
1298
1310
mutex_lock (& dpm_list_mtx );
1311
+
1299
1312
if (error ) {
1300
1313
pm_dev_err (dev , state , " noirq" , error );
1301
1314
dpm_save_failed_dev (dev_name (dev ));
1302
- put_device (dev );
1303
- break ;
1304
- }
1305
- if (!list_empty (& dev -> power .entry ))
1315
+ } else if (!list_empty (& dev -> power .entry )) {
1306
1316
list_move (& dev -> power .entry , & dpm_noirq_list );
1317
+ }
1318
+
1319
+ mutex_unlock (& dpm_list_mtx );
1320
+
1307
1321
put_device (dev );
1308
1322
1309
- if (async_error )
1323
+ mutex_lock (& dpm_list_mtx );
1324
+
1325
+ if (error || async_error )
1310
1326
break ;
1311
1327
}
1312
1328
mutex_unlock (& dpm_list_mtx );
@@ -1472,23 +1488,28 @@ int dpm_suspend_late(pm_message_t state)
1472
1488
struct device * dev = to_device (dpm_suspended_list .prev );
1473
1489
1474
1490
get_device (dev );
1491
+
1475
1492
mutex_unlock (& dpm_list_mtx );
1476
1493
1477
1494
error = device_suspend_late (dev );
1478
1495
1479
1496
mutex_lock (& dpm_list_mtx );
1497
+
1480
1498
if (!list_empty (& dev -> power .entry ))
1481
1499
list_move (& dev -> power .entry , & dpm_late_early_list );
1482
1500
1483
1501
if (error ) {
1484
1502
pm_dev_err (dev , state , " late" , error );
1485
1503
dpm_save_failed_dev (dev_name (dev ));
1486
- put_device (dev );
1487
- break ;
1488
1504
}
1505
+
1506
+ mutex_unlock (& dpm_list_mtx );
1507
+
1489
1508
put_device (dev );
1490
1509
1491
- if (async_error )
1510
+ mutex_lock (& dpm_list_mtx );
1511
+
1512
+ if (error || async_error )
1492
1513
break ;
1493
1514
}
1494
1515
mutex_unlock (& dpm_list_mtx );
@@ -1748,21 +1769,27 @@ int dpm_suspend(pm_message_t state)
1748
1769
struct device * dev = to_device (dpm_prepared_list .prev );
1749
1770
1750
1771
get_device (dev );
1772
+
1751
1773
mutex_unlock (& dpm_list_mtx );
1752
1774
1753
1775
error = device_suspend (dev );
1754
1776
1755
1777
mutex_lock (& dpm_list_mtx );
1778
+
1756
1779
if (error ) {
1757
1780
pm_dev_err (dev , state , "" , error );
1758
1781
dpm_save_failed_dev (dev_name (dev ));
1759
- put_device (dev );
1760
- break ;
1761
- }
1762
- if (!list_empty (& dev -> power .entry ))
1782
+ } else if (!list_empty (& dev -> power .entry )) {
1763
1783
list_move (& dev -> power .entry , & dpm_suspended_list );
1784
+ }
1785
+
1786
+ mutex_unlock (& dpm_list_mtx );
1787
+
1764
1788
put_device (dev );
1765
- if (async_error )
1789
+
1790
+ mutex_lock (& dpm_list_mtx );
1791
+
1792
+ if (error || async_error )
1766
1793
break ;
1767
1794
}
1768
1795
mutex_unlock (& dpm_list_mtx );
@@ -1879,28 +1906,31 @@ int dpm_prepare(pm_message_t state)
1879
1906
struct device * dev = to_device (dpm_list .next );
1880
1907
1881
1908
get_device (dev );
1909
+
1882
1910
mutex_unlock (& dpm_list_mtx );
1883
1911
1884
1912
trace_device_pm_callback_start (dev , "" , state .event );
1885
1913
error = device_prepare (dev , state );
1886
1914
trace_device_pm_callback_end (dev , error );
1887
1915
1888
1916
mutex_lock (& dpm_list_mtx );
1889
- if (error ) {
1890
- if (error == - EAGAIN ) {
1891
- put_device (dev );
1892
- error = 0 ;
1893
- continue ;
1894
- }
1917
+
1918
+ if (!error ) {
1919
+ dev -> power .is_prepared = true;
1920
+ if (!list_empty (& dev -> power .entry ))
1921
+ list_move_tail (& dev -> power .entry , & dpm_prepared_list );
1922
+ } else if (error == - EAGAIN ) {
1923
+ error = 0 ;
1924
+ } else {
1895
1925
dev_info (dev , "not prepared for power transition: code %d\n" ,
1896
1926
error );
1897
- put_device (dev );
1898
- break ;
1899
1927
}
1900
- dev -> power . is_prepared = true;
1901
- if (! list_empty ( & dev -> power . entry ))
1902
- list_move_tail ( & dev -> power . entry , & dpm_prepared_list );
1928
+
1929
+ mutex_unlock ( & dpm_list_mtx );
1930
+
1903
1931
put_device (dev );
1932
+
1933
+ mutex_lock (& dpm_list_mtx );
1904
1934
}
1905
1935
mutex_unlock (& dpm_list_mtx );
1906
1936
trace_suspend_resume (TPS ("dpm_prepare" ), state .event , false);
0 commit comments