Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 329db102a26d ("pwm: meson: make full use of common clock framework")
Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com>
Signed-off-by: George Stark <gnstark@salutedevices.com>
Link: https://lore.kernel.org/r/20240425171253.2752877-3-gnstark@salutedevices.com
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

authored by

George Stark and committed by
Uwe Kleine-König
3e551115 6b2d60a5

+6 -5
+6 -5
drivers/pwm/pwm-meson.c
··· 148 148 struct meson_pwm *meson = to_meson_pwm(chip); 149 149 struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; 150 150 unsigned int cnt, duty_cnt; 151 - unsigned long fin_freq; 151 + long fin_freq; 152 152 u64 duty, period, freq; 153 153 154 154 duty = state->duty_cycle; ··· 168 168 freq = ULONG_MAX; 169 169 170 170 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; 174 175 } 175 176 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); 177 178 178 179 cnt = div_u64(fin_freq * period, NSEC_PER_SEC); 179 180 if (cnt > 0xffff) {