Skip to contentSkip to conversation

ASoC: codecs: ntp8918: Fix hw_params return values

PATCH In review [email protected] 2 participants 3 messages Oct 22 – Nov 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

From: bui duc phuc <[email protected]>

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")
---
 sound/soc/codecs/ntp8918.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
sound/soc/codecs/ntp8918.c +15 -4
index eca34fafc4e6..e851cfcca7c0 100644
@@ -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)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 ASoC: codecs: ntp8835: Fix hw_params return values

From: bui duc phuc <[email protected]>

snd_soc_component_update_bits() returns 1 when the register is updated successfully. Treating this as an error causes ntp8835_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 dc9004ea273a ("ASoC: codecs: Add NeoFidelity NTP8835 codec")
---
 sound/soc/codecs/ntp8835.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
sound/soc/codecs/ntp8835.c +15 -4
index 39620b84e214..2be713e99eab 100644
@@ -321,7 +321,7 @@ static int ntp8835_hw_params(struct snd_pcm_substream *substream,
 
 	ret = snd_soc_component_update_bits(component, NTP8835_MCLK_FREQ_CTRL,
 					    NTP8835_MCLK_FREQ_MCF, mcf);
-	if (ret)
+	if (ret < 0)
 		return ret;
 
 	switch (ntp8835->format) {
@@ -341,8 +341,10 @@ static int ntp8835_hw_params(struct snd_pcm_substream *substream,
 					    NTP8835_INPUT_FMT_GSA_MODE,
 					    input_fmt);
 
-	if (!(input_fmt & NTP8835_INPUT_FMT_GSA_MODE) || ret < 0)
+	if (ret < 0)
 		return ret;
+	if (!(input_fmt & NTP8835_INPUT_FMT_GSA_MODE))
+		return 0;
 
 	switch (params_width(params)) {
 	case 24:
@@ -364,8 +366,17 @@ static int ntp8835_hw_params(struct snd_pcm_substream *substream,
 	gsa_fmt_mask = NTP8835_GSA_BS_MASK |
 		       NTP8835_GSA_RIGHT_J |
 		       NTP8835_GSA_LSB;
-	return snd_soc_component_update_bits(component, NTP8835_GSA_FMT,
-					     gsa_fmt_mask, gsa_fmt);
+	ret = snd_soc_component_update_bits(component, NTP8835_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 ntp8835_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
Signature · 1 line
2.43.0
maintainer
#2 lore raw
In reply to [email protected]
Quoted 1 line · On Thu, 22 Oct 2026 17:26:37 +0700, [email protected] wrote:

ASoC: codecs: ntp8918: Fix hw_params return values

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.5

Thanks!

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

      https://git.kernel.org/broonie/sound/c/972483b70fbe
[2/2] ASoC: codecs: ntp8835: Fix hw_params return values
      https://git.kernel.org/broonie/sound/c/dd1112e7907f

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark