Re: [PATCH] ALSA: hdsp: Fix divide-by-zero in DDS offset control

From: Takashi Iwai

Date: Wed Nov 04 2026 - 05:17:00 EST


On Wed, 04 Nov 2026 09:30:45 +0100,
songxiebing wrote:
>
> From: Bob Song <songxiebing@xxxxxxxxxx>
>
> hdsp_set_dds_offset() computes the target rate as
> system_sample_rate + offset_hz without validating the result. A user
> can set the DDS offset to -system_sample_rate through the control API,
> making rate zero and causing div_u64() in hdsp_set_dds_value() to
> divide by zero.
>
> Reject non-positive rates before programming the DDS value.
>
> Fixes: e4b6088c8cf1 ("[ALSA] hdsp - Add support for fine tuning of sample rate support to HDSP 9632")
> Cc: <stable@xxxxxxxxxxxxxxx>
> Signed-off-by: Bob Song <songxiebing@xxxxxxxxxx>
> ---
> sound/pci/rme9652/hdsp.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
> index 7dce548b9f36..694816f966d2 100644
> --- a/sound/pci/rme9652/hdsp.c
> +++ b/sound/pci/rme9652/hdsp.c
> @@ -2802,6 +2802,9 @@ static int hdsp_dds_offset(struct hdsp *hdsp)
> static int hdsp_set_dds_offset(struct hdsp *hdsp, int offset_hz)
> {
> int rate = hdsp->system_sample_rate + offset_hz;
> +
> + if (rate <= 0)
> + return -EINVAL;
> hdsp_set_dds_value(hdsp, rate);
> return 0;
> }

The caller doesn't check the error case properly.
Please fix the caller side, too.


thanks,

Takashi