From: Niranjan H Y <niranjan.hy@ti.com>
To: <alsa-devel@alsa-project.org>
Cc: <linux-sound@vger.kernel.org>, <lgirdwood@gmail.com>,
<broonie@kernel.org>, <perex@perex.cz>, <tiwai@suse.com>,
<yung-chuan.liao@linux.intel.com>, <cezary.rojewski@intel.com>,
<peter.ujfalusi@linux.intel.com>,
<ranjani.sridharan@linux.intel.com>,
<kai.vehmanen@linux.intel.com>, <pierre-louis.bossart@linux.dev>,
<navada@ti.com>, <shenghao-ding@ti.com>, <v-hampiholi@ti.com>,
<baojun.xu@ti.com>, Niranjan H Y <niranjan.hy@ti.com>
Subject: [PATCH v5 1/5] ASoC: ops: improve snd_soc_get_volsw
Date: Fri, 12 Sep 2025 14:06:20 +0530 [thread overview]
Message-ID: <20250912083624.804-1-niranjan.hy@ti.com> (raw)
* 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
next reply other threads:[~2025-09-12 8:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-12 8:36 Niranjan H Y [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250912083624.804-1-niranjan.hy@ti.com \
--to=niranjan.hy@ti.com \
--cc=alsa-devel@alsa-project.org \
--cc=baojun.xu@ti.com \
--cc=broonie@kernel.org \
--cc=cezary.rojewski@intel.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=lgirdwood@gmail.com \
--cc=linux-sound@vger.kernel.org \
--cc=navada@ti.com \
--cc=perex@perex.cz \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=ranjani.sridharan@linux.intel.com \
--cc=shenghao-ding@ti.com \
--cc=tiwai@suse.com \
--cc=v-hampiholi@ti.com \
--cc=yung-chuan.liao@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox