@@ -98,12 +98,9 @@ static int __fwnode_link_add(struct fwnode_handle *con,
98
98
int fwnode_link_add (struct fwnode_handle * con , struct fwnode_handle * sup ,
99
99
u8 flags )
100
100
{
101
- int ret ;
101
+ guard ( mutex )( & fwnode_link_lock ) ;
102
102
103
- mutex_lock (& fwnode_link_lock );
104
- ret = __fwnode_link_add (con , sup , flags );
105
- mutex_unlock (& fwnode_link_lock );
106
- return ret ;
103
+ return __fwnode_link_add (con , sup , flags );
107
104
}
108
105
109
106
/**
@@ -144,10 +141,10 @@ static void fwnode_links_purge_suppliers(struct fwnode_handle *fwnode)
144
141
{
145
142
struct fwnode_link * link , * tmp ;
146
143
147
- mutex_lock (& fwnode_link_lock );
144
+ guard (mutex )(& fwnode_link_lock );
145
+
148
146
list_for_each_entry_safe (link , tmp , & fwnode -> suppliers , c_hook )
149
147
__fwnode_link_del (link );
150
- mutex_unlock (& fwnode_link_lock );
151
148
}
152
149
153
150
/**
@@ -160,10 +157,10 @@ static void fwnode_links_purge_consumers(struct fwnode_handle *fwnode)
160
157
{
161
158
struct fwnode_link * link , * tmp ;
162
159
163
- mutex_lock (& fwnode_link_lock );
160
+ guard (mutex )(& fwnode_link_lock );
161
+
164
162
list_for_each_entry_safe (link , tmp , & fwnode -> consumers , s_hook )
165
163
__fwnode_link_del (link );
166
- mutex_unlock (& fwnode_link_lock );
167
164
}
168
165
169
166
/**
@@ -1059,20 +1056,16 @@ int device_links_check_suppliers(struct device *dev)
1059
1056
* Device waiting for supplier to become available is not allowed to
1060
1057
* probe.
1061
1058
*/
1062
- mutex_lock (& fwnode_link_lock );
1063
- sup_fw = fwnode_links_check_suppliers (dev -> fwnode );
1064
- if (sup_fw ) {
1065
- if (!dev_is_best_effort (dev )) {
1066
- fwnode_ret = - EPROBE_DEFER ;
1067
- dev_err_probe (dev , - EPROBE_DEFER ,
1068
- "wait for supplier %pfwf\n" , sup_fw );
1069
- } else {
1070
- fwnode_ret = - EAGAIN ;
1059
+ scoped_guard (mutex , & fwnode_link_lock ) {
1060
+ sup_fw = fwnode_links_check_suppliers (dev -> fwnode );
1061
+ if (sup_fw ) {
1062
+ if (dev_is_best_effort (dev ))
1063
+ fwnode_ret = - EAGAIN ;
1064
+ else
1065
+ return dev_err_probe (dev , - EPROBE_DEFER ,
1066
+ "wait for supplier %pfwf\n" , sup_fw );
1071
1067
}
1072
1068
}
1073
- mutex_unlock (& fwnode_link_lock );
1074
- if (fwnode_ret == - EPROBE_DEFER )
1075
- return fwnode_ret ;
1076
1069
1077
1070
device_links_write_lock ();
1078
1071
@@ -1247,9 +1240,8 @@ static ssize_t waiting_for_supplier_show(struct device *dev,
1247
1240
bool val ;
1248
1241
1249
1242
device_lock (dev );
1250
- mutex_lock (& fwnode_link_lock );
1251
- val = !!fwnode_links_check_suppliers (dev -> fwnode );
1252
- mutex_unlock (& fwnode_link_lock );
1243
+ scoped_guard (mutex , & fwnode_link_lock )
1244
+ val = !!fwnode_links_check_suppliers (dev -> fwnode );
1253
1245
device_unlock (dev );
1254
1246
return sysfs_emit (buf , "%u\n" , val );
1255
1247
}
@@ -1322,13 +1314,15 @@ void device_links_driver_bound(struct device *dev)
1322
1314
*/
1323
1315
if (dev -> fwnode && dev -> fwnode -> dev == dev ) {
1324
1316
struct fwnode_handle * child ;
1317
+
1325
1318
fwnode_links_purge_suppliers (dev -> fwnode );
1326
- mutex_lock (& fwnode_link_lock );
1319
+
1320
+ guard (mutex )(& fwnode_link_lock );
1321
+
1327
1322
fwnode_for_each_available_child_node (dev -> fwnode , child )
1328
1323
__fw_devlink_pickup_dangling_consumers (child ,
1329
1324
dev -> fwnode );
1330
1325
__fw_devlink_link_to_consumers (dev );
1331
- mutex_unlock (& fwnode_link_lock );
1332
1326
}
1333
1327
device_remove_file (dev , & dev_attr_waiting_for_supplier );
1334
1328
@@ -2337,10 +2331,10 @@ static void fw_devlink_link_device(struct device *dev)
2337
2331
2338
2332
fw_devlink_parse_fwtree (fwnode );
2339
2333
2340
- mutex_lock (& fwnode_link_lock );
2334
+ guard (mutex )(& fwnode_link_lock );
2335
+
2341
2336
__fw_devlink_link_to_consumers (dev );
2342
2337
__fw_devlink_link_to_suppliers (dev , fwnode );
2343
- mutex_unlock (& fwnode_link_lock );
2344
2338
}
2345
2339
2346
2340
/* Device links support end. */
0 commit comments