Skip to content

Commit 2cfe2bb

Browse files
charleskeepaxopsiff
authored andcommitted
ASoC: ops: Consistently treat platform_max as control value
[ Upstream commit 0eba2a7e858907a746ba69cd002eb9eb4dbd7bf3 ] This reverts commit 9bdd10d ("ASoC: ops: Shift tested values in snd_soc_put_volsw() by +min"), and makes some additional related updates. There are two ways the platform_max could be interpreted; the maximum register value, or the maximum value the control can be set to. The patch moved from treating the value as a control value to a register one. When the patch was applied it was technically correct as snd_soc_limit_volume() also used the register interpretation. However, even then most of the other usages treated platform_max as a control value, and snd_soc_limit_volume() has since been updated to also do so in commit fb9ad24 ("ASoC: ops: add correct range check for limiting volume"). That patch however, missed updating snd_soc_put_volsw() back to the control interpretation, and fixing snd_soc_info_volsw_range(). The control interpretation makes more sense as limiting is typically done from the machine driver, so it is appropriate to use the customer facing representation rather than the internal codec representation. Update all the code to consistently use this interpretation of platform_max. Finally, also add some comments to the soc_mixer_control struct to hopefully avoid further patches switching between the two approaches. Fixes: fb9ad24 ("ASoC: ops: add correct range check for limiting volume") Signed-off-by: Charles Keepax <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 5440553)
1 parent 33aa58c commit 2cfe2bb

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

include/sound/soc.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,10 @@ void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd);
11711171

11721172
/* mixer control */
11731173
struct soc_mixer_control {
1174-
int min, max, platform_max;
1174+
/* Minimum and maximum specified as written to the hardware */
1175+
int min, max;
1176+
/* Limited maximum value specified as presented through the control */
1177+
int platform_max;
11751178
int reg, rreg;
11761179
unsigned int shift, rshift;
11771180
unsigned int sign_bit;

sound/soc/soc-ops.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
336336
if (ucontrol->value.integer.value[0] < 0)
337337
return -EINVAL;
338338
val = ucontrol->value.integer.value[0];
339-
if (mc->platform_max && ((int)val + min) > mc->platform_max)
339+
if (mc->platform_max && val > mc->platform_max)
340340
return -EINVAL;
341341
if (val > max - min)
342342
return -EINVAL;
@@ -349,7 +349,7 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
349349
if (ucontrol->value.integer.value[1] < 0)
350350
return -EINVAL;
351351
val2 = ucontrol->value.integer.value[1];
352-
if (mc->platform_max && ((int)val2 + min) > mc->platform_max)
352+
if (mc->platform_max && val2 > mc->platform_max)
353353
return -EINVAL;
354354
if (val2 > max - min)
355355
return -EINVAL;
@@ -502,17 +502,16 @@ int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
502502
{
503503
struct soc_mixer_control *mc =
504504
(struct soc_mixer_control *)kcontrol->private_value;
505-
int platform_max;
506-
int min = mc->min;
505+
int max;
507506

508-
if (!mc->platform_max)
509-
mc->platform_max = mc->max;
510-
platform_max = mc->platform_max;
507+
max = mc->max - mc->min;
508+
if (mc->platform_max && mc->platform_max < max)
509+
max = mc->platform_max;
511510

512511
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
513512
uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
514513
uinfo->value.integer.min = 0;
515-
uinfo->value.integer.max = platform_max - min;
514+
uinfo->value.integer.max = max;
516515

517516
return 0;
518517
}

0 commit comments

Comments
 (0)