[PATCH 1/2] ASoC: codecs: ntp8918: Fix hw_params return values

From: phucduc . bui

Date: Thu Oct 22 2026 - 06:28:29 EST


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

snd_soc_component_update_bits() returns 1 when the register is
updated successfully. Treating this as an error causes
ntp8918_hw_params() to return early with a positive value, skipping
the remaining configuration.

ASoC expects .hw_params() to return 0 on success to mark the
operation as completed.

Check for negative errors and return 0 on success.

Fixes: 2bd61fff3e93 ("ASoC: codecs: Add NeoFidelity NTP8918 codec")
Signed-off-by: bui duc phuc <phucduc.bui@xxxxxxxxx>
---
sound/soc/codecs/ntp8918.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/ntp8918.c b/sound/soc/codecs/ntp8918.c
index eca34fafc4e6..e851cfcca7c0 100644
--- a/sound/soc/codecs/ntp8918.c
+++ b/sound/soc/codecs/ntp8918.c
@@ -233,7 +233,7 @@ static int ntp8918_hw_params(struct snd_pcm_substream *substream,

ret = snd_soc_component_update_bits(component, NTP8918_MCLK_FREQ_CTRL,
NTP8918_MCLK_FREQ_MCF, mcf);
- if (ret)
+ if (ret < 0)
return ret;

switch (ntp8918->format) {
@@ -253,8 +253,10 @@ static int ntp8918_hw_params(struct snd_pcm_substream *substream,
NTP8918_INPUT_FMT_GSA_MODE,
input_fmt);

- if (!(input_fmt & NTP8918_INPUT_FMT_GSA_MODE) || ret < 0)
+ if (ret < 0)
return ret;
+ if (!(input_fmt & NTP8918_INPUT_FMT_GSA_MODE))
+ return 0;

switch (params_width(params)) {
case 24:
@@ -276,8 +278,17 @@ static int ntp8918_hw_params(struct snd_pcm_substream *substream,
gsa_fmt_mask = NTP8918_GSA_BS_MASK |
NTP8918_GSA_RIGHT_J |
NTP8918_GSA_LSB;
- return snd_soc_component_update_bits(component, NTP8918_GSA_FMT,
- gsa_fmt_mask, gsa_fmt);
+ ret = snd_soc_component_update_bits(component, NTP8918_GSA_FMT,
+ gsa_fmt_mask, gsa_fmt);
+ if (ret < 0)
+ return ret;
+
+ /*
+ * ASoC only marks the DAI hw_params as done when .hw_params() returns 0.
+ * Since snd_soc_component_update_bits() may return 1, explicitly
+ * return 0 to ensure the DAI is correctly marked.
+ */
+ return 0;
}

static int ntp8918_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
--
2.43.0