[PATCH v2 09/10] ASoC: fsl_sai: Reject bclk ratio smaller than slot width
From: phucduc . bui
Date: Thu Nov 05 2026 - 05:47:15 EST
From: bui duc phuc <phucduc.bui@xxxxxxxxx>
In hw_params(), when a bclk ratio is set, the number of slots is
computed as bclk_ratio / slot_width. If the ratio is smaller than
the slot width, slots becomes zero and the following
DIV_ROUND_UP(channels, slots) divides by zero.
Return -EINVAL in this case.
Signed-off-by: bui duc phuc <phucduc.bui@xxxxxxxxx>
---
sound/soc/fsl/fsl_sai.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index 5c50ed7c2258..c61703ddb6f8 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -632,8 +632,14 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
if (sai->slots[tx])
slots = sai->slots[tx];
- else if (sai->bclk_ratio)
+ else if (sai->bclk_ratio) {
+ if (sai->bclk_ratio < slot_width) {
+ dev_err(cpu_dai->dev, "bclk ratio %u < slot width %u\n",
+ sai->bclk_ratio, slot_width);
+ return -EINVAL;
+ }
slots = sai->bclk_ratio / slot_width;
+ }
pins = DIV_ROUND_UP(channels, slots);
--
2.43.0