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

leds: mt6323: move period calculation

clang static analysis reports this problem

leds-mt6323.c:275:12: warning: Division by zero
duty_hw = MT6323_CAL_HW_DUTY(*delay_on, period);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is because period can be 0.

period = *delay_on + *delay_off;

There is a later check that *delay_on/off are valid.

if (!*delay_on && !*delay_off) {
*delay_on = 500;
*delay_off = 500;
}

Setting the delay_on/off means period needs to be recalculated
anyway. So move the period statements after this check.

Fixes: 216ec6cc4c19 ("leds: Add LED support for MT6323 PMIC")

Signed-off-by: Tom Rix <trix@redhat.com>
Signed-off-by: Pavel Machek <pavel@ucw.cz>

authored by

Tom Rix and committed by
Pavel Machek
fa31311c 2d26684a

+9 -9
+9 -9
drivers/leds/leds-mt6323.c
··· 249 249 int ret; 250 250 251 251 /* 252 - * Units are in ms, if over the hardware able 253 - * to support, fallback into software blink 254 - */ 255 - period = *delay_on + *delay_off; 256 - 257 - if (period > MT6323_MAX_PERIOD) 258 - return -EINVAL; 259 - 260 - /* 261 252 * LED subsystem requires a default user 262 253 * friendly blink pattern for the LED so using 263 254 * 1Hz duty cycle 50% here if without specific ··· 258 267 *delay_on = 500; 259 268 *delay_off = 500; 260 269 } 270 + 271 + /* 272 + * Units are in ms, if over the hardware able 273 + * to support, fallback into software blink 274 + */ 275 + period = *delay_on + *delay_off; 276 + 277 + if (period > MT6323_MAX_PERIOD) 278 + return -EINVAL; 261 279 262 280 /* 263 281 * Calculate duty_hw based on the percentage of period during