linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: fsl_easrc: force cast 'val1' to u32 for do_div()
@ 2025-12-29  8:59 Shengjiu Wang
  2025-12-29 13:02 ` David Laight
  0 siblings, 1 reply; 2+ messages in thread
From: Shengjiu Wang @ 2025-12-29  8:59 UTC (permalink / raw)
  To: shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, lgirdwood,
	broonie, perex, tiwai, linux-sound, linuxppc-dev, linux-kernel

Fix below cocci warnings, the real width of val1 is 32bit, so use force
cast to avoid warning.

cocci warnings: (new ones prefixed by >>)
>> sound/soc/fsl/fsl_easrc.c:1999:2-8: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead.

Fixes: 27147695aaf7 ("ASoC: fsl_easrc: define functions for memory to memory usage")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202512281902.bPsKjjkC-lkp@intel.com/
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
---
 sound/soc/fsl/fsl_easrc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/fsl/fsl_easrc.c b/sound/soc/fsl/fsl_easrc.c
index f404a39009e1..16a45a7146e8 100644
--- a/sound/soc/fsl/fsl_easrc.c
+++ b/sound/soc/fsl/fsl_easrc.c
@@ -1996,7 +1996,7 @@ static int fsl_easrc_m2m_calc_out_len(struct fsl_asrc_pair *pair, int input_buff
 		/* right shift 12 bit to make ratio in 32bit space */
 		val2 = (u64)in_samples << (frac_bits - 12);
 		val1 = val1 >> 12;
-		do_div(val2, val1);
+		do_div(val2, (u32)val1);
 		out_samples = val2;
 
 		out_length = out_samples * out_width * channels;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ASoC: fsl_easrc: force cast 'val1' to u32 for do_div()
  2025-12-29  8:59 [PATCH] ASoC: fsl_easrc: force cast 'val1' to u32 for do_div() Shengjiu Wang
@ 2025-12-29 13:02 ` David Laight
  0 siblings, 0 replies; 2+ messages in thread
From: David Laight @ 2025-12-29 13:02 UTC (permalink / raw)
  To: Shengjiu Wang
  Cc: shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, lgirdwood,
	broonie, perex, tiwai, linux-sound, linuxppc-dev, linux-kernel

On Mon, 29 Dec 2025 16:59:19 +0800
Shengjiu Wang <shengjiu.wang@nxp.com> wrote:

> Fix below cocci warnings, the real width of val1 is 32bit, so use force
> cast to avoid warning.

I just looked at the uses of 'frac_bits' in that file.
Some of the related code looks very dubious.

The 200 has:
	val = (u64)in_rate << frac_bits;
	do_div(val, out_rate);
	r = (uint32_t *)&val;
followed by uses of r[0] and r[1] - that probably isn't going to DTRT big endian
and will generate worse code LE than using val and val >> 32.

Line 2063 has:
	val <<= (frac_bits - 31);
	regmap_write(easrc->regmap, REG_EASRC_RUC(pair->index), EASRC_RSUC_RS_RM(val));
where EASRC_RSUC_RS_RM(v) is (v) << 32
That is a lot of shift lefts on an 'int'.

The code in question can shift 'val1' right and convert to 32 bits
before ctx_priv->ratio_mod is added in.

	David

> 
> cocci warnings: (new ones prefixed by >>)
> >> sound/soc/fsl/fsl_easrc.c:1999:2-8: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead.  
> 
> Fixes: 27147695aaf7 ("ASoC: fsl_easrc: define functions for memory to memory usage")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202512281902.bPsKjjkC-lkp@intel.com/
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> ---
>  sound/soc/fsl/fsl_easrc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sound/soc/fsl/fsl_easrc.c b/sound/soc/fsl/fsl_easrc.c
> index f404a39009e1..16a45a7146e8 100644
> --- a/sound/soc/fsl/fsl_easrc.c
> +++ b/sound/soc/fsl/fsl_easrc.c
> @@ -1996,7 +1996,7 @@ static int fsl_easrc_m2m_calc_out_len(struct fsl_asrc_pair *pair, int input_buff
>  		/* right shift 12 bit to make ratio in 32bit space */
>  		val2 = (u64)in_samples << (frac_bits - 12);
>  		val1 = val1 >> 12;
> -		do_div(val2, val1);
> +		do_div(val2, (u32)val1);
>  		out_samples = val2;
>  
>  		out_length = out_samples * out_width * channels;



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-29 14:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-29  8:59 [PATCH] ASoC: fsl_easrc: force cast 'val1' to u32 for do_div() Shengjiu Wang
2025-12-29 13:02 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).