diff options
author | Boris BREZILLON <boris.brezillon@free-electrons.com> | 2014-12-18 21:05:30 +0100 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2015-01-30 12:16:00 +0100 |
commit | df6922adec987b1c7f07870a00f899fbc9a7d4cc (patch) | |
tree | 75bad2f5ed22e5c7fb71fee2a8151ce00e5f2968 /drivers/pwm | |
parent | d2048c49152a414efcf8b2696896bc8803ef2f1e (diff) | |
download | op-kernel-dev-df6922adec987b1c7f07870a00f899fbc9a7d4cc.zip op-kernel-dev-df6922adec987b1c7f07870a00f899fbc9a7d4cc.tar.gz |
pwm: atmel-hlcdc: Prevent division by zero
The slow and system clock should never return a rate of zero, but this
might happen if the clocks property defined in the DT is referencing the
wrong clocks.
Prevent any division by zero from happening by testing the clk_freq
value before calling do_div().
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm')
-rw-r--r-- | drivers/pwm/pwm-atmel-hlcdc.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/pwm/pwm-atmel-hlcdc.c b/drivers/pwm/pwm-atmel-hlcdc.c index e7a785f..522f707 100644 --- a/drivers/pwm/pwm-atmel-hlcdc.c +++ b/drivers/pwm/pwm-atmel-hlcdc.c @@ -64,6 +64,9 @@ static int atmel_hlcdc_pwm_config(struct pwm_chip *c, if (!chip->errata || !chip->errata->slow_clk_erratum) { clk_freq = clk_get_rate(new_clk); + if (!clk_freq) + return -EINVAL; + clk_period_ns = (u64)NSEC_PER_SEC * 256; do_div(clk_period_ns, clk_freq); } @@ -73,6 +76,9 @@ static int atmel_hlcdc_pwm_config(struct pwm_chip *c, clk_period_ns > period_ns) { new_clk = hlcdc->sys_clk; clk_freq = clk_get_rate(new_clk); + if (!clk_freq) + return -EINVAL; + clk_period_ns = (u64)NSEC_PER_SEC * 256; do_div(clk_period_ns, clk_freq); } |