Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH 1/2] ASoC: soc-ops: Fix clamp range for SOC_DOUBLE_SX_TLV controls
@ 2026-01-12  3:13 Cole Leavitt
  2026-01-21 10:18 ` Charles Keepax
  0 siblings, 1 reply; 2+ messages in thread
From: Cole Leavitt @ 2026-01-12  3:13 UTC (permalink / raw)
  To: linux-sound; +Cc: broonie, lgirdwood, Cole Leavitt

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


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

end of thread, other threads:[~2026-01-21 10:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-12  3:13 [PATCH 1/2] ASoC: soc-ops: Fix clamp range for SOC_DOUBLE_SX_TLV controls Cole Leavitt
2026-01-21 10:18 ` Charles Keepax

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