public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: pcmtest: Fix resource leaks in module init error paths
@ 2026-04-21 13:03 Cássio Gabriel
  2026-04-21 16:19 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Cássio Gabriel @ 2026-04-21 13:03 UTC (permalink / raw)
  To: Ivan Orlov, Takashi Iwai, Jaroslav Kysela
  Cc: linux-sound, linux-kernel, stable, Cássio Gabriel

pcmtest allocates its pattern buffers and creates its debugfs tree
before registering the platform device and driver, but mod_init()
does not release those resources when a later init step fails.

As a result, a debugfs directory creation failure leaks the pattern
buffers, while platform_device_register() and
platform_driver_register() failures leave both the pattern buffers
and the debugfs tree behind. The recent fix for failed device
registration only dropped the embedded device reference.

Add the missing cleanup for the debugfs tree and pattern buffers in
the remaining module init error paths.

Fixes: 315a3d57c64c ("ALSA: Implement the new Virtual PCM Test Driver")
Cc: stable@vger.kernel.org
Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>
---
 sound/drivers/pcmtest.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/sound/drivers/pcmtest.c b/sound/drivers/pcmtest.c
index 20ceb9082fa9..fe31ff1e5b3c 100644
--- a/sound/drivers/pcmtest.c
+++ b/sound/drivers/pcmtest.c
@@ -754,15 +754,24 @@ static int __init mod_init(void)
 
 	err = init_debug_files(buf_allocated);
 	if (err)
-		return err;
+		goto err_free_patterns;
 	err = platform_device_register(&pcmtst_pdev);
 	if (err) {
 		platform_device_put(&pcmtst_pdev);
-		return err;
+		goto err_clear_debug;
 	}
 	err = platform_driver_register(&pcmtst_pdrv);
-	if (err)
+	if (err) {
 		platform_device_unregister(&pcmtst_pdev);
+		goto err_clear_debug;
+	}
+
+	return 0;
+
+err_clear_debug:
+	clear_debug_files();
+err_free_patterns:
+	free_pattern_buffers();
 	return err;
 }
 

---
base-commit: 0396822571d079e2f275cca8446f653e6ac0e9f2
change-id: 20260419-alsa-pcmtest-init-unwind-7c0bd10dd23d

Best regards,
--  
Cássio Gabriel <cassiogabrielcontato@gmail.com>


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

* Re: [PATCH] ALSA: pcmtest: Fix resource leaks in module init error paths
  2026-04-21 13:03 [PATCH] ALSA: pcmtest: Fix resource leaks in module init error paths Cássio Gabriel
@ 2026-04-21 16:19 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-04-21 16:19 UTC (permalink / raw)
  To: Cássio Gabriel
  Cc: Ivan Orlov, Takashi Iwai, Jaroslav Kysela, linux-sound,
	linux-kernel, stable

On Tue, 21 Apr 2026 15:03:06 +0200,
Cássio Gabriel wrote:
> 
> pcmtest allocates its pattern buffers and creates its debugfs tree
> before registering the platform device and driver, but mod_init()
> does not release those resources when a later init step fails.
> 
> As a result, a debugfs directory creation failure leaks the pattern
> buffers, while platform_device_register() and
> platform_driver_register() failures leave both the pattern buffers
> and the debugfs tree behind. The recent fix for failed device
> registration only dropped the embedded device reference.
> 
> Add the missing cleanup for the debugfs tree and pattern buffers in
> the remaining module init error paths.
> 
> Fixes: 315a3d57c64c ("ALSA: Implement the new Virtual PCM Test Driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>

Thanks, applied now.


Takashi

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

end of thread, other threads:[~2026-04-21 16:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-21 13:03 [PATCH] ALSA: pcmtest: Fix resource leaks in module init error paths Cássio Gabriel
2026-04-21 16:19 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox