Skip to content

Commit 4c50c71

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: Use guards for export->lock instead of explicity mutex_lock + mutex_unlock
With the compiler caring for unlocking the mutex several functions can be simplified. Benefit from that. There is just one caller left for mutex_lock(&export->lock). The code flow is too complicated there to convert it to the compiler assisted variant. Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/210010f2e579a92476462726e18e0135f6854909.1719520143.git.u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 650af6c commit 4c50c71

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

drivers/pwm/core.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,11 @@ static ssize_t period_store(struct device *pwm_dev,
503503
if (ret)
504504
return ret;
505505

506-
mutex_lock(&export->lock);
506+
guard(mutex)(&export->lock);
507+
507508
pwm_get_state(pwm, &state);
508509
state.period = val;
509510
ret = pwm_apply_might_sleep(pwm, &state);
510-
mutex_unlock(&export->lock);
511511

512512
return ret ? : size;
513513
}
@@ -538,11 +538,11 @@ static ssize_t duty_cycle_store(struct device *pwm_dev,
538538
if (ret)
539539
return ret;
540540

541-
mutex_lock(&export->lock);
541+
guard(mutex)(&export->lock);
542+
542543
pwm_get_state(pwm, &state);
543544
state.duty_cycle = val;
544545
ret = pwm_apply_might_sleep(pwm, &state);
545-
mutex_unlock(&export->lock);
546546

547547
return ret ? : size;
548548
}
@@ -572,7 +572,7 @@ static ssize_t enable_store(struct device *pwm_dev,
572572
if (ret)
573573
return ret;
574574

575-
mutex_lock(&export->lock);
575+
guard(mutex)(&export->lock);
576576

577577
pwm_get_state(pwm, &state);
578578

@@ -584,14 +584,11 @@ static ssize_t enable_store(struct device *pwm_dev,
584584
state.enabled = true;
585585
break;
586586
default:
587-
ret = -EINVAL;
588-
goto unlock;
587+
return -EINVAL;
589588
}
590589

591590
ret = pwm_apply_might_sleep(pwm, &state);
592591

593-
unlock:
594-
mutex_unlock(&export->lock);
595592
return ret ? : size;
596593
}
597594

@@ -635,11 +632,11 @@ static ssize_t polarity_store(struct device *pwm_dev,
635632
else
636633
return -EINVAL;
637634

638-
mutex_lock(&export->lock);
635+
guard(mutex)(&export->lock);
636+
639637
pwm_get_state(pwm, &state);
640638
state.polarity = polarity;
641639
ret = pwm_apply_might_sleep(pwm, &state);
642-
mutex_unlock(&export->lock);
643640

644641
return ret ? : size;
645642
}

0 commit comments

Comments
 (0)