* [PATCH] ALSA: jack: Fix control leak on jack allocation failure
@ 2026-11-15 10:19 Sreeraj S Kurup
2026-11-15 11:43 ` [PATCH v2] ALSA: jack: Fix jack control cleanup on error paths Sreeraj S Kurup
0 siblings, 1 reply; 3+ messages in thread
From: Sreeraj S Kurup @ 2026-11-15 10:19 UTC (permalink / raw)
To: perex, tiwai; +Cc: linux-kernel, linux-sound, Sreeraj S Kurup
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@gmail.com>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] ALSA: jack: Fix jack control cleanup on error paths
2026-11-15 10:19 [PATCH] ALSA: jack: Fix control leak on jack allocation failure Sreeraj S Kurup
@ 2026-11-15 11:43 ` Sreeraj S Kurup
2026-11-16 15:46 ` Takashi Iwai
0 siblings, 1 reply; 3+ messages in thread
From: Sreeraj S Kurup @ 2026-11-15 11:43 UTC (permalink / raw)
To: sreekuttan2156239, perex, tiwai; +Cc: linux-kernel, linux-sound
snd_jack_new() creates an ALSA jack control before allocating
the jack structure.
If a later allocation or device registration fails, the
function returns without removing the previously created
control. This leaves the control attached to the sound card
and can cause invalid list operations during card teardown.
Initialize the control list in snd_jack_kctl_new() so that
the private_free callback can safely remove the list entry.
Route all failure paths in snd_jack_new() through common
cleanup labels to remove the control and free allocated
resources.
Fixes: 4e3f0dc65883 ("ALSA: jack: extend snd_jack_new to support phantom jack")
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
v2:
- Initialize the jack control list to prevent invalid list operations during cleanup.
- Handle cleanup of the jack control on all error paths in "snd_jack_new()".
sound/core/jack.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/sound/core/jack.c b/sound/core/jack.c
index af2dc2cfbe19..c35a92390527 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -487,6 +487,7 @@ static struct snd_jack_kctl * snd_jack_kctl_new(struct snd_card *card, const cha
jack_kctl->kctl = kctl;
jack_kctl->mask_bits = mask;
+ INIT_LIST_HEAD(&jack_kctl->list);
kctl->private_data = jack_kctl;
kctl->private_free = snd_jack_kctl_private_free;
@@ -555,13 +556,15 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
}
jack = kzalloc_obj(struct snd_jack);
- if (jack == NULL)
- return -ENOMEM;
+ if (!jack) {
+ err = -ENOMEM;
+ goto fail_kctl;
+ }
jack->id = kstrdup(id, GFP_KERNEL);
if (jack->id == NULL) {
- kfree(jack);
- return -ENOMEM;
+ err = -ENOMEM;
+ goto fail_jack;
}
#ifdef CONFIG_SND_JACK_INPUT_DEV
@@ -607,8 +610,13 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
#ifdef CONFIG_SND_JACK_INPUT_DEV
input_free_device(jack->input_dev);
#endif
+fail_jack:
kfree(jack->id);
kfree(jack);
+fail_kctl:
+ if (jack_kctl)
+ snd_ctl_remove(card, jack_kctl->kctl);
+
return err;
}
EXPORT_SYMBOL(snd_jack_new);
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] ALSA: jack: Fix jack control cleanup on error paths
2026-11-15 11:43 ` [PATCH v2] ALSA: jack: Fix jack control cleanup on error paths Sreeraj S Kurup
@ 2026-11-16 15:46 ` Takashi Iwai
0 siblings, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2026-11-16 15:46 UTC (permalink / raw)
To: Sreeraj S Kurup; +Cc: perex, tiwai, linux-kernel, linux-sound
On Sun, 15 Nov 2026 12:43:15 +0100,
Sreeraj S Kurup wrote:
>
> snd_jack_new() creates an ALSA jack control before allocating
> the jack structure.
>
> If a later allocation or device registration fails, the
> function returns without removing the previously created
> control. This leaves the control attached to the sound card
> and can cause invalid list operations during card teardown.
>
> Initialize the control list in snd_jack_kctl_new() so that
> the private_free callback can safely remove the list entry.
>
> Route all failure paths in snd_jack_new() through common
> cleanup labels to remove the control and free allocated
> resources.
>
> Fixes: 4e3f0dc65883 ("ALSA: jack: extend snd_jack_new to support phantom jack")
> Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
Applied to for-next branch now, as it's no urgent fix that can trigger
a crash or such.
thanks,
Takashi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-16 15:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15 10:19 [PATCH] ALSA: jack: Fix control leak on jack allocation failure Sreeraj S Kurup
2026-11-15 11:43 ` [PATCH v2] ALSA: jack: Fix jack control cleanup on error paths Sreeraj S Kurup
2026-11-16 15:46 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®