diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2019-08-24 11:37:07 -0400 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2019-09-20 21:25:10 -0400 |
commit | 71523d1812aca61e32e742e87ec064e3d8c615e1 (patch) | |
tree | 20491f0323c9b71d0628741824c4dcf992e22363 /drivers/pwm/pwm-meson.c | |
parent | c9675829ba4b0e95c613f6d6d83d2b5cb9c5371c (diff) |
pwm: Ensure pwm_apply_state() doesn't modify the state argument
It is surprising for a PWM consumer when the variable holding the
requested state is modified by pwm_apply_state(). Consider for example a
driver doing:
#define PERIOD 5000000
#define DUTY_LITTLE 10
...
struct pwm_state state = {
.period = PERIOD,
.duty_cycle = DUTY_LITTLE,
.polarity = PWM_POLARITY_NORMAL,
.enabled = true,
};
pwm_apply_state(mypwm, &state);
...
state.duty_cycle = PERIOD / 2;
pwm_apply_state(mypwm, &state);
For sure the second call to pwm_apply_state() should still have
state.period = PERIOD and not something the hardware driver chose for a
reason that doesn't necessarily apply to the second call.
So declare the state argument as a pointer to a const type and adapt all
drivers' .apply callbacks.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm/pwm-meson.c')
-rw-r--r-- | drivers/pwm/pwm-meson.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 3cbff5cbb789..6245bbdb6e6c 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c | |||
@@ -159,7 +159,7 @@ static void meson_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) | |||
159 | } | 159 | } |
160 | 160 | ||
161 | static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, | 161 | static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, |
162 | struct pwm_state *state) | 162 | const struct pwm_state *state) |
163 | { | 163 | { |
164 | struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); | 164 | struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); |
165 | unsigned int duty, period, pre_div, cnt, duty_cnt; | 165 | unsigned int duty, period, pre_div, cnt, duty_cnt; |
@@ -265,7 +265,7 @@ static void meson_pwm_disable(struct meson_pwm *meson, struct pwm_device *pwm) | |||
265 | } | 265 | } |
266 | 266 | ||
267 | static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, | 267 | static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, |
268 | struct pwm_state *state) | 268 | const struct pwm_state *state) |
269 | { | 269 | { |
270 | struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); | 270 | struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); |
271 | struct meson_pwm *meson = to_meson_pwm(chip); | 271 | struct meson_pwm *meson = to_meson_pwm(chip); |