Commit 4c50c71c authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Uwe Kleine-König

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: default avatarUwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/210010f2e579a92476462726e18e0135f6854909.1719520143.git.u.kleine-koenig@baylibre.comSigned-off-by: default avatarUwe Kleine-König <ukleinek@kernel.org>
parent 650af6c0
...@@ -503,11 +503,11 @@ static ssize_t period_store(struct device *pwm_dev, ...@@ -503,11 +503,11 @@ static ssize_t period_store(struct device *pwm_dev,
if (ret) if (ret)
return ret; return ret;
mutex_lock(&export->lock); guard(mutex)(&export->lock);
pwm_get_state(pwm, &state); pwm_get_state(pwm, &state);
state.period = val; state.period = val;
ret = pwm_apply_might_sleep(pwm, &state); ret = pwm_apply_might_sleep(pwm, &state);
mutex_unlock(&export->lock);
return ret ? : size; return ret ? : size;
} }
...@@ -538,11 +538,11 @@ static ssize_t duty_cycle_store(struct device *pwm_dev, ...@@ -538,11 +538,11 @@ static ssize_t duty_cycle_store(struct device *pwm_dev,
if (ret) if (ret)
return ret; return ret;
mutex_lock(&export->lock); guard(mutex)(&export->lock);
pwm_get_state(pwm, &state); pwm_get_state(pwm, &state);
state.duty_cycle = val; state.duty_cycle = val;
ret = pwm_apply_might_sleep(pwm, &state); ret = pwm_apply_might_sleep(pwm, &state);
mutex_unlock(&export->lock);
return ret ? : size; return ret ? : size;
} }
...@@ -572,7 +572,7 @@ static ssize_t enable_store(struct device *pwm_dev, ...@@ -572,7 +572,7 @@ static ssize_t enable_store(struct device *pwm_dev,
if (ret) if (ret)
return ret; return ret;
mutex_lock(&export->lock); guard(mutex)(&export->lock);
pwm_get_state(pwm, &state); pwm_get_state(pwm, &state);
...@@ -584,14 +584,11 @@ static ssize_t enable_store(struct device *pwm_dev, ...@@ -584,14 +584,11 @@ static ssize_t enable_store(struct device *pwm_dev,
state.enabled = true; state.enabled = true;
break; break;
default: default:
ret = -EINVAL; return -EINVAL;
goto unlock;
} }
ret = pwm_apply_might_sleep(pwm, &state); ret = pwm_apply_might_sleep(pwm, &state);
unlock:
mutex_unlock(&export->lock);
return ret ? : size; return ret ? : size;
} }
...@@ -635,11 +632,11 @@ static ssize_t polarity_store(struct device *pwm_dev, ...@@ -635,11 +632,11 @@ static ssize_t polarity_store(struct device *pwm_dev,
else else
return -EINVAL; return -EINVAL;
mutex_lock(&export->lock); guard(mutex)(&export->lock);
pwm_get_state(pwm, &state); pwm_get_state(pwm, &state);
state.polarity = polarity; state.polarity = polarity;
ret = pwm_apply_might_sleep(pwm, &state); ret = pwm_apply_might_sleep(pwm, &state);
mutex_unlock(&export->lock);
return ret ? : size; return ret ? : size;
} }
......
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