mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-01-11 09:00:12 +00:00
ALSA: ac97: fix a double free in snd_ac97_controller_register()
If ac97_add_adapter() fails, put_device() is the correct way to drop
the device reference. kfree() is not required.
Add kfree() if idr_alloc() fails and in ac97_adapter_release() to do
the cleanup.
Found by code review.
Fixes: 74426fbff66e ("ALSA: ac97: add an ac97 bus")
Cc: stable@vger.kernel.org
Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
Link: https://patch.msgid.link/20251219162845.657525-1-lihaoxiang@isrc.iscas.ac.cn
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
17753d1755
commit
830988b6cf
@ -298,6 +298,7 @@ static void ac97_adapter_release(struct device *dev)
|
||||
idr_remove(&ac97_adapter_idr, ac97_ctrl->nr);
|
||||
dev_dbg(&ac97_ctrl->adap, "adapter unregistered by %s\n",
|
||||
dev_name(ac97_ctrl->parent));
|
||||
kfree(ac97_ctrl);
|
||||
}
|
||||
|
||||
static const struct device_type ac97_adapter_type = {
|
||||
@ -319,7 +320,9 @@ static int ac97_add_adapter(struct ac97_controller *ac97_ctrl)
|
||||
ret = device_register(&ac97_ctrl->adap);
|
||||
if (ret)
|
||||
put_device(&ac97_ctrl->adap);
|
||||
}
|
||||
} else
|
||||
kfree(ac97_ctrl);
|
||||
|
||||
if (!ret) {
|
||||
list_add(&ac97_ctrl->controllers, &ac97_controllers);
|
||||
dev_dbg(&ac97_ctrl->adap, "adapter registered by %s\n",
|
||||
@ -361,14 +364,11 @@ struct ac97_controller *snd_ac97_controller_register(
|
||||
ret = ac97_add_adapter(ac97_ctrl);
|
||||
|
||||
if (ret)
|
||||
goto err;
|
||||
return ERR_PTR(ret);
|
||||
ac97_bus_reset(ac97_ctrl);
|
||||
ac97_bus_scan(ac97_ctrl);
|
||||
|
||||
return ac97_ctrl;
|
||||
err:
|
||||
kfree(ac97_ctrl);
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(snd_ac97_controller_register);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user