Re: [PATCH] math64: Provide an uprounding variant of mul_u64_u64_div_u64()

From: Nicolas Pitre
Date: Wed Mar 19 2025 - 15:43:36 EST


On Wed, 19 Mar 2025, Uwe Kleine-König wrote:

> This is needed (at least) in the pwm-stm32 driver. Currently the
> pwm-stm32 driver implements this function itself. This private
> implementation can be dropped as a followup of this patch.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxx>
> ---
[...]
> +#ifndef mul_u64_u64_div_u64_roundup
> +u64 mul_u64_u64_div_u64_roundup(u64 a, u64 b, u64 c)
> +{
> + u64 res = mul_u64_u64_div_u64(a, b, c);
> + /* Those multiplications might overflow but it doesn't matter */
> + u64 rem = a * b - c * res;
> +
> + if (rem)
> + res += 1;
> +
> + return res;
> +}
> +EXPORT_SYMBOL(mul_u64_u64_div_u64_roundup);
> +#endif

Might there ever be a need for a _rem variant similar to
div64_u64_rem()? If so the _roundup could then be a simple wrapper.

Otherwise:

Reviewed-by: Nicolas Pitre <npitre@xxxxxxxxxxxx>