@@ -1343,14 +1343,12 @@ static LIST_HEAD(pwm_lookup_list);
1343
1343
*/
1344
1344
void pwm_add_table (struct pwm_lookup * table , size_t num )
1345
1345
{
1346
- mutex_lock (& pwm_lookup_lock );
1346
+ guard ( mutex ) (& pwm_lookup_lock );
1347
1347
1348
1348
while (num -- ) {
1349
1349
list_add_tail (& table -> list , & pwm_lookup_list );
1350
1350
table ++ ;
1351
1351
}
1352
-
1353
- mutex_unlock (& pwm_lookup_lock );
1354
1352
}
1355
1353
1356
1354
/**
@@ -1360,14 +1358,12 @@ void pwm_add_table(struct pwm_lookup *table, size_t num)
1360
1358
*/
1361
1359
void pwm_remove_table (struct pwm_lookup * table , size_t num )
1362
1360
{
1363
- mutex_lock (& pwm_lookup_lock );
1361
+ guard ( mutex ) (& pwm_lookup_lock );
1364
1362
1365
1363
while (num -- ) {
1366
1364
list_del (& table -> list );
1367
1365
table ++ ;
1368
1366
}
1369
-
1370
- mutex_unlock (& pwm_lookup_lock );
1371
1367
}
1372
1368
1373
1369
/**
@@ -1428,36 +1424,33 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
1428
1424
* Then we take the most specific entry - with the following order
1429
1425
* of precedence: dev+con > dev only > con only.
1430
1426
*/
1431
- mutex_lock (& pwm_lookup_lock );
1427
+ scoped_guard (mutex , & pwm_lookup_lock )
1428
+ list_for_each_entry (p , & pwm_lookup_list , list ) {
1429
+ match = 0 ;
1432
1430
1433
- list_for_each_entry (p , & pwm_lookup_list , list ) {
1434
- match = 0 ;
1431
+ if (p -> dev_id ) {
1432
+ if (!dev_id || strcmp (p -> dev_id , dev_id ))
1433
+ continue ;
1435
1434
1436
- if (p -> dev_id ) {
1437
- if (!dev_id || strcmp (p -> dev_id , dev_id ))
1438
- continue ;
1435
+ match += 2 ;
1436
+ }
1439
1437
1440
- match += 2 ;
1441
- }
1438
+ if (p -> con_id ) {
1439
+ if (!con_id || strcmp (p -> con_id , con_id ))
1440
+ continue ;
1442
1441
1443
- if (p -> con_id ) {
1444
- if (!con_id || strcmp (p -> con_id , con_id ))
1445
- continue ;
1442
+ match += 1 ;
1443
+ }
1446
1444
1447
- match += 1 ;
1448
- }
1445
+ if ( match > best ) {
1446
+ chosen = p ;
1449
1447
1450
- if (match > best ) {
1451
- chosen = p ;
1452
-
1453
- if (match != 3 )
1454
- best = match ;
1455
- else
1456
- break ;
1448
+ if (match != 3 )
1449
+ best = match ;
1450
+ else
1451
+ break ;
1452
+ }
1457
1453
}
1458
- }
1459
-
1460
- mutex_unlock (& pwm_lookup_lock );
1461
1454
1462
1455
if (!chosen )
1463
1456
return ERR_PTR (- ENODEV );
0 commit comments