Skip to content

Commit 40cfa41

Browse files
arndblag-linaro
authored andcommitted
leds: sun50i-a100: Avoid division-by-zero warning
When CONFIG_COMMON_CLK is disabled, e.g. on an x86 randconfig compile test, clang reports a field overflow from propagating the result of a division by zero: drivers/leds/leds-sun50i-a100.c:309:12: error: call to '__compiletime_assert_265' declared with 'error' attribute: FIELD_PREP: value too large for the field control = FIELD_PREP(LEDC_T01_TIMING_CTRL_REG_T1H, timing->t1h_ns / cycle_ns) | Avoid the problem by adding an explicit check for the zero value here. Alternatively the assertion could be avoided with a Kconfig dependency on COMMON_CLK. Fixes: 090a25a ("leds: sun50i-a100: New driver for the A100 LED controller") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Guo Ren <guoren@kernel.org> Link: https://lore.kernel.org/r/20231212214536.175327-1-arnd@kernel.org Signed-off-by: Lee Jones <lee@kernel.org>
1 parent c82a166 commit 40cfa41

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/leds/leds-sun50i-a100.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,13 @@ static void sun50i_a100_ledc_set_timing(struct sun50i_a100_ledc *priv)
303303
{
304304
const struct sun50i_a100_ledc_timing *timing = &priv->timing;
305305
unsigned long mod_freq = clk_get_rate(priv->mod_clk);
306-
u32 cycle_ns = NSEC_PER_SEC / mod_freq;
306+
u32 cycle_ns;
307307
u32 control;
308308

309+
if (!mod_freq)
310+
return;
311+
312+
cycle_ns = NSEC_PER_SEC / mod_freq;
309313
control = FIELD_PREP(LEDC_T01_TIMING_CTRL_REG_T1H, timing->t1h_ns / cycle_ns) |
310314
FIELD_PREP(LEDC_T01_TIMING_CTRL_REG_T1L, timing->t1l_ns / cycle_ns) |
311315
FIELD_PREP(LEDC_T01_TIMING_CTRL_REG_T0H, timing->t0h_ns / cycle_ns) |

0 commit comments

Comments
 (0)