]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
staging: mt7621-mmc: Fix bug on dma_alloc_coherent fail
authorChristian Lütke-Stetzkamp <christian@lkamp.de>
Wed, 4 Apr 2018 20:15:36 +0000 (22:15 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 23 Apr 2018 13:34:03 +0000 (15:34 +0200)
In case of dma_alloc_coherent failing the current code just called
BUG_ON. By adding error handling for that case this can be avoided.
This also fixes a memory leek in case of a fail later on in the probe
function.

Signed-off-by: Christian Lütke-Stetzkamp <christian@lkamp.de>
Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/mt7621-mmc/sd.c

index ab5d5c864c135a5ab4a6455f502fdcb4d9839771..9e507cd2506f0f7731c12c5f43226ce6fa83b368 100644 (file)
@@ -2787,7 +2787,10 @@ static int msdc_drv_probe(struct platform_device *pdev)
        /* using dma_alloc_coherent*/  /* todo: using 1, for all 4 slots */
        host->dma.gpd = dma_alloc_coherent(NULL, MAX_GPD_NUM * sizeof(struct gpd), &host->dma.gpd_addr, GFP_KERNEL);
        host->dma.bd =  dma_alloc_coherent(NULL, MAX_BD_NUM  * sizeof(struct bd),  &host->dma.bd_addr,  GFP_KERNEL);
-       BUG_ON((!host->dma.gpd) || (!host->dma.bd));
+       if (!host->dma.gpd || !host->dma.bd) {
+               ret = -ENOMEM;
+               goto release_mem;
+       }
        msdc_init_gpd_bd(host, &host->dma);
        /*for emmc*/
        msdc_6575_host[pdev->id] = host;
@@ -2855,6 +2858,13 @@ static int msdc_drv_probe(struct platform_device *pdev)
        cancel_delayed_work_sync(&host->card_delaywork);
 #endif
 
+release_mem:
+       if (host->dma.gpd)
+               dma_free_coherent(NULL, MAX_GPD_NUM * sizeof(struct gpd),
+                                 host->dma.gpd, host->dma.gpd_addr);
+       if (host->dma.bd)
+               dma_free_coherent(NULL, MAX_BD_NUM * sizeof(struct bd),
+                                 host->dma.bd, host->dma.bd_addr);
 host_free:
        mmc_free_host(mmc);