Re: [PATCH] ASoC: sophgo: fix 64-bit division build failure

Alexander Sverdlin <[email protected]>
Newsgroups dev.linux.lists.sophgo,org.kernel.vger.linux-kernel,org.kernel.vger.linux-sound
Message-ID <[email protected]>
Hi Arnd!

On Mon, 2026-02-02 at 10:53 +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <[email protected]>
> 
> cv1800b_adc_setbclk_div() does four 64-bit divisions in a row, which

3 of the 4 divisors are actually a power of two, so it would be a bug
in the compiler to issue a division for them...

Regarding the 64 bits: seems that the actual issue is the tmp variable that
is of u64 type for no reason, because priv->mclk_rate is only u32.

Maybe turning tmp into a u32 would avoid unnecessary 64-bit division
altogether?

> is rather inefficient on 32-bit systems, and using the plain division
> causes a build failure as a result:
> 
> ERROR: modpost: "__aeabi_uldivmod" [sound/soc/sophgo/cv1800b-sound-adc.ko] undefined!
> 
> Consolidate those into a single division using the div_u64() macro.
> 
> Fixes: 4cf8752a03e6 ("ASoC: sophgo: add CV1800B internal ADC codec driver")
> Signed-off-by: Arnd Bergmann <[email protected]>
> ---
>  sound/soc/sophgo/cv1800b-sound-adc.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/sound/soc/sophgo/cv1800b-sound-adc.c b/sound/soc/sophgo/cv1800b-sound-adc.c
> index 794030b713e9..b66761156b99 100644
> --- a/sound/soc/sophgo/cv1800b-sound-adc.c
> +++ b/sound/soc/sophgo/cv1800b-sound-adc.c
> @@ -105,11 +105,8 @@ static int cv1800b_adc_setbclk_div(struct cv1800b_priv *priv, unsigned int rate)
>  	if (!priv->mclk_rate || !rate)
>  		return -EINVAL;
>  
> -	tmp = priv->mclk_rate;
> -	tmp /= CV1800B_RXADC_WORD_LEN;
> -	tmp /= CV1800B_RXADC_CHANNELS;
> -	tmp /= rate;
> -	tmp /= 2;
> +	tmp = div_u64(priv->mclk_rate, CV1800B_RXADC_WORD_LEN *
> +		      CV1800B_RXADC_CHANNELS * rate * 2);
>  
>  	if (!tmp) {
>  		dev_err(priv->dev, "computed BCLK divider is zero\n");

-- 
Alexander Sverdlin.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.