Skip to content

Commit 3e55111

Browse files
geo-starkUwe Kleine-König
authored andcommitted
pwm: meson: Add check for error from clk_round_rate()
clk_round_rate() can return not only zero if requested frequency can not be provided but also negative error code so add check for it too. Also change type of variable holding clk_round_rate() result from unsigned long to long. It's safe due to clk_round_rate() returns long. Fixes: 329db10 ("pwm: meson: make full use of common clock framework") Signed-off-by: Dmitry Rokosov <[email protected]> Signed-off-by: George Stark <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 6b2d60a commit 3e55111

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/pwm/pwm-meson.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
148148
struct meson_pwm *meson = to_meson_pwm(chip);
149149
struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm];
150150
unsigned int cnt, duty_cnt;
151-
unsigned long fin_freq;
151+
long fin_freq;
152152
u64 duty, period, freq;
153153

154154
duty = state->duty_cycle;
@@ -168,12 +168,13 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
168168
freq = ULONG_MAX;
169169

170170
fin_freq = clk_round_rate(channel->clk, freq);
171-
if (fin_freq == 0) {
172-
dev_err(pwmchip_parent(chip), "invalid source clock frequency\n");
173-
return -EINVAL;
171+
if (fin_freq <= 0) {
172+
dev_err(pwmchip_parent(chip),
173+
"invalid source clock frequency %llu\n", freq);
174+
return fin_freq ? fin_freq : -EINVAL;
174175
}
175176

176-
dev_dbg(pwmchip_parent(chip), "fin_freq: %lu Hz\n", fin_freq);
177+
dev_dbg(pwmchip_parent(chip), "fin_freq: %ld Hz\n", fin_freq);
177178

178179
cnt = div_u64(fin_freq * period, NSEC_PER_SEC);
179180
if (cnt > 0xffff) {

0 commit comments

Comments
 (0)