[PATCH 2/5] ASoC: dwc: Fix error handling in dw_i2s_set_fmt()

From: phucduc . bui

Date: Fri Nov 06 2026 - 06:47:38 EST


From: bui duc phuc <phucduc.bui@xxxxxxxxx>

Return early when an unsupported clock provider format is
encountered, preventing the function from updating frame_offset
before returning an error.

Fixes: 221acc16aee1 ("ASoC: dwc: Add TDM mode support")
Signed-off-by: bui duc phuc <phucduc.bui@xxxxxxxxx>
---
sound/soc/dwc/dwc-i2s.c | 24 +++++++-----------------
1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/sound/soc/dwc/dwc-i2s.c b/sound/soc/dwc/dwc-i2s.c
index 9007ba1157ac..6dc84c55db0f 100644
--- a/sound/soc/dwc/dwc-i2s.c
+++ b/sound/soc/dwc/dwc-i2s.c
@@ -390,29 +390,19 @@ static int dw_i2s_trigger(struct snd_pcm_substream *substream,
static int dw_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
{
struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(cpu_dai);
- int ret = 0;

switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
case SND_SOC_DAIFMT_BC_FC:
- if (dev->capability & DW_I2S_SLAVE)
- ret = 0;
- else
- ret = -EINVAL;
+ if (!(dev->capability & DW_I2S_SLAVE))
+ return -EINVAL;
break;
case SND_SOC_DAIFMT_BP_FP:
- if (dev->capability & DW_I2S_MASTER)
- ret = 0;
- else
- ret = -EINVAL;
- break;
- case SND_SOC_DAIFMT_BC_FP:
- case SND_SOC_DAIFMT_BP_FC:
- ret = -EINVAL;
+ if (!(dev->capability & DW_I2S_MASTER))
+ return -EINVAL;
break;
default:
dev_dbg(dev->dev, "dwc : Invalid clock provider format\n");
- ret = -EINVAL;
- break;
+ return -EINVAL;
}

switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
@@ -427,11 +417,11 @@ static int dw_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
dev->frame_offset = 0;
break;
default:
- dev_err(dev->dev, "DAI format unsupported");
+ dev_err(dev->dev, "DAI format unsupported\n");
return -EINVAL;
}

- return ret;
+ return 0;
}

static int dw_i2s_set_tdm_slot(struct snd_soc_dai *cpu_dai, unsigned int tx_mask,
--
2.43.0