]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
staging: mt7621-mmc: Check for nonzero number of scatterlist entries
authorGeorge Hilliard <thirtythreeforty@gmail.com>
Wed, 20 Mar 2019 22:42:05 +0000 (16:42 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 22 Mar 2019 14:20:27 +0000 (15:20 +0100)
The buffer descriptor setup loop is correct only if it is setting up at
least one bd struct.  Besides, there is an error if dma_map_sg() returns
0, which is possible and must be handled.

Additionally, remove the BUG_ON() checking sglen, which is unnecessary
because we configure DMA with that constraint during init.

Signed-off-by: George Hilliard <thirtythreeforty@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/mt7621-mmc/sd.c

index ff01872ab972f060db41aa324e310ebece3e219b..e346167754bd7799c5452cdf5f2110736839b9d4 100644 (file)
@@ -591,8 +591,6 @@ static void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma,
        struct bd *bd;
        u32 j;
 
-       BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
-
        gpd = dma->gpd;
        bd  = dma->bd;
 
@@ -681,6 +679,13 @@ static int msdc_do_request(struct mmc_host *mmc, struct mmc_request *mrq)
                data->sg_count = dma_map_sg(mmc_dev(mmc), data->sg,
                                            data->sg_len,
                                            mmc_get_dma_dir(data));
+
+               if (data->sg_count == 0) {
+                       dev_err(mmc_dev(host->mmc), "failed to map DMA for transfer\n");
+                       data->error = -ENOMEM;
+                       goto done;
+               }
+
                msdc_dma_setup(host, &host->dma, data->sg,
                               data->sg_count);