summaryrefslogtreecommitdiffstats
path: root/drivers/pwm
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>2024-06-27 22:31:21 +0200
committerUwe Kleine-König <ukleinek@kernel.org>2024-07-10 17:53:52 +0200
commit0007fa1292a24ef23d662ec7afe178088ab7766d (patch)
tree653fef6a624d26e6ec2b8cc7952dbf7a340e68ad /drivers/pwm
parentpwm: Use guards for export->lock instead of explicity mutex_lock + mutex_unlock (diff)
downloadlinux-0007fa1292a24ef23d662ec7afe178088ab7766d.tar.xz
linux-0007fa1292a24ef23d662ec7afe178088ab7766d.zip
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 <u.kleine-koenig@baylibre.com> Link: https://lore.kernel.org/r/28807cb5d9dbce66860f74829c0f57cd9c01373e.1719520143.git.u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
Diffstat (limited to 'drivers/pwm')
-rw-r--r--drivers/pwm/core.c51
1 files changed, 22 insertions, 29 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 3df8397d7b2b..cf6d91f1a9e6 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -1343,14 +1343,12 @@ static LIST_HEAD(pwm_lookup_list);
*/
void pwm_add_table(struct pwm_lookup *table, size_t num)
{
- mutex_lock(&pwm_lookup_lock);
+ guard(mutex)(&pwm_lookup_lock);
while (num--) {
list_add_tail(&table->list, &pwm_lookup_list);
table++;
}
-
- mutex_unlock(&pwm_lookup_lock);
}
/**
@@ -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)
{
- mutex_lock(&pwm_lookup_lock);
+ guard(mutex)(&pwm_lookup_lock);
while (num--) {
list_del(&table->list);
table++;
}
-
- mutex_unlock(&pwm_lookup_lock);
}
/**
@@ -1428,36 +1424,33 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
* Then we take the most specific entry - with the following order
* 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) {
+ match = 0;
- list_for_each_entry(p, &pwm_lookup_list, list) {
- match = 0;
+ if (p->dev_id) {
+ if (!dev_id || strcmp(p->dev_id, dev_id))
+ continue;
- if (p->dev_id) {
- if (!dev_id || strcmp(p->dev_id, dev_id))
- continue;
+ match += 2;
+ }
- match += 2;
- }
+ if (p->con_id) {
+ if (!con_id || strcmp(p->con_id, con_id))
+ continue;
- if (p->con_id) {
- if (!con_id || strcmp(p->con_id, con_id))
- continue;
+ match += 1;
+ }
- match += 1;
- }
+ if (match > best) {
+ chosen = p;
- if (match > best) {
- chosen = p;
-
- if (match != 3)
- best = match;
- else
- break;
+ if (match != 3)
+ best = match;
+ else
+ break;
+ }
}
- }
-
- mutex_unlock(&pwm_lookup_lock);
if (!chosen)
return ERR_PTR(-ENODEV);