Skip to content

Commit b05d394

Browse files
quic-bjorandejhovold
authored andcommitted
leds: qcom-lpg: Fix PWM period limits
The introduction of high resolution PWM support changed the order of the operations in the calculation of min and max period. The result in both divisions is in most cases a truncation to 0, which limits the period to the range of [0, 0]. Both numerators (and denominators) are within 64 bits, so the whole expression can be put directly into the div64_u64, instead of doing it partially. Fixes: b00d2ed ("leds: rgb: leds-qcom-lpg: Add support for high resolution PWM") Reviewed-by: Caleb Connolly <[email protected]> Tested-by: Steev Klimaszewski <[email protected]> Signed-off-by: Bjorn Andersson <[email protected]> Acked-by: Lee Jones <[email protected]> Tested-by: Johan Hovold <[email protected]> Tested-by: Neil Armstrong <[email protected]> # on SM8550-QRD Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Johan Hovold <[email protected]>
1 parent 7877cb9 commit b05d394

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/leds/rgb/leds-qcom-lpg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,14 @@ static int lpg_calc_freq(struct lpg_channel *chan, uint64_t period)
312312
max_res = LPG_RESOLUTION_9BIT;
313313
}
314314

315-
min_period = (u64)NSEC_PER_SEC *
316-
div64_u64((1 << pwm_resolution_arr[0]), clk_rate_arr[clk_len - 1]);
315+
min_period = div64_u64((u64)NSEC_PER_SEC * (1 << pwm_resolution_arr[0]),
316+
clk_rate_arr[clk_len - 1]);
317317
if (period <= min_period)
318318
return -EINVAL;
319319

320320
/* Limit period to largest possible value, to avoid overflows */
321-
max_period = (u64)NSEC_PER_SEC * max_res * LPG_MAX_PREDIV *
322-
div64_u64((1 << LPG_MAX_M), 1024);
321+
max_period = div64_u64((u64)NSEC_PER_SEC * max_res * LPG_MAX_PREDIV * (1 << LPG_MAX_M),
322+
1024);
323323
if (period > max_period)
324324
period = max_period;
325325

0 commit comments

Comments
 (0)