pwm: meson: Add check for error from clk_round_rate()
[linux-block.git] / drivers / pwm / pwm-meson.c
index f4d70da621ec40e2abd705081665c183f4d34626..4a652d500dfc847b5c9d5b264f4682c471959c3e 100644 (file)
@@ -148,7 +148,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
        struct meson_pwm *meson = to_meson_pwm(chip);
        struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm];
        unsigned int cnt, duty_cnt;
-       unsigned long fin_freq;
+       long fin_freq;
        u64 duty, period, freq;
 
        duty = state->duty_cycle;
@@ -168,12 +168,13 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
                freq = ULONG_MAX;
 
        fin_freq = clk_round_rate(channel->clk, freq);
-       if (fin_freq == 0) {
-               dev_err(pwmchip_parent(chip), "invalid source clock frequency\n");
-               return -EINVAL;
+       if (fin_freq <= 0) {
+               dev_err(pwmchip_parent(chip),
+                       "invalid source clock frequency %llu\n", freq);
+               return fin_freq ? fin_freq : -EINVAL;
        }
 
-       dev_dbg(pwmchip_parent(chip), "fin_freq: %lu Hz\n", fin_freq);
+       dev_dbg(pwmchip_parent(chip), "fin_freq: %ld Hz\n", fin_freq);
 
        cnt = div_u64(fin_freq * period, NSEC_PER_SEC);
        if (cnt > 0xffff) {