imx_audio_rpmsg_probe() registers the rpmsg platform device and the card
platform device, but when a registration fails it only records the error
code and continues to the next step. The rpmsg core does not call remove
for a probe that failed, so a card device registered after the rpmsg
device registration failed stays registered forever. The reverse case is
just as bad: if the card registration fails, the already registered
rpmsg device is never unregistered.

Return immediately when the rpmsg device cannot be registered, and
unregister that device before returning when the card device cannot be
registered.

Fixes: c73524768e9e ("ASoC: fsl: Let imx-audio-rpmsg register platform device 
for card")
Cc: [email protected]
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <[email protected]>
---
 sound/soc/fsl/imx-audio-rpmsg.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/sound/soc/fsl/imx-audio-rpmsg.c b/sound/soc/fsl/imx-audio-rpmsg.c
index b55dfbdb4502..950bf9e5b648 100644
--- a/sound/soc/fsl/imx-audio-rpmsg.c
+++ b/sound/soc/fsl/imx-audio-rpmsg.c
@@ -92,7 +92,7 @@ static int imx_audio_rpmsg_probe(struct rpmsg_device *rpdev)
                                                         NULL, 0);
        if (IS_ERR(data->rpmsg_pdev)) {
                dev_err(&rpdev->dev, "failed to register rpmsg platform.\n");
-               ret = PTR_ERR(data->rpmsg_pdev);
+               return PTR_ERR(data->rpmsg_pdev);
        }
 
        data->card_pdev = platform_device_register_data(&rpdev->dev,
@@ -103,9 +103,12 @@ static int imx_audio_rpmsg_probe(struct rpmsg_device 
*rpdev)
        if (IS_ERR(data->card_pdev)) {
                dev_err(&rpdev->dev, "failed to register rpmsg card.\n");
                ret = PTR_ERR(data->card_pdev);
+               platform_device_unregister(data->rpmsg_pdev);
+               data->rpmsg_pdev = NULL;
+               return ret;
        }
 
-       return ret;
+       return 0;
 }
 
 static void imx_audio_rpmsg_remove(struct rpmsg_device *rpdev)
-- 
2.34.1


Reply via email to