Skip to content

Commit 0007fa1

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: Use guards for pwm_lookup_lock instead of explicity mutex_lock + mutex_unlock
With the compiler caring for unlocking the mutex several functions can be simplified. Benefit from that. Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/28807cb5d9dbce66860f74829c0f57cd9c01373e.1719520143.git.u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 4c50c71 commit 0007fa1

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

drivers/pwm/core.c

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,14 +1343,12 @@ static LIST_HEAD(pwm_lookup_list);
13431343
*/
13441344
void pwm_add_table(struct pwm_lookup *table, size_t num)
13451345
{
1346-
mutex_lock(&pwm_lookup_lock);
1346+
guard(mutex)(&pwm_lookup_lock);
13471347

13481348
while (num--) {
13491349
list_add_tail(&table->list, &pwm_lookup_list);
13501350
table++;
13511351
}
1352-
1353-
mutex_unlock(&pwm_lookup_lock);
13541352
}
13551353

13561354
/**
@@ -1360,14 +1358,12 @@ void pwm_add_table(struct pwm_lookup *table, size_t num)
13601358
*/
13611359
void pwm_remove_table(struct pwm_lookup *table, size_t num)
13621360
{
1363-
mutex_lock(&pwm_lookup_lock);
1361+
guard(mutex)(&pwm_lookup_lock);
13641362

13651363
while (num--) {
13661364
list_del(&table->list);
13671365
table++;
13681366
}
1369-
1370-
mutex_unlock(&pwm_lookup_lock);
13711367
}
13721368

13731369
/**
@@ -1428,36 +1424,33 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
14281424
* Then we take the most specific entry - with the following order
14291425
* of precedence: dev+con > dev only > con only.
14301426
*/
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;
14321430

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;
14351434

1436-
if (p->dev_id) {
1437-
if (!dev_id || strcmp(p->dev_id, dev_id))
1438-
continue;
1435+
match += 2;
1436+
}
14391437

1440-
match += 2;
1441-
}
1438+
if (p->con_id) {
1439+
if (!con_id || strcmp(p->con_id, con_id))
1440+
continue;
14421441

1443-
if (p->con_id) {
1444-
if (!con_id || strcmp(p->con_id, con_id))
1445-
continue;
1442+
match += 1;
1443+
}
14461444

1447-
match += 1;
1448-
}
1445+
if (match > best) {
1446+
chosen = p;
14491447

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+
}
14571453
}
1458-
}
1459-
1460-
mutex_unlock(&pwm_lookup_lock);
14611454

14621455
if (!chosen)
14631456
return ERR_PTR(-ENODEV);

0 commit comments

Comments
 (0)