Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH v5 1/5] ASoC: ops: improve snd_soc_get_volsw
@ 2025-09-12  8:36 Niranjan H Y
  2025-09-12  8:36 ` [PATCH v5 2/5] ASoc: tas2783A: Add soundwire based codec driver Niranjan H Y
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Niranjan H Y @ 2025-09-12  8:36 UTC (permalink / raw)
  To: alsa-devel
  Cc: linux-sound, lgirdwood, broonie, perex, tiwai, yung-chuan.liao,
	cezary.rojewski, peter.ujfalusi, ranjani.sridharan, kai.vehmanen,
	pierre-louis.bossart, navada, shenghao-ding, v-hampiholi,
	baojun.xu, Niranjan H Y

* add error handling in case register read fails
* clamp the values if the register value read is
  out of range

Signed-off-by: Niranjan H Y <niranjan.hy@ti.com>
--
v5:
 - remove clamp parameter
 - move the boundary check after sign-bit extension
---
 sound/soc/soc-ops.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index a629e0eac..03f74c32d 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -118,6 +118,7 @@ static int soc_mixer_reg_to_ctl(struct soc_mixer_control *mc, unsigned int reg_v
 	if (mc->sign_bit)
 		val = sign_extend32(val, mc->sign_bit);
 
+	val = clamp(val, mc->min, mc->max);
 	val -= mc->min;
 
 	if (mc->invert)
@@ -249,9 +250,15 @@ static int soc_get_volsw(struct snd_kcontrol *kcontrol,
 {
 	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
 	unsigned int reg_val;
-	int val;
+	int val, ret = 0;
 
 	reg_val = snd_soc_component_read(component, mc->reg);
+	val = reg_val;
+	if (val < 0) {
+		ret = val;
+		goto get_volsw_done;
+	}
+
 	val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
 
 	ucontrol->value.integer.value[0] = val;
@@ -261,13 +268,19 @@ static int soc_get_volsw(struct snd_kcontrol *kcontrol,
 			val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->rshift, max);
 		} else {
 			reg_val = snd_soc_component_read(component, mc->rreg);
+			val = reg_val;
+			if (val < 0) {
+				ret = val;
+				goto get_volsw_done;
+			}
 			val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
 		}
 
 		ucontrol->value.integer.value[1] = val;
 	}
 
-	return 0;
+get_volsw_done:
+	return ret;
 }
 
 /**
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-01-01  3:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-12  8:36 [PATCH v5 1/5] ASoC: ops: improve snd_soc_get_volsw Niranjan H Y
2025-09-12  8:36 ` [PATCH v5 2/5] ASoc: tas2783A: Add soundwire based codec driver Niranjan H Y
2025-09-12  8:36 ` [PATCH v5 3/5] ASoc: tas2783A: machine driver amp utility for TI devices Niranjan H Y
2025-09-12  8:36 ` [PATCH v5 4/5] ASoc: tas2783A: add machine driver changes Niranjan H Y
2025-09-12  8:36 ` [PATCH v5 5/5] tas2783A: Add acpi match changes for Intel MTL Niranjan H Y
2025-09-22 11:58 ` [PATCH v5 1/5] ASoC: ops: improve snd_soc_get_volsw Mark Brown
2025-09-23  8:20 ` Mark Brown
2026-01-01  3:34 ` Richard Acayan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox