ALSA: pcmtest: fix reference leak on failed device registration

When platform_device_register() fails in mod_init(), the embedded struct
device in pcmtst_pdev has already been initialized by
device_initialize(), but the failure path returns the error without
dropping the device reference for the current platform device:

  mod_init()
    -> platform_device_register(&pcmtst_pdev)
       -> device_initialize(&pcmtst_pdev.dev)
       -> setup_pdev_dma_masks(&pcmtst_pdev)
       -> platform_device_add(&pcmtst_pdev)

This leads to a reference leak when platform_device_register() fails.
Fix this by calling platform_device_put() before returning the error.

The issue was identified by a static analysis tool I developed and
confirmed by manual review.

Fixes: 315a3d57c6 ("ALSA: Implement the new Virtual PCM Test Driver")
Cc: [email protected]
Signed-off-by: Guangshuo Li <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Takashi Iwai <[email protected]>
This commit is contained in:
Guangshuo Li authored and Takashi Iwai committed 2026-04-17 09:54:34 +02:00
1 parent dc88eef8f5
commit 4ff036f952
1 file changed
+3 -1
+3 -1
View File
@@ -756,8 +756,10 @@ static int __init mod_init(void)
if (err)
return err;
err = platform_device_register(&pcmtst_pdev);
if (err)
if (err) {
platform_device_put(&pcmtst_pdev);
return err;
}
err = platform_driver_register(&pcmtst_pdrv);
if (err)
platform_device_unregister(&pcmtst_pdev);