[PATCH 09/28] ASoC: ops: Move guts out of snd_soc_limit_volume
From: James Calligeros
Date: Sun Sep 20 2026 - 00:57:51 EST
From: Martin Povišer <povik+lin@xxxxxxxxxxx>
In advance of other changes, move the modification of the control itself
into function of its own.
Signed-off-by: Martin Povišer <povik+lin@xxxxxxxxxxx>
Signed-off-by: James Calligeros <jcalligeros99@xxxxxxxxx>
---
sound/soc/soc-ops.c | 28 +++++++++++++------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index 142f407e3939..e572b05840b4 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -434,6 +434,16 @@ static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)
return ret;
}
+static int soc_limit_volume(struct snd_kcontrol *kctl, int max)
+{
+ struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value;
+
+ if (max <= 0 || max > mc->max - mc->min)
+ return -EINVAL;
+ mc->platform_max = max;
+ return snd_soc_clip_to_platform_max(kctl);
+}
+
/**
* snd_soc_limit_volume - Set new limit to an existing volume control.
*
@@ -446,28 +456,20 @@ static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)
int snd_soc_limit_volume(struct snd_soc_card *card, const char *name, int max)
{
struct snd_kcontrol *kctl;
- int ret = -EINVAL;
- /* Sanity check for name and max */
- if (unlikely(!name || max <= 0))
+ /* Sanity check for name */
+ if (unlikely(!name))
return -EINVAL;
kctl = snd_soc_card_get_kcontrol(card, name);
- if (kctl) {
- struct soc_mixer_control *mc =
- (struct soc_mixer_control *)kctl->private_value;
-
- if (max <= mc->max - mc->min) {
- mc->platform_max = max;
- ret = snd_soc_clip_to_platform_max(kctl);
- }
- } else {
+ if (!kctl) {
/* Some cards blindly add limits for multiple variants. */
dev_dbg(card->dev, "Volume limit for unknown control '%s'\n",
name);
+ return -EINVAL;
}
- return ret;
+ return soc_limit_volume(kctl, max);
}
EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
--
2.55.0