From: Cole Leavitt <cole@unwrap.rs>
To: linux-sound@vger.kernel.org
Cc: broonie@kernel.org, lgirdwood@gmail.com, Cole Leavitt <cole@unwrap.rs>
Subject: [PATCH 1/2] ASoC: soc-ops: Fix clamp range for SOC_DOUBLE_SX_TLV controls
Date: Sun, 11 Jan 2026 20:13:29 -0700 [thread overview]
Message-ID: <20260112031329.17088-1-cole@unwrap.rs> (raw)
For SOC_DOUBLE_SX_TLV controls, mc->min represents the hardware register
offset (e.g., 283) and mc->max represents the number of user-visible
steps (e.g., 229). The valid hardware register range is therefore
[min, min + max], not [min, max].
When min > max (which is valid for SX controls), the clamp() call
misbehaves because it expects min <= max. This causes the control
read function to return incorrect values.
For example, with the CS42L43 headphone volume control:
- min = 0x11B (283), max = 229
- Register value 0x1FF (511) should read as user value 228
- But clamp(511, 283, 229) returns 229, then 229 - 283 = -54
- The masked result (-54 & 0x1FF) = 458, which is wrong
Fix by clamping to [min, min + max] which correctly handles both
regular controls (where min=0) and SX controls (where min is an offset).
Signed-off-by: Cole Leavitt <cole@unwrap.rs>
---
sound/soc/soc-ops.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index ce86978c1..b28fdf238 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -148,7 +148,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 = clamp(val, mc->min, mc->min + mc->max);
val -= mc->min;
if (mc->invert)
--
2.52.0
next reply other threads:[~2026-01-12 3:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-12 3:13 Cole Leavitt [this message]
2026-01-21 10:18 ` [PATCH 1/2] ASoC: soc-ops: Fix clamp range for SOC_DOUBLE_SX_TLV controls Charles Keepax
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=20260112031329.17088-1-cole@unwrap.rs \
--to=cole@unwrap.rs \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-sound@vger.kernel.org \
/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