ASoC: ops: fix snd_soc_get_volsw for sx controls
Subsystems (3)
PATCH 1/1 ASoC: ops: fix snd_soc_get_volsw for sx controls
From: Stefan Binding <[email protected]>
[ Upstream commit 095d621141826a2841dae85b52c784c147ea99d3 ]
SX controls are currently broken, since the clamp introduced in commit a0ce874cfaaa ("ASoC: ops: improve snd_soc_get_volsw") does not handle SX controls, for example where the min value in the clamp is greater than the max value in the clamp.
Add clamp parameter to prevent clamping in SX controls.
The nature of SX controls mean that it wraps around 0, with a variable number of bits, therefore clamping the value becomes complicated and prone to error.
Fixes 35 kunit tests for soc_ops_test_access.
---
This is a necessary fix to an earlier change that broke SX ALSA controls (see fixes tag), this causes volumes to get set incorrectly on several production laptops. It has already been backported to 6.18 stable, however seems to have been missed on 6.17. I suspect it was missed due to a minor conflict that I have resolved here.
Thanks,
Charles
sound/soc/soc-ops.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
sound/soc/soc-ops.c +16 -10
@@ -111,20 +111,26 @@ int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,EXPORT_SYMBOL_GPL (snd_soc_put_enum_double);static int soc_mixer_reg_to_ctl (struct soc_mixer_control *mc,unsigned int reg_val, -unsigned int mask,unsigned int shift,int max) +unsigned int mask,unsigned int shift,int max, +bool sx) {int val = (reg_val >> shift) & mask;if (mc->sign_bit) val =sign_extend32 (val, mc->sign_bit); - val =clamp (val, mc->min, mc->max); - val -= mc->min; +if (sx) { + val -= mc->min;// SX controls intentionally can overflow here + val = min_t(unsigned int, val & mask, max); + }else { + val =clamp (val, mc->min, mc->max); + val -= mc->min; + }if (mc->invert) val = max - val; -return val & mask; +return val; } static unsigned int soc_mixer_ctl_to_reg(struct soc_mixer_control *mc, int val,
@@ -246,23 +252,23 @@ static int soc_put_volsw(struct snd_kcontrol *kcontrol,static int soc_get_volsw (struct snd_kcontrol *kcontrol,struct snd_ctl_elem_value *ucontrol, -struct soc_mixer_control *mc,int mask,int max) +struct soc_mixer_control *mc,int mask,int max,bool sx) {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);unsigned int reg_val;int val; reg_val =snd_soc_component_read (component, mc->reg); - val =soc_mixer_reg_to_ctl (mc, reg_val, mask, mc->shift, max); + val =soc_mixer_reg_to_ctl (mc, reg_val, mask, mc->shift, max, sx); ucontrol->value.integer.value[0 ] = val;if (snd_soc_volsw_is_stereo (mc)) {if (mc->reg == mc->rreg) { - val =soc_mixer_reg_to_ctl (mc, reg_val, mask, mc->rshift, max); + val =soc_mixer_reg_to_ctl (mc, reg_val, mask, mc->rshift, max, sx); }else { reg_val =snd_soc_component_read (component, mc->rreg); - val =soc_mixer_reg_to_ctl (mc, reg_val, mask, mc->shift, max); + val =soc_mixer_reg_to_ctl (mc, reg_val, mask, mc->shift, max, sx); } ucontrol->value.integer.value[1 ] = val;
@@ -331,7 +337,7 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, (struct soc_mixer_control *)kcontrol->private_value;unsigned int mask =soc_mixer_mask (mc); -return soc_get_volsw (kcontrol, ucontrol, mc, mask, mc->max - mc->min); +return soc_get_volsw (kcontrol, ucontrol, mc, mask, mc->max - mc->min, false); }EXPORT_SYMBOL_GPL (snd_soc_get_volsw);
@@ -373,7 +379,7 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, (struct soc_mixer_control *)kcontrol->private_value;unsigned int mask =soc_mixer_sx_mask (mc); -return soc_get_volsw (kcontrol, ucontrol, mc, mask, mc->max); +return soc_get_volsw (kcontrol, ucontrol, mc, mask, mc->max, true); }EXPORT_SYMBOL_GPL (snd_soc_get_volsw_sx);
Signature · 1 line
2.47.3
Greg KH
maintainerQuoted 25 lines · Charles Keepax
From: Stefan Binding <[email protected]>
[ Upstream commit
095d621141826a2841dae85b52c784c147ea99d3]SX controls are currently broken, since the clamp introduced in commit
a0ce874cfaaa("ASoC: ops: improvesnd_soc_get_volsw") does not handle SX controls, for example where the min value in the clamp is greater than the max value in the clamp.Add clamp parameter to prevent clamping in SX controls.
The nature of SX controls mean that it wraps around 0, with a variable number of bits, therefore clamping the value becomes complicated and prone to error.Fixes 35 kunit tests for
soc_ops_test_access.Fixes a0ce874cfaaa ("ASoC: ops: improve snd_soc_get_volsw")CC [email protected] # 6.17Co-developed-by Charles Keepax <[email protected]>Signed-off-by Stefan Binding <[email protected]>Tested-by Peter Ujfalusi <[email protected]>Signed-off-by Mark Brown <[email protected]>Signed-off-by Charles Keepax <[email protected]>
Quoted 7 lines
---
This is a necessary fix to an earlier change that broke SX ALSA controls (see fixes tag), this causes volumes to get set incorrectly on several production laptops. It has already been backported to 6.18 stable, however seems to have been missed on 6.17. I suspect it was missed due to a minor conflict that I have resolved here.
6.17.y is long end-of-life, there is nothing we can do there anymore, please do not use that kernel tree at this time. Always look at the front page of kernel.org for the information about what branches are still under development, and what ones are not.
thanks,
greg k-h