* [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á
2026-12-04 10:48 ` Alvin Šipraga
0 siblings, 2 replies; 4+ 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] 4+ 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á
2026-12-04 10:48 ` Alvin Šipraga
1 sibling, 0 replies; 4+ 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] 4+ 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á
@ 2026-12-04 10:48 ` Alvin Šipraga
2026-12-04 12:58 ` lijun
1 sibling, 1 reply; 4+ messages in thread
From: Alvin Šipraga @ 2026-12-04 10:48 UTC (permalink / raw)
To: Li Jun; +Cc: lars, nuno.sa, 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;
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
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ASoC: adau-utils: Fix divide-by-zero when freq_in is zero
2026-12-04 10:48 ` Alvin Šipraga
@ 2026-12-04 12:58 ` lijun
0 siblings, 0 replies; 4+ messages in thread
From: lijun @ 2026-12-04 12:58 UTC (permalink / raw)
To: Alvin Šipraga
Cc: lars, nuno.sa, lgirdwood, broonie, perex, tiwai, linux-sound
I am patching a theoretical bug.
2026/12/4 18:48, Alvin Šipraga :
> 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
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-04 12:58 UTC | newest]
Thread overview: 4+ 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á
2026-12-04 10:48 ` Alvin Šipraga
2026-12-04 12:58 ` lijun
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.