aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pwm/core.c
diff options
context:
space:
mode:
authorBoris BREZILLON <boris.brezillon@free-electrons.com>2016-03-30 16:03:27 -0400
committerThierry Reding <thierry.reding@gmail.com>2016-05-17 08:44:59 -0400
commit459a25afe97cb3d7f978b90c881f4d7aac8fb755 (patch)
tree233902a29b5d0f418de168ffe531149b997cbcf4 /drivers/pwm/core.c
parent4ff66efd59102280a71d432c9f0e89cdaf66b849 (diff)
pwm: Get rid of pwm->lock
PWM devices are not protected against concurrent accesses. The lock in struct pwm_device might let PWM users think it is, but it's actually only protecting the enabled state. Removing this lock should be fine as long as all PWM users are aware that accesses to the PWM device have to be serialized, which seems to be the case for all of them except the sysfs interface. Patch the sysfs code by adding a lock to the pwm_export struct and making sure it's taken for all relevant accesses to the exported PWM device. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm/core.c')
-rw-r--r--drivers/pwm/core.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 22cf3959041c..cb762cf51332 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -269,7 +269,6 @@ int pwmchip_add_with_polarity(struct pwm_chip *chip,
269 pwm->pwm = chip->base + i; 269 pwm->pwm = chip->base + i;
270 pwm->hwpwm = i; 270 pwm->hwpwm = i;
271 pwm->polarity = polarity; 271 pwm->polarity = polarity;
272 mutex_init(&pwm->lock);
273 272
274 radix_tree_insert(&pwm_tree, pwm->pwm, pwm); 273 radix_tree_insert(&pwm_tree, pwm->pwm, pwm);
275 } 274 }
@@ -474,22 +473,16 @@ int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity)
474 if (!pwm->chip->ops->set_polarity) 473 if (!pwm->chip->ops->set_polarity)
475 return -ENOSYS; 474 return -ENOSYS;
476 475
477 mutex_lock(&pwm->lock); 476 if (pwm_is_enabled(pwm))
478 477 return -EBUSY;
479 if (pwm_is_enabled(pwm)) {
480 err = -EBUSY;
481 goto unlock;
482 }
483 478
484 err = pwm->chip->ops->set_polarity(pwm->chip, pwm, polarity); 479 err = pwm->chip->ops->set_polarity(pwm->chip, pwm, polarity);
485 if (err) 480 if (err)
486 goto unlock; 481 return err;
487 482
488 pwm->polarity = polarity; 483 pwm->polarity = polarity;
489 484
490unlock: 485 return 0;
491 mutex_unlock(&pwm->lock);
492 return err;
493} 486}
494EXPORT_SYMBOL_GPL(pwm_set_polarity); 487EXPORT_SYMBOL_GPL(pwm_set_polarity);
495 488
@@ -506,16 +499,12 @@ int pwm_enable(struct pwm_device *pwm)
506 if (!pwm) 499 if (!pwm)
507 return -EINVAL; 500 return -EINVAL;
508 501
509 mutex_lock(&pwm->lock);
510
511 if (!test_and_set_bit(PWMF_ENABLED, &pwm->flags)) { 502 if (!test_and_set_bit(PWMF_ENABLED, &pwm->flags)) {
512 err = pwm->chip->ops->enable(pwm->chip, pwm); 503 err = pwm->chip->ops->enable(pwm->chip, pwm);
513 if (err) 504 if (err)
514 clear_bit(PWMF_ENABLED, &pwm->flags); 505 clear_bit(PWMF_ENABLED, &pwm->flags);
515 } 506 }
516 507
517 mutex_unlock(&pwm->lock);
518
519 return err; 508 return err;
520} 509}
521EXPORT_SYMBOL_GPL(pwm_enable); 510EXPORT_SYMBOL_GPL(pwm_enable);