Skip to content

Commit

Permalink
ALSA: aoa: i2sbus: fix possible memory leak in i2sbus_add_dev()
Browse files Browse the repository at this point in the history
[ Upstream commit 4a4c848 ]

dev_set_name() in soundbus_add_one() allocates memory for name, it need be
freed when of_device_register() fails, call soundbus_dev_put() to give up
the reference that hold in device_initialize(), so that it can be freed in
kobject_cleanup() when the refcount hit to 0. And other resources are also
freed in i2sbus_release_dev(), so it can return 0 directly.

Fixes: f3d9478 ("[ALSA] snd-aoa: add snd-aoa")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221027013438.991920-1-yangyingliang@huawei.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Yang Yingliang authored and gregkh committed Nov 3, 2022
1 parent 77a754f commit e81d782
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sound/aoa/soundbus/i2sbus/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ static int i2sbus_add_dev(struct macio_dev *macio,

if (soundbus_add_one(&dev->sound)) {
printk(KERN_DEBUG "i2sbus: device registration error!\n");
if (dev->sound.ofdev.dev.kobj.state_initialized) {
soundbus_dev_put(&dev->sound);
return 0;
}
goto err;
}

Expand Down

0 comments on commit e81d782

Please sign in to comment.