[PATCH] ALSA: jack: Fix control leak on jack allocation failure

From: Sreeraj S Kurup

Date: Sun Nov 15 2026 - 05:20:29 EST


snd_jack_new() creates an ALSA jack control before allocating the
jack structure.

If the jack structure allocation fails, the function returns
-ENOMEM without removing the previously created control.

Remove the control using snd_ctl_remove() to release the control
and its private data before returning -ENOMEM.

Initialize the control list before removal so that the
private_free callback can safely remove the list entry.

Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@xxxxxxxxx>
---
sound/core/jack.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/sound/core/jack.c b/sound/core/jack.c
index af2dc2cfbe19..92febcb42a8d 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -555,8 +555,14 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
}

jack = kzalloc_obj(struct snd_jack);
- if (jack == NULL)
+ if (!jack) {
+ if (jack_kctl) {
+ INIT_LIST_HEAD(&jack_kctl->list);
+ snd_ctl_remove(card, jack_kctl->kctl);
+ }
+
return -ENOMEM;
+ }

jack->id = kstrdup(id, GFP_KERNEL);
if (jack->id == NULL) {
--
2.55.0