[PATCH 2/8] ASoC: ops: Fix return value in snd_soc_limit_volume()

From: Amadeusz Sławiński

Date: Wed Oct 14 2026 - 16:06:31 EST


As documented snd_soc_limit_volume() should return 0 on success, however
at some point in time this promise was broken when
snd_soc_clip_to_platform_max() was refactored, refactor it once again
using __free() to automatically free struct snd_ctl_elem_value and
return proper value.

Fixes: 7e10d7242ea8 ("ASoC: ops: dynamically allocate struct snd_ctl_elem_value")
Signed-off-by: Amadeusz Sławiński <amade@xxxxxxxxxx>
---
sound/soc/soc-ops.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index 142f407e3939..b3a719604ec7 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -406,7 +406,7 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)
{
struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value;
- struct snd_ctl_elem_value *uctl;
+ struct snd_ctl_elem_value *uctl __free(kfree) = NULL;
int ret;

if (!mc->platform_max)
@@ -418,7 +418,7 @@ static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)

ret = kctl->get(kctl, uctl);
if (ret < 0)
- goto out;
+ return ret;

if (uctl->value.integer.value[0] > mc->platform_max)
uctl->value.integer.value[0] = mc->platform_max;
@@ -428,10 +428,10 @@ static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)
uctl->value.integer.value[1] = mc->platform_max;

ret = kctl->put(kctl, uctl);
+ if (ret < 0)
+ return ret;

-out:
- kfree(uctl);
- return ret;
+ return 0;
}

/**
--
2.56.0