ASoC: Atmel: ClassD: unregister codec when error occurs
authorSongjun Wu <songjun.wu@atmel.com>
Fri, 11 Dec 2015 03:07:37 +0000 (11:07 +0800)
committerMark Brown <broonie@kernel.org>
Sat, 12 Dec 2015 22:57:00 +0000 (22:57 +0000)
Add code to unregister codec in probe function,
when the error occurs after the codec is registered.

Signed-off-by: Songjun Wu <songjun.wu@atmel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/atmel/atmel-classd.c

index 8276675730ef1252483b4a5e1d2b649bf71dfe1e..f3ffb39bfe2753b7477d75b7e63c323d30574391 100644 (file)
@@ -636,8 +636,10 @@ static int atmel_classd_probe(struct platform_device *pdev)
 
        /* register sound card */
        card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
-       if (!card)
-               return -ENOMEM;
+       if (!card) {
+               ret = -ENOMEM;
+               goto unregister_codec;
+       }
 
        snd_soc_card_set_drvdata(card, dd);
        platform_set_drvdata(pdev, card);
@@ -645,16 +647,20 @@ static int atmel_classd_probe(struct platform_device *pdev)
        ret = atmel_classd_asoc_card_init(dev, card);
        if (ret) {
                dev_err(dev, "failed to init sound card\n");
-               return ret;
+               goto unregister_codec;
        }
 
        ret = devm_snd_soc_register_card(dev, card);
        if (ret) {
                dev_err(dev, "failed to register sound card: %d\n", ret);
-               return ret;
+               goto unregister_codec;
        }
 
        return 0;
+
+unregister_codec:
+       snd_soc_unregister_codec(dev);
+       return ret;
 }
 
 static int atmel_classd_remove(struct platform_device *pdev)