ASoC: meson: aiu: Fix resource leak
PATCH 1/1 ASoC: meson: aiu: Fix resource leak
In snd_soc_register_component() error path, the aiu-formatter is not being freed. Instead of returning now goto the err tag so the aiu-formatter can properly be freed.
--- sound/soc/meson/aiu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/meson/aiu.c +1 -1
@@ -310,7 +310,7 @@ static int aiu_probe(struct platform_device *pdev) ARRAY_SIZE(aiu_cpu_dai_drv));if (ret) {dev_err (dev,"Failed to register cpu component\n" ); -return ret; + goto err; }/* Register the hdmi codec control component */
Signature · 3 lines
Thanks, ET https://github.com/sponsors/ethantidmore
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch modifies the error path to purportedly free the `aiu-formatter` resource by jumping to…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch modifies the error path to purportedly free the aiu-formatter resource by jumping to the err label, referencing commit 83b83024cdbfd. However, the aiu-formatter allocation and cleanup code (specifically gx_formatter_create and gx_formatter_free) does not exist in the codebase at this revision. The patch is a "ghost fix" attempting to resolve a resource leak for a feature that is missing in this tree. --
--- Patch [1]: [PATCH] ASoC: meson: aiu: Fix resource leak --- commit e1f43f4a59c62657488472af87aa2e5d80576b03
Author: Ethan Tidmore <[email protected]>
ASoC: meson: aiu: Fix resource leak
This commit changes an error path in aiu_probe() to use a goto label instead of returning directly. The commit message indicates this is to ensure the aiu-formatter is properly freed when component registration fails.
Quoted 4 lines
sound/soc/meson/aiu.c +0
-0
[ ... ]
sound/soc/meson/aiu.c static int aiu_probe(struct platform_device *pdev) · line 291
Quoted 6 lines
sound/soc/meson/aiu.c +1
-1@@ -288,7 +288,7 @@ static int aiu_probe(struct platform_device *pdev) ARRAY_SIZE(aiu_cpu_dai_drv));if (ret) {dev_err (dev,"Failed to register cpu component\n" ); -return ret; + goto err;
[Severity: Medium]
Is there a missing dependency for this patch, or is it an incomplete backport?
The commit message mentions that the aiu-formatter is not being freed. However, looking at aiu_probe() in this tree, there is no aiu-formatter allocation or cleanup code present anywhere in the function.
Quoted 3 lines
sound/soc/meson/aiu.c +0
-0}/* Register the hdmi codec control component */
[ ... ]
sound/soc/meson/aiu.c
Quoted 4 lines
err:
sound/soc/meson/aiu.c +0
-0snd_soc_unregister_component (dev);return ret; }
[Severity: Medium]
At this error label, only snd_soc_unregister_component() is called, and no formatter cleanup logic exists. Does this fix apply to a different tree where the formatter feature is actually present?
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1 _______________________________________________ linux-amlogic mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-amlogic
Quoted 3 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch modifies the error path to purportedly free theaiu-formatterresource by jumping to theerrlabel, referencing commit83b83024cdbfd. However, theaiu-formatterallocation and cleanup code (specificallygx_formatter_createandgx_formatter_free) does not exist in the codebase at this revision. The patch is a "ghost fix" attempting to resolve a resource leak for a feature that is missing in this tree. --
This bug exists in linux-next. The AI is using the mainline.
--
Thanks,
ET
https://github.com/sponsors/ethantidmore
Quoted 15 lines · Ethan Tidmore
In
snd_soc_register_component()error path, the aiu-formatter is not being freed. Instead of returning now goto the err tag so the aiu-formatter can properly be freed.Fixes 83b83024cdbfd ("ASoC: meson: aiu: use aiu-formatter-i2s to format I2S output data")Signed-off-by Ethan Tidmore <[email protected]>--- sound/soc/meson/aiu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)sound/soc/meson/aiu.c +0
-0
sound/soc/meson/aiu.c static int aiu_probe(struct platform_device *pdev) · line 316
Quoted 8 lines
sound/soc/meson/aiu.c +1
-1@@ -310,7 +310,7 @@ static int aiu_probe(struct platform_device *pdev) ARRAY_SIZE(aiu_cpu_dai_drv));if (ret) {dev_err (dev,"Failed to register cpu component\n" ); -return ret; + goto err; }/* Register the hdmi codec control component */
Technically the fix is OK, but I don't think the commit title and message are correct. aiu-formatter data is allocated in 'gx_formatter_create' using 'devm_kzalloc' so, unless I'm missing something, the data should be automatically freed when the device is removed in case of error. What 'gx_formatter_free' does is simply clearing widget's private pointer (i.e. 'w->priv'). I think that not clearing it should not have any bad consequence since the pointer would be overwritten on the next probe. However I agree that for consistency reasons it's a good thing to clear to do when 'aiu_probe' fails.
So perhaps the title should be rewritten to something like "ASoC: meson: aiu: reset widget private data on probe error path"?
Signature · 1 line
Valerio
…
Quoted 9 lines
Quoted 9 lines
+++
b/sound/soc/meson/aiu.csound/soc/meson/aiu.c +1
-1@@ -310,7 +310,7 @@ static int aiu_probe(struct platform_device *pdev) ARRAY_SIZE(aiu_cpu_dai_drv));if (ret) {dev_err (dev,"Failed to register cpu component\n" ); -return ret; + goto err; }
Quoted 3 lines
sound/soc/meson/aiu.c static int aiu_probe(struct platform_device *pdev) · line 316
Quoted 1 line
sound/soc/meson/aiu.c +0
-0/* Register the hdmi codec control component */ Technically the fix is OK, …
I doubt it.
How can a snd_soc_unregister_component(dev) call ever fit to a failed snd_soc_register_component() call (according to the presented suggestion)?
https://elixir.bootlin.com/linux/v7.2-rc1/source/sound/soc/meson/aiu.c#L240-L315
Regards,
Markus
Quoted 14 lines · Markus Elfring
…
Quoted 9 lines
Quoted 9 lines
+++
b/sound/soc/meson/aiu.csound/soc/meson/aiu.c +1
-1@@ -310,7 +310,7 @@ static int aiu_probe(struct platform_device *pdev) ARRAY_SIZE(aiu_cpu_dai_drv));if (ret) {dev_err (dev,"Failed to register cpu component\n" ); -return ret; + goto err; }Quoted 3 lines
sound/soc/meson/aiu.c static int aiu_probe(struct platform_device *pdev) · line 316
Quoted 1 line
sound/soc/meson/aiu.c +0
-0/* Register the hdmi codec control component */ Technically the fix is OK, …
Quoted 5 lines
I doubt it.
How can a
snd_soc_unregister_component(dev)call ever fit to a failedsnd_soc_register_component()call (according to the presented suggestion)?
https://elixir.bootlin.com/linux/v7.2-rc1/source/sound/soc/meson/aiu.c#L240-L315
The reply was based on the fact that looking at 'snd_soc_unregister_component' that's a macro for 'snd_soc_unregister_component_by_driver'. The latter cycles through all registered components and if nothing is found related to the given dev, then it results in a no-op. So calling 'snd_soc_unregister_component' on a failed 'snd_soc_register_component' looked harmless to me.
What did I miss?
Signature · 1 line
Valerio