mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: pcm: Fix potential device leak on partial registration failure
@ 2026-11-17 14:47 Guangshuo Li
  2026-11-18 12:52 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-17 14:47 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai; +Cc: linux-sound, linux-kernel

If capture registration fails after playback was registered, the PCM
remains in the BUILD state. Card teardown therefore skips its disconnect
callback, leaving the playback device registered and holding its parent
card reference.

Unregister previously registered streams and release their timers before
returning the registration error.

This issue was found by our static analysis tool under development.

Fixes: ef46c7af93f9 ("ALSA: pcm: Embed struct device")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 sound/core/pcm.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 064df4cd3b50..7343b366986c 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -1080,16 +1080,26 @@ static int snd_pcm_dev_register(struct snd_device *device)
 		err = snd_register_device(devtype, pcm->card, pcm->device,
 					  &snd_pcm_f_ops[cidx], pcm,
 					  pcm->streams[cidx].dev);
-		if (err < 0) {
-			list_del_init(&pcm->list);
-			return err;
-		}
+		if (err < 0)
+			goto error;
 
 		for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
 			snd_pcm_timer_init(substream);
 	}
 
 	pcm_call_notify(pcm, n_register);
+	return 0;
+
+error:
+	while (--cidx >= 0) {
+		if (!pcm->streams[cidx].substream)
+			continue;
+		snd_unregister_device(pcm->streams[cidx].dev);
+		for (substream = pcm->streams[cidx].substream; substream;
+		     substream = substream->next)
+			snd_pcm_timer_done(substream);
+	}
+	list_del_init(&pcm->list);
 	return err;
 }
 

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: pcm: Fix potential device leak on partial registration failure
  2026-11-17 14:47 [PATCH] ALSA: pcm: Fix potential device leak on partial registration failure Guangshuo Li
@ 2026-11-18 12:52 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-11-18 12:52 UTC (permalink / raw)
  To: Guangshuo Li; +Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel

On Tue, 17 Nov 2026 15:47:05 +0100,
Guangshuo Li wrote:
> 
> If capture registration fails after playback was registered, the PCM
> remains in the BUILD state. Card teardown therefore skips its disconnect
> callback, leaving the playback device registered and holding its parent
> card reference.
> 
> Unregister previously registered streams and release their timers before
> returning the registration error.
> 
> This issue was found by our static analysis tool under development.
> 
> Fixes: ef46c7af93f9 ("ALSA: pcm: Embed struct device")
> Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>

Applied to for-next branch.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-18 12:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 14:47 [PATCH] ALSA: pcm: Fix potential device leak on partial registration failure Guangshuo Li
2026-11-18 12:52 ` 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®