mmc: core: free mmc_card if cmd 3,9,7 fails in mmc_sd_init_card
authorWei WANG <wei_wang@realsil.com.cn>
Wed, 17 Jul 2013 06:21:10 +0000 (14:21 +0800)
committerlintao <lintao@rock-chips.com>
Fri, 7 Mar 2014 05:42:25 +0000 (13:42 +0800)
In function mmc_sd_init_card, if command 3/9/7 got failed, mmc_card
allocated just before won't be freed. This would cause memory leak.

Signed-off-by: Wei WANG <wei_wang@realsil.com.cn>
Signed-off-by: Chris Ball <cjb@laptop.org>
drivers/mmc/core/sd.c

index f60febaa63bfaf22e82108b4962b1d926ea66c55..752889a11491d11d5d75b8d5d2d5bc29ebd0ee36 100644 (file)
@@ -964,13 +964,13 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
        if (!mmc_host_is_spi(host)) {
                err = mmc_send_relative_addr(host, &card->rca);
                if (err)
-                       return err;
+                       goto free_card;
        }
 
        if (!oldcard) {
                err = mmc_sd_get_csd(host, card);
                if (err)
-                       return err;
+                       goto free_card;
 
                mmc_decode_cid(card);
        }
@@ -981,7 +981,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
        if (!mmc_host_is_spi(host)) {
                err = mmc_select_card(card);
                if (err)
-                       return err;
+                       goto free_card;
        }
 
        err = mmc_sd_setup_card(host, card, oldcard != NULL);