Skip to content

Commit b006631

Browse files
khoroshilovstorulf
authored andcommitted
mmc: mmc_spi: add checks for dma mapping error
There is no checks for dma mapping errors in mmc_spi. Tha patch fixes that and by the way it adds dma_unmap_single(ones_dma) that was left on a failure path mmc_spi_probe(). Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 2df9d58 commit b006631

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

drivers/mmc/host/mmc_spi.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,10 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
925925

926926
dma_addr = dma_map_page(dma_dev, sg_page(sg), 0,
927927
PAGE_SIZE, dir);
928+
if (dma_mapping_error(dma_dev, dma_addr)) {
929+
data->error = -EFAULT;
930+
break;
931+
}
928932
if (direction == DMA_TO_DEVICE)
929933
t->tx_dma = dma_addr + sg->offset;
930934
else
@@ -1393,10 +1397,12 @@ static int mmc_spi_probe(struct spi_device *spi)
13931397
host->dma_dev = dev;
13941398
host->ones_dma = dma_map_single(dev, ones,
13951399
MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
1400+
if (dma_mapping_error(dev, host->ones_dma))
1401+
goto fail_ones_dma;
13961402
host->data_dma = dma_map_single(dev, host->data,
13971403
sizeof(*host->data), DMA_BIDIRECTIONAL);
1398-
1399-
/* REVISIT in theory those map operations can fail... */
1404+
if (dma_mapping_error(dev, host->data_dma))
1405+
goto fail_data_dma;
14001406

14011407
dma_sync_single_for_cpu(host->dma_dev,
14021408
host->data_dma, sizeof(*host->data),
@@ -1462,6 +1468,11 @@ static int mmc_spi_probe(struct spi_device *spi)
14621468
if (host->dma_dev)
14631469
dma_unmap_single(host->dma_dev, host->data_dma,
14641470
sizeof(*host->data), DMA_BIDIRECTIONAL);
1471+
fail_data_dma:
1472+
if (host->dma_dev)
1473+
dma_unmap_single(host->dma_dev, host->ones_dma,
1474+
MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
1475+
fail_ones_dma:
14651476
kfree(host->data);
14661477

14671478
fail_nobuf1:

0 commit comments

Comments
 (0)