Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: adau-utils: Fix divide-by-zero when freq_in is zero
@ 2026-12-02  9:28 Li Jun
  2026-12-02 11:33 ` Nuno Sá
  0 siblings, 1 reply; 2+ messages in thread
From: Li Jun @ 2026-12-02  9:28 UTC (permalink / raw)
  To: lijun01, lars, nuno.sa, lgirdwood, broonie, perex, tiwai,
	linux-sound

adau_calc_pll_cfg() uses freq_in as a divisor without validating it.
With a non-zero freq_out and freq_in = 0, freq_out % freq_in causes a
divide-by-zero exception.
Both adau17x1 and adau1372 call the helper at probe time with the rate
returned by clk_get_rate(), in clk_get_rate():
	 if (!clk)
    		return 0;
if the rate returned by clk_get_rate() is 0, call adau_calc_pll_cfg in
adau17x1_probe and adau1372_setup_pll causes a divide-by-zero.

Fixes: 0eadaa9ce2aa ("ASoC: adau: Factor out shared PLL configuration code")
Signed-off-by: Li Jun <lijun01@kylinos.cn>
---
 sound/soc/codecs/adau-utils.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sound/soc/codecs/adau-utils.c b/sound/soc/codecs/adau-utils.c
index 836940f2ab92..875dea223ee5 100644
--- a/sound/soc/codecs/adau-utils.c
+++ b/sound/soc/codecs/adau-utils.c
@@ -24,6 +24,9 @@ int adau_calc_pll_cfg(unsigned int freq_in, unsigned int freq_out,
 		m = 0;
 		div = 0;
 	} else {
+		if (!freq_in)
+			return -EINVAL;
+
 		if (freq_out % freq_in != 0) {
 			div = DIV_ROUND_UP(freq_in, 13500000);
 			freq_in /= div;
-- 
2.25.1


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

* Re: [PATCH] ASoC: adau-utils: Fix divide-by-zero when freq_in is zero
  2026-12-02  9:28 [PATCH] ASoC: adau-utils: Fix divide-by-zero when freq_in is zero Li Jun
@ 2026-12-02 11:33 ` Nuno Sá
  0 siblings, 0 replies; 2+ messages in thread
From: Nuno Sá @ 2026-12-02 11:33 UTC (permalink / raw)
  To: Li Jun; +Cc: lars, lgirdwood, broonie, perex, tiwai, linux-sound

On Wed, Dec 02, 2026 at 05:28:12PM +0800, Li Jun wrote:
> adau_calc_pll_cfg() uses freq_in as a divisor without validating it.
> With a non-zero freq_out and freq_in = 0, freq_out % freq_in causes a
> divide-by-zero exception.
> Both adau17x1 and adau1372 call the helper at probe time with the rate
> returned by clk_get_rate(), in clk_get_rate():
> 	 if (!clk)
>     		return 0;
> if the rate returned by clk_get_rate() is 0, call adau_calc_pll_cfg in
> adau17x1_probe and adau1372_setup_pll causes a divide-by-zero.
> 
> Fixes: 0eadaa9ce2aa ("ASoC: adau: Factor out shared PLL configuration code")
> Signed-off-by: Li Jun <lijun01@kylinos.cn>
> ---

Ok, seems like a valid improvement:

Reviewed-by: Nuno Sá <nuno.sa@analog.com>

>  sound/soc/codecs/adau-utils.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/sound/soc/codecs/adau-utils.c b/sound/soc/codecs/adau-utils.c
> index 836940f2ab92..875dea223ee5 100644
> --- a/sound/soc/codecs/adau-utils.c
> +++ b/sound/soc/codecs/adau-utils.c
> @@ -24,6 +24,9 @@ int adau_calc_pll_cfg(unsigned int freq_in, unsigned int freq_out,
>  		m = 0;
>  		div = 0;
>  	} else {
> +		if (!freq_in)
> +			return -EINVAL;
> +
>  		if (freq_out % freq_in != 0) {
>  			div = DIV_ROUND_UP(freq_in, 13500000);
>  			freq_in /= div;
> -- 
> 2.25.1
> 

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

end of thread, other threads:[~2026-12-02 11:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  9:28 [PATCH] ASoC: adau-utils: Fix divide-by-zero when freq_in is zero Li Jun
2026-12-02 11:33 ` Nuno Sá

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox