From: bui duc phuc <[email protected]> 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 <[email protected]> --- 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
