All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alvin Šipraga" <alvin.sipraga@analog.com>
To: Li Jun <lijun01@kylinos.cn>
Cc: lars@metafoo.de, nuno.sa@analog.com, lgirdwood@gmail.com,
	broonie@kernel.org, perex@perex.cz, tiwai@suse.com,
	linux-sound@vger.kernel.org
Subject: Re: [PATCH] ASoC: adau-utils: Fix divide-by-zero when freq_in is zero
Date: Fri, 4 Dec 2026 11:48:48 +0100	[thread overview]
Message-ID: <axKaGpozYiJ7bOvv@analog.com> (raw)
In-Reply-To: <20261202092812.2283516-1-lijun01@kylinos.cn>

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;

I suppose it would make sense to catch this error earlier in those
drivers, but this is also valid.

Curious if you hit this issue in real life, or if you're patching a
theoretical bug?

Reviewed-by: Alvin Šipraga <alvin.sipraga@analog.com>

> 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
> 

  parent reply	other threads:[~2026-12-04 10:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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á
2026-12-04 10:48 ` Alvin Šipraga [this message]
2026-12-04 12:58   ` lijun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axKaGpozYiJ7bOvv@analog.com \
    --to=alvin.sipraga@analog.com \
    --cc=broonie@kernel.org \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=lijun01@kylinos.cn \
    --cc=linux-sound@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.