Skip to content

Commit e70c64a

Browse files
povikopsiff
authored andcommitted
ASoC: ops: Enforce platform maximum on initial value
[ Upstream commit 783db68 ] Lower the volume if it is violating the platform maximum at its initial value (i.e. at the time of the 'snd_soc_limit_volume' call). Signed-off-by: Martin Povišer <povik+lin@cutebit.org> [Cherry picked from the Asahi kernel with fixups -- broonie] Signed-off-by: Mark Brown <broonie@kernel.org> Link: https://patch.msgid.link/20250208-asoc-volume-limit-v1-1-b98fcf4cdbad@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit 9dcce3f40d54d243a076e2073fbca699a2da773d)
1 parent ec81355 commit e70c64a

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

sound/soc/soc-ops.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,33 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
638638
}
639639
EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
640640

641+
static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)
642+
{
643+
struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value;
644+
struct snd_ctl_elem_value uctl;
645+
int ret;
646+
647+
if (!mc->platform_max)
648+
return 0;
649+
650+
ret = kctl->get(kctl, &uctl);
651+
if (ret < 0)
652+
return ret;
653+
654+
if (uctl.value.integer.value[0] > mc->platform_max)
655+
uctl.value.integer.value[0] = mc->platform_max;
656+
657+
if (snd_soc_volsw_is_stereo(mc) &&
658+
uctl.value.integer.value[1] > mc->platform_max)
659+
uctl.value.integer.value[1] = mc->platform_max;
660+
661+
ret = kctl->put(kctl, &uctl);
662+
if (ret < 0)
663+
return ret;
664+
665+
return 0;
666+
}
667+
641668
/**
642669
* snd_soc_limit_volume - Set new limit to an existing volume control.
643670
*
@@ -662,7 +689,7 @@ int snd_soc_limit_volume(struct snd_soc_card *card,
662689
struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value;
663690
if (max <= mc->max - mc->min) {
664691
mc->platform_max = max;
665-
ret = 0;
692+
ret = snd_soc_clip_to_platform_max(kctl);
666693
}
667694
}
668695
return ret;

0 commit comments

Comments
 (0)