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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'pwm/for-6.10-rc5-fixes-take2' of git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux

Pull pwm fixes from Uwe Kleine-König:
"Three fixes for the pwm-stm32 driver.

The first patch prevents an integer wrap-around for small periods. In
the second patch the calculation of the prescaler is fixed which
resulted in values for the ARR register that don't fit into the
corresponding register bit field. The last commit improves an error
message that was wrongly copied from another error path"

* tag 'pwm/for-6.10-rc5-fixes-take2' of git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux:
pwm: stm32: Fix error message to not describe the previous error path
pwm: stm32: Fix calculation of prescaler
pwm: stm32: Refuse too small period requests

+16 -7
+16 -7
drivers/pwm/pwm-stm32.c
··· 321 321 * First we need to find the minimal value for prescaler such that 322 322 * 323 323 * period_ns * clkrate 324 - * ------------------------------ 324 + * ------------------------------ < max_arr + 1 325 325 * NSEC_PER_SEC * (prescaler + 1) 326 326 * 327 - * isn't bigger than max_arr. 327 + * This equation is equivalent to 328 + * 329 + * period_ns * clkrate 330 + * ---------------------------- < prescaler + 1 331 + * NSEC_PER_SEC * (max_arr + 1) 332 + * 333 + * Using integer division and knowing that the right hand side is 334 + * integer, this is further equivalent to 335 + * 336 + * (period_ns * clkrate) // (NSEC_PER_SEC * (max_arr + 1)) ≤ prescaler 328 337 */ 329 338 330 339 prescaler = mul_u64_u64_div_u64(period_ns, clk_get_rate(priv->clk), 331 - (u64)NSEC_PER_SEC * priv->max_arr); 332 - if (prescaler > 0) 333 - prescaler -= 1; 334 - 340 + (u64)NSEC_PER_SEC * ((u64)priv->max_arr + 1)); 335 341 if (prescaler > MAX_TIM_PSC) 336 342 return -EINVAL; 337 343 338 344 prd = mul_u64_u64_div_u64(period_ns, clk_get_rate(priv->clk), 339 345 (u64)NSEC_PER_SEC * (prescaler + 1)); 346 + if (!prd) 347 + return -EINVAL; 340 348 341 349 /* 342 350 * All channels share the same prescaler and counter so when two ··· 681 673 * .apply() won't overflow. 682 674 */ 683 675 if (clk_get_rate(priv->clk) > 1000000000) 684 - return dev_err_probe(dev, -EINVAL, "Failed to lock clock\n"); 676 + return dev_err_probe(dev, -EINVAL, "Clock freq too high (%lu)\n", 677 + clk_get_rate(priv->clk)); 685 678 686 679 chip->ops = &stm32pwm_ops; 687 680