ASoC: Fix use-after-free at card unregistration
[pandora-kernel.git] / sound / soc / soc-core.c
index a5d3685..ff8dd8b 100644 (file)
@@ -709,6 +709,12 @@ int snd_soc_resume(struct device *dev)
        struct snd_soc_card *card = dev_get_drvdata(dev);
        int i, ac97_control = 0;
 
+       /* If the initialization of this soc device failed, there is no codec
+        * associated with it. Just bail out in this case.
+        */
+       if (list_empty(&card->codec_dev_list))
+               return 0;
+
        /* AC97 devices might have other drivers hanging off them so
         * need to resume immediately.  Other drivers don't have that
         * problem and may take a substantial amount of time to resume
@@ -1568,6 +1574,9 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card)
                flush_delayed_work_sync(&rtd->delayed_work);
        }
 
+       /* free the ALSA card at first; this syncs with pending operations */
+       snd_card_free(card->snd_card);
+
        /* remove auxiliary devices */
        for (i = 0; i < card->num_aux_devs; i++)
                soc_remove_aux_dev(card, i);
@@ -1584,9 +1593,7 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card)
        snd_soc_dapm_free(&card->dapm);
 
        kfree(card->rtd);
-       snd_card_free(card->snd_card);
        return 0;
-
 }
 
 /* removes a socdev */