aoa: Fix codec unregister handling
Subsystems (2)
PATCH 1/1 aoa: Fix codec unregister handling
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 no module reference had been acquired by attach_codec_to_fabric(). This could cause an incorrect module reference count.
Save codec->fabric before unregistering the codec, and call exit(), remove_codec(), and module_put() only when the codec is actually attached to a fabric.
This also prevents releasing the module reference a second time when codec initialization has already failed and the attach path has cleaned up.
--- sound/aoa/core/core.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
sound/aoa/core/core.c +11 -6
@@ -71,13 +71,18 @@ EXPORT_SYMBOL_GPL(aoa_codec_register);void aoa_codec_unregister (struct aoa_codec *codec) { +struct aoa_fabric *codec_fabric = codec->fabric; +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) { +if (codec->exit) + codec->exit (codec); +if (codec_fabric->remove_codec) + codec_fabric->remove_codec (codec); + + codec->fabric =NULL ; +module_put (codec->owner); + } }EXPORT_SYMBOL_GPL (aoa_codec_unregister);
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] ALSA: aoa: aoa_codec_unregister() duplicates aoa_fabric_unlink_codec() - [Low] ALSA: aoa: missing…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Low] ALSA: aoa: aoa_codec_unregister() duplicates aoa_fabric_unlink_codec()
- [Low] ALSA: aoa: missing Fixes: trailer in commit message --
commit b926c8dbc73cbd6442745a299e6053651d3d611b
Author: Sreeraj S Kurup <[email protected]>
Quoted 17 lines
aoa: Fix codec unregister handling
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'sremove_codec()callback for a codec that was never attached to the fabric.The function also called
module_put()unconditionally, even when no module reference had been acquired byattach_codec_to_fabric(). This could cause an incorrect module reference count.Save
codec->fabricbefore unregistering the codec, and callexit(),remove_codec(), andmodule_put()only when the codec is actually attached to a fabric.
Quoted 5 lines
This also prevents releasing the module reference a second time when codec initialization has already failed and the attach path has cleaned up.
Signed-off-by Sreeraj S Kurup <[email protected]>
[Severity: Low]
Since this fixes a bug introduced when snd-aoa was added, should it include:
Quoted 18 lines
sound/aoa/core/core.c +3
-6@@ -71,13 +71,18 @@ EXPORT_SYMBOL_GPL(aoa_codec_register);void aoa_codec_unregister (struct aoa_codec *codec) { +struct aoa_fabric *codec_fabric = codec->fabric; +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) {
sound/aoa/core/core.c EXPORT_SYMBOL_GPL(aoa_codec_register); · line 87
Quoted 10 lines
sound/aoa/core/core.c +8
-0+if (codec->exit) + codec->exit (codec); +if (codec_fabric->remove_codec) + codec_fabric->remove_codec (codec); + + codec->fabric =NULL ; +module_put (codec->owner); + } }EXPORT_SYMBOL_GPL (aoa_codec_unregister);
[Severity: Low]
This isn't a bug, but could this call aoa_fabric_unlink_codec(codec) when codec->fabric is set, the same way aoa_fabric_unregister() does, instead of duplicating the detach sequence?
sound/aoa/core/core.c:aoa_fabric_unlink_codec() {
...
if (codec->exit)
codec->exit(codec);
if (codec->fabric->remove_codec)
codec->fabric->remove_codec(codec);
codec->fabric = NULL;
module_put(codec->owner);
}Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v2 1/1 ALSA: aoa: Fix codec unregister handling
In reply to Sreeraj S KurupFix 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.
---
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(-)
sound/aoa/core/core.c +3 -6
@@ -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);
Signature · 1 line
2.55.0
Takashi Iwai
AppliedRe: [PATCH v2] ALSA: aoa: Fix codec unregister handling
Quoted 17 lines · Sreeraj S Kurup
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'sremove_codec()callback for a codec that was never attached to the fabric.The function also called
module_put()unconditionally, even whenattach_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 callsexit(),remove_codec(), andmodule_put()and clearscodec->fabric. These operations are now performed only when the codec is actually attached to a fabric.
Quoted 6 lines
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]>
Applied to for-next branch. Thanks.
Takashi
Re: [PATCH v2] ALSA: aoa: Fix codec unregister handling
Hi,
Thanks for applying the patch!
Best regards,
Sreeraj