mmc: host: omap_hsmmc: avoid possible overflow of timeout value
[pandora-kernel.git] / drivers / mmc / host / omap_hsmmc.c
index 101cd31..2b47f34 100644 (file)
@@ -1010,6 +1010,7 @@ static void omap_hsmmc_dma_cleanup(struct omap_hsmmc_host *host, int errno)
                        host->data->sg_len,
                        omap_hsmmc_get_dma_dir(host, host->data));
                omap_free_dma(dma_ch);
+               host->data->host_cookie = 0;
        }
        host->data = NULL;
 }
@@ -1498,10 +1499,11 @@ static int omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host,
 }
 
 static void set_data_timeout(struct omap_hsmmc_host *host,
-                            unsigned int timeout_ns,
+                            unsigned long long timeout_ns,
                             unsigned int timeout_clks)
 {
-       unsigned int timeout, cycle_ns;
+       unsigned long long timeout = timeout_ns;
+       unsigned int cycle_ns;
        uint32_t reg, clkd, dto = 0;
 
        reg = OMAP_HSMMC_READ(host->base, SYSCTL);
@@ -1510,7 +1512,7 @@ static void set_data_timeout(struct omap_hsmmc_host *host,
                clkd = 1;
 
        cycle_ns = 1000000000 / (clk_get_rate(host->fclk) / clkd);
-       timeout = timeout_ns / cycle_ns;
+       do_div(timeout, cycle_ns);
        timeout += timeout_clks;
        if (timeout) {
                while ((timeout & 0x80000000) == 0) {
@@ -1575,8 +1577,10 @@ static void omap_hsmmc_post_req(struct mmc_host *mmc, struct mmc_request *mrq,
        struct mmc_data *data = mrq->data;
 
        if (host->use_dma) {
-               dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
-                            omap_hsmmc_get_dma_dir(host, data));
+               if (data->host_cookie)
+                       dma_unmap_sg(mmc_dev(host->mmc), data->sg,
+                                    data->sg_len,
+                                    omap_hsmmc_get_dma_dir(host, data));
                data->host_cookie = 0;
        }
 }
@@ -2185,9 +2189,7 @@ static int omap_hsmmc_suspend(struct device *dev)
                } else {
                        host->suspended = 0;
                        if (host->pdata->resume) {
-                               ret = host->pdata->resume(&pdev->dev,
-                                                         host->slot_id);
-                               if (ret)
+                               if (host->pdata->resume(&pdev->dev, host->slot_id))
                                        dev_dbg(mmc_dev(host->mmc),
                                                "Unmask interrupt failed\n");
                        }