Fix aoa_codec_unregister() to use the codec's own fabric pointer
when removing a codec.

Previously, the function checked the global fabric pointer instead
of codec->fabric. This could call the fabric's remove_codec()
callback for a codec that was never attached to the fabric.

The function also called module_put() unconditionally, even when
attach_codec_to_fabric() had not acquired a module reference.
This could cause an incorrect module reference count.

Use aoa_fabric_unlink_codec() to detach an attached codec. This
helper calls exit(), remove_codec(), and module_put() and clears
codec->fabric. These operations are now performed only when the
codec is actually attached to a fabric.

This also prevents releasing the module reference a second time
when codec initialization fails and the attach path has already
cleaned up.

Fixes: f3d9478b2ce4 ("[ALSA] snd-aoa: add snd-aoa")
Signed-off-by: Sreeraj S Kurup <[email protected]>
---
v2:
 - Reuse aoa_fabric_unlink_codec() to detach the codec instead of
   duplicating the cleanup code.
 - Call the helper only when codec->fabric is set.
 - Add Fixes trailer.

 sound/aoa/core/core.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/sound/aoa/core/core.c b/sound/aoa/core/core.c
index 99b032a4081f..09eeadba4277 100644
--- a/sound/aoa/core/core.c
+++ b/sound/aoa/core/core.c
@@ -72,12 +72,9 @@ EXPORT_SYMBOL_GPL(aoa_codec_register);
 void aoa_codec_unregister(struct aoa_codec *codec)
 {
        list_del(&codec->list);
-       if (codec->fabric && codec->exit)
-               codec->exit(codec);
-       if (fabric && fabric->remove_codec)
-               fabric->remove_codec(codec);
-       codec->fabric = NULL;
-       module_put(codec->owner);
+
+       if (codec->fabric)
+               aoa_fabric_unlink_codec(codec);
 }
 EXPORT_SYMBOL_GPL(aoa_codec_unregister);
 
-- 
2.55.0


Reply via email to