Commit 0007fa12 authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Uwe Kleine-König

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: default avatarUwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/28807cb5d9dbce66860f74829c0f57cd9c01373e.1719520143.git.u.kleine-koenig@baylibre.comSigned-off-by: default avatarUwe Kleine-König <ukleinek@kernel.org>
parent 4c50c71c
...@@ -1343,14 +1343,12 @@ static LIST_HEAD(pwm_lookup_list); ...@@ -1343,14 +1343,12 @@ static LIST_HEAD(pwm_lookup_list);
*/ */
void pwm_add_table(struct pwm_lookup *table, size_t num) void pwm_add_table(struct pwm_lookup *table, size_t num)
{ {
mutex_lock(&pwm_lookup_lock); guard(mutex)(&pwm_lookup_lock);
while (num--) { while (num--) {
list_add_tail(&table->list, &pwm_lookup_list); list_add_tail(&table->list, &pwm_lookup_list);
table++; table++;
} }
mutex_unlock(&pwm_lookup_lock);
} }
/** /**
...@@ -1360,14 +1358,12 @@ void pwm_add_table(struct pwm_lookup *table, size_t num) ...@@ -1360,14 +1358,12 @@ void pwm_add_table(struct pwm_lookup *table, size_t num)
*/ */
void pwm_remove_table(struct pwm_lookup *table, size_t num) void pwm_remove_table(struct pwm_lookup *table, size_t num)
{ {
mutex_lock(&pwm_lookup_lock); guard(mutex)(&pwm_lookup_lock);
while (num--) { while (num--) {
list_del(&table->list); list_del(&table->list);
table++; table++;
} }
mutex_unlock(&pwm_lookup_lock);
} }
/** /**
...@@ -1428,8 +1424,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id) ...@@ -1428,8 +1424,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
* Then we take the most specific entry - with the following order * Then we take the most specific entry - with the following order
* of precedence: dev+con > dev only > con only. * of precedence: dev+con > dev only > con only.
*/ */
mutex_lock(&pwm_lookup_lock); scoped_guard(mutex, &pwm_lookup_lock)
list_for_each_entry(p, &pwm_lookup_list, list) { list_for_each_entry(p, &pwm_lookup_list, list) {
match = 0; match = 0;
...@@ -1457,8 +1452,6 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id) ...@@ -1457,8 +1452,6 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
} }
} }
mutex_unlock(&pwm_lookup_lock);
if (!chosen) if (!chosen)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment