stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: ac97: fix a double free in snd_ac97_controller_register()
@ 2025-12-19 16:28 Haoxiang Li
  2025-12-23  9:44 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Haoxiang Li @ 2025-12-19 16:28 UTC (permalink / raw)
  To: perex, tiwai, robert.jarzmik, broonie
  Cc: linux-sound, linux-kernel, Haoxiang Li, stable

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>
---
 sound/ac97/bus.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sound/ac97/bus.c b/sound/ac97/bus.c
index f4254703d29f..bb9b795e0226 100644
--- a/sound/ac97/bus.c
+++ b/sound/ac97/bus.c
@@ -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);
 
-- 
2.25.1


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

* Re: [PATCH] ALSA: ac97: fix a double free in snd_ac97_controller_register()
  2025-12-19 16:28 [PATCH] ALSA: ac97: fix a double free in snd_ac97_controller_register() Haoxiang Li
@ 2025-12-23  9:44 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2025-12-23  9:44 UTC (permalink / raw)
  To: Haoxiang Li
  Cc: perex, tiwai, robert.jarzmik, broonie, linux-sound, linux-kernel,
	stable

On Fri, 19 Dec 2025 17:28:45 +0100,
Haoxiang Li wrote:
> 
> 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>

Thanks, applied now.


Takashi

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

end of thread, other threads:[~2025-12-23  9:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-19 16:28 [PATCH] ALSA: ac97: fix a double free in snd_ac97_controller_register() Haoxiang Li
2025-12-23  9:44 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).