Commit 650af6c0 authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Uwe Kleine-König

pwm: Use guards for pwm_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/2102fe8189bdf1f02ff3785b551a69be27a65af4.1719520143.git.u.kleine-koenig@baylibre.comSigned-off-by: default avatarUwe Kleine-König <ukleinek@kernel.org>
parent 44ee9518
...@@ -293,19 +293,15 @@ EXPORT_SYMBOL_GPL(pwm_adjust_config); ...@@ -293,19 +293,15 @@ EXPORT_SYMBOL_GPL(pwm_adjust_config);
int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result, int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result,
unsigned long timeout) unsigned long timeout)
{ {
int err;
if (!pwm || !pwm->chip->ops) if (!pwm || !pwm->chip->ops)
return -EINVAL; return -EINVAL;
if (!pwm->chip->ops->capture) if (!pwm->chip->ops->capture)
return -ENOSYS; return -ENOSYS;
mutex_lock(&pwm_lock); guard(mutex)(&pwm_lock);
err = pwm->chip->ops->capture(pwm->chip, pwm, result, timeout);
mutex_unlock(&pwm_lock);
return err; return pwm->chip->ops->capture(pwm->chip, pwm, result, timeout);
} }
EXPORT_SYMBOL_GPL(pwm_capture); EXPORT_SYMBOL_GPL(pwm_capture);
...@@ -317,19 +313,15 @@ static struct pwm_chip *pwmchip_find_by_name(const char *name) ...@@ -317,19 +313,15 @@ static struct pwm_chip *pwmchip_find_by_name(const char *name)
if (!name) if (!name)
return NULL; return NULL;
mutex_lock(&pwm_lock); guard(mutex)(&pwm_lock);
idr_for_each_entry_ul(&pwm_chips, chip, tmp, id) { idr_for_each_entry_ul(&pwm_chips, chip, tmp, id) {
const char *chip_name = dev_name(pwmchip_parent(chip)); const char *chip_name = dev_name(pwmchip_parent(chip));
if (chip_name && strcmp(chip_name, name) == 0) { if (chip_name && strcmp(chip_name, name) == 0)
mutex_unlock(&pwm_lock);
return chip; return chip;
}
} }
mutex_unlock(&pwm_lock);
return NULL; return NULL;
} }
...@@ -406,14 +398,14 @@ static struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, ...@@ -406,14 +398,14 @@ static struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
if (!chip || index >= chip->npwm) if (!chip || index >= chip->npwm)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
mutex_lock(&pwm_lock); guard(mutex)(&pwm_lock);
pwm = &chip->pwms[index]; pwm = &chip->pwms[index];
err = pwm_device_request(pwm, label); err = pwm_device_request(pwm, label);
if (err < 0) if (err < 0)
pwm = ERR_PTR(err); return ERR_PTR(err);
mutex_unlock(&pwm_lock);
return pwm; return pwm;
} }
...@@ -1102,11 +1094,11 @@ int __pwmchip_add(struct pwm_chip *chip, struct module *owner) ...@@ -1102,11 +1094,11 @@ int __pwmchip_add(struct pwm_chip *chip, struct module *owner)
chip->owner = owner; chip->owner = owner;
mutex_lock(&pwm_lock); guard(mutex)(&pwm_lock);
ret = idr_alloc(&pwm_chips, chip, 0, 0, GFP_KERNEL); ret = idr_alloc(&pwm_chips, chip, 0, 0, GFP_KERNEL);
if (ret < 0) if (ret < 0)
goto err_idr_alloc; return ret;
chip->id = ret; chip->id = ret;
...@@ -1119,8 +1111,6 @@ int __pwmchip_add(struct pwm_chip *chip, struct module *owner) ...@@ -1119,8 +1111,6 @@ int __pwmchip_add(struct pwm_chip *chip, struct module *owner)
if (ret) if (ret)
goto err_device_add; goto err_device_add;
mutex_unlock(&pwm_lock);
return 0; return 0;
err_device_add: err_device_add:
...@@ -1128,9 +1118,6 @@ int __pwmchip_add(struct pwm_chip *chip, struct module *owner) ...@@ -1128,9 +1118,6 @@ int __pwmchip_add(struct pwm_chip *chip, struct module *owner)
of_pwmchip_remove(chip); of_pwmchip_remove(chip);
idr_remove(&pwm_chips, chip->id); idr_remove(&pwm_chips, chip->id);
err_idr_alloc:
mutex_unlock(&pwm_lock);
return ret; return ret;
} }
...@@ -1149,11 +1136,8 @@ void pwmchip_remove(struct pwm_chip *chip) ...@@ -1149,11 +1136,8 @@ void pwmchip_remove(struct pwm_chip *chip)
if (IS_ENABLED(CONFIG_OF)) if (IS_ENABLED(CONFIG_OF))
of_pwmchip_remove(chip); of_pwmchip_remove(chip);
mutex_lock(&pwm_lock); scoped_guard(mutex, &pwm_lock)
idr_remove(&pwm_chips, chip->id);
idr_remove(&pwm_chips, chip->id);
mutex_unlock(&pwm_lock);
device_del(&chip->dev); device_del(&chip->dev);
} }
...@@ -1209,15 +1193,11 @@ static struct pwm_chip *fwnode_to_pwmchip(struct fwnode_handle *fwnode) ...@@ -1209,15 +1193,11 @@ static struct pwm_chip *fwnode_to_pwmchip(struct fwnode_handle *fwnode)
struct pwm_chip *chip; struct pwm_chip *chip;
unsigned long id, tmp; unsigned long id, tmp;
mutex_lock(&pwm_lock); guard(mutex)(&pwm_lock);
idr_for_each_entry_ul(&pwm_chips, chip, tmp, id) idr_for_each_entry_ul(&pwm_chips, chip, tmp, id)
if (pwmchip_parent(chip) && device_match_fwnode(pwmchip_parent(chip), fwnode)) { if (pwmchip_parent(chip) && device_match_fwnode(pwmchip_parent(chip), fwnode))
mutex_unlock(&pwm_lock);
return chip; return chip;
}
mutex_unlock(&pwm_lock);
return ERR_PTR(-EPROBE_DEFER); return ERR_PTR(-EPROBE_DEFER);
} }
...@@ -1532,11 +1512,11 @@ void pwm_put(struct pwm_device *pwm) ...@@ -1532,11 +1512,11 @@ void pwm_put(struct pwm_device *pwm)
chip = pwm->chip; chip = pwm->chip;
mutex_lock(&pwm_lock); guard(mutex)(&pwm_lock);
if (!test_and_clear_bit(PWMF_REQUESTED, &pwm->flags)) { if (!test_and_clear_bit(PWMF_REQUESTED, &pwm->flags)) {
pr_warn("PWM device already freed\n"); pr_warn("PWM device already freed\n");
goto out; return;
} }
if (chip->ops->free) if (chip->ops->free)
...@@ -1547,8 +1527,6 @@ void pwm_put(struct pwm_device *pwm) ...@@ -1547,8 +1527,6 @@ void pwm_put(struct pwm_device *pwm)
put_device(&chip->dev); put_device(&chip->dev);
module_put(chip->owner); module_put(chip->owner);
out:
mutex_unlock(&pwm_lock);
} }
EXPORT_SYMBOL_GPL(pwm_put); EXPORT_SYMBOL_GPL(pwm_put);
......
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