From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: Cole Leavitt <cole@unwrap.rs>
Cc: linux-sound@vger.kernel.org, broonie@kernel.org, lgirdwood@gmail.com
Subject: Re: [PATCH 1/2] ASoC: soc-ops: Fix clamp range for SOC_DOUBLE_SX_TLV controls
Date: Wed, 21 Jan 2026 10:18:42 +0000 [thread overview]
Message-ID: <aXCoAldpRqiGHpG9@opensource.cirrus.com> (raw)
In-Reply-To: <20260112031329.17088-1-cole@unwrap.rs>
On Sun, Jan 11, 2026 at 08:13:29PM -0700, Cole Leavitt wrote:
> 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);
No, this was discussed here:
https://lore.kernel.org/linux-sound/20251217120623.16620-1-peter.ujfalusi@linux.intel.com/
And the actual fix was merged here:
https://lore.kernel.org/all/20251216134938.788625-1-sbinding@opensource.cirrus.com/
Thanks,
Charles
prev parent reply other threads:[~2026-01-21 10:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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=aXCoAldpRqiGHpG9@opensource.cirrus.com \
--to=ckeepax@opensource.cirrus.com \
--cc=broonie@kernel.org \
--cc=cole@unwrap.rs \
--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