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

pwm: img: Test clock rate to avoid division by 0

The clk API may return 0 on clk_get_rate(), so we should check the
result before using it as a divisor.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Wolfram Sang and committed by
Thierry Reding
bea307c1 92e963f5

+5
+5
drivers/pwm/pwm-img.c
··· 237 237 } 238 238 239 239 clk_rate = clk_get_rate(pwm->pwm_clk); 240 + if (!clk_rate) { 241 + dev_err(&pdev->dev, "pwm clock has no frequency\n"); 242 + ret = -EINVAL; 243 + goto disable_pwmclk; 244 + } 240 245 241 246 /* The maximum input clock divider is 512 */ 242 247 val = (u64)NSEC_PER_SEC * 512 * pwm->data->max_timebase;