Skip to content

Commit 0eba2a7

Browse files
charleskeepaxbroonie
authored andcommitted
ASoC: ops: Consistently treat platform_max as control value
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]>
1 parent 927e6be commit 0eba2a7

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

include/sound/soc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,10 @@ void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd);
12611261

12621262
/* mixer control */
12631263
struct soc_mixer_control {
1264-
int min, max, platform_max;
1264+
/* Minimum and maximum specified as written to the hardware */
1265+
int min, max;
1266+
/* Limited maximum value specified as presented through the control */
1267+
int platform_max;
12651268
int reg, rreg;
12661269
unsigned int shift, rshift;
12671270
unsigned int sign_bit;

sound/soc/soc-ops.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
337337
if (ucontrol->value.integer.value[0] < 0)
338338
return -EINVAL;
339339
val = ucontrol->value.integer.value[0];
340-
if (mc->platform_max && ((int)val + min) > mc->platform_max)
340+
if (mc->platform_max && val > mc->platform_max)
341341
return -EINVAL;
342342
if (val > max - min)
343343
return -EINVAL;
@@ -350,7 +350,7 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
350350
if (ucontrol->value.integer.value[1] < 0)
351351
return -EINVAL;
352352
val2 = ucontrol->value.integer.value[1];
353-
if (mc->platform_max && ((int)val2 + min) > mc->platform_max)
353+
if (mc->platform_max && val2 > mc->platform_max)
354354
return -EINVAL;
355355
if (val2 > max - min)
356356
return -EINVAL;
@@ -503,17 +503,16 @@ int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
503503
{
504504
struct soc_mixer_control *mc =
505505
(struct soc_mixer_control *)kcontrol->private_value;
506-
int platform_max;
507-
int min = mc->min;
506+
int max;
508507

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

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

518517
return 0;
519518
}

0 commit comments

Comments
 (0)