Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1407717
| From | Brian Norris <briannorris@chromium.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH] pwm: don't allow duty cycle higher than period |
| Date | 2016-05-26 23:10 +0200 |
| Message-ID | <rDaHw-2Xq-17@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
It doesn't make sense to allow the duty cycle to be larger than the
period. I can see this behavior by, e.g.:
# echo 1 > /sys/class/pwm/pwmchip0/export
# cat /sys/class/pwm/pwmchip0/pwm1/period
100
# echo 101 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
[... driver may or may not reject the value, or trigger some logic bug ...]
It's better to see:
# echo 1 > /sys/class/pwm/pwmchip0/export
# cat /sys/class/pwm/pwmchip0/pwm1/period
100
# echo 101 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
-bash: echo: write error: Invalid argument
Signed-off-by: Brian Norris <briannorris@chromium.org>
---
drivers/pwm/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index dba3843c53b8..9246b60f894a 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -463,6 +463,9 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
if (!memcmp(state, &pwm->state, sizeof(*state)))
return 0;
+ if (state->duty_cycle > state->period)
+ return -EINVAL;
+
if (pwm->chip->ops->apply) {
err = pwm->chip->ops->apply(pwm->chip, pwm, state);
if (err)
--
2.8.0.rc3.226.g39d4020
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH] pwm: don't allow duty cycle higher than period Brian Norris <briannorris@chromium.org> - 2016-05-26 23:10 +0200
Re: [PATCH] pwm: don't allow duty cycle higher than period Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-05-27 09:40 +0200
Re: [PATCH] pwm: don't allow duty cycle higher than period Brian Norris <briannorris@chromium.org> - 2016-05-27 18:40 +0200
Re: [PATCH] pwm: don't allow duty cycle higher than period Brian Norris <briannorris@chromium.org> - 2016-05-27 19:00 +0200
Re: [PATCH] pwm: don't allow duty cycle higher than period Brian Norris <briannorris@chromium.org> - 2016-05-27 18:40 +0200
Re: [PATCH] pwm: don't allow duty cycle higher than period Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-05-27 18:40 +0200
Re: [PATCH] pwm: don't allow duty cycle higher than period Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-05-27 18:50 +0200
csiph-web