ALSA: ac97: fix possible memory leak in snd_ac97_dev_register()
authorYang Yingliang <yangyingliang@huawei.com>
Wed, 19 Oct 2022 09:30:25 +0000 (17:30 +0800)
committerTakashi Iwai <tiwai@suse.de>
Thu, 20 Oct 2022 12:19:48 +0000 (14:19 +0200)
If device_register() fails in snd_ac97_dev_register(), it should
call put_device() to give up reference, or the name allocated in
dev_set_name() is leaked.

Fixes: 0ca06a00e206 ("[ALSA] AC97 bus interface for ad-hoc drivers")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221019093025.1179475-1-yangyingliang@huawei.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/ac97/ac97_codec.c

index cb60a07d39a8e4d8a3072ef07bc648a322299132..ceead55f13ab13277d34d08eeed9e406f3c24467 100644 (file)
@@ -2009,6 +2009,7 @@ static int snd_ac97_dev_register(struct snd_device *device)
        err = device_register(&ac97->dev);
        if (err < 0) {
                ac97_err(ac97, "Can't register ac97 bus\n");
+               put_device(&ac97->dev);
                ac97->dev.bus = NULL;
                return err;
        }