Skip to content

Commit 60095ac

Browse files
Thomas-fouriervinodkoul
authored andcommitted
dmaengine: mv_xor: Fix missing check after DMA map and missing unmap
The DMA map functions can fail and should be tested for errors. In case of error, unmap the already mapped regions. Fixes: 2284354 ("dma: mv_xor: Add support for DMA_INTERRUPT") Signed-off-by: Thomas Fourier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent b330d77 commit 60095ac

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

drivers/dma/mv_xor.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,16 @@ mv_xor_channel_add(struct mv_xor_device *xordev,
10611061
*/
10621062
mv_chan->dummy_src_addr = dma_map_single(dma_dev->dev,
10631063
mv_chan->dummy_src, MV_XOR_MIN_BYTE_COUNT, DMA_FROM_DEVICE);
1064+
if (dma_mapping_error(dma_dev->dev, mv_chan->dummy_src_addr))
1065+
return ERR_PTR(-ENOMEM);
1066+
10641067
mv_chan->dummy_dst_addr = dma_map_single(dma_dev->dev,
10651068
mv_chan->dummy_dst, MV_XOR_MIN_BYTE_COUNT, DMA_TO_DEVICE);
1069+
if (dma_mapping_error(dma_dev->dev, mv_chan->dummy_dst_addr)) {
1070+
ret = -ENOMEM;
1071+
goto err_unmap_src;
1072+
}
1073+
10661074

10671075
/* allocate coherent memory for hardware descriptors
10681076
* note: writecombine gives slightly better performance, but
@@ -1071,8 +1079,10 @@ mv_xor_channel_add(struct mv_xor_device *xordev,
10711079
mv_chan->dma_desc_pool_virt =
10721080
dma_alloc_wc(&pdev->dev, MV_XOR_POOL_SIZE, &mv_chan->dma_desc_pool,
10731081
GFP_KERNEL);
1074-
if (!mv_chan->dma_desc_pool_virt)
1075-
return ERR_PTR(-ENOMEM);
1082+
if (!mv_chan->dma_desc_pool_virt) {
1083+
ret = -ENOMEM;
1084+
goto err_unmap_dst;
1085+
}
10761086

10771087
/* discover transaction capabilities from the platform data */
10781088
dma_dev->cap_mask = cap_mask;
@@ -1155,6 +1165,13 @@ mv_xor_channel_add(struct mv_xor_device *xordev,
11551165
err_free_dma:
11561166
dma_free_coherent(&pdev->dev, MV_XOR_POOL_SIZE,
11571167
mv_chan->dma_desc_pool_virt, mv_chan->dma_desc_pool);
1168+
err_unmap_dst:
1169+
dma_unmap_single(dma_dev->dev, mv_chan->dummy_dst_addr,
1170+
MV_XOR_MIN_BYTE_COUNT, DMA_TO_DEVICE);
1171+
err_unmap_src:
1172+
dma_unmap_single(dma_dev->dev, mv_chan->dummy_src_addr,
1173+
MV_XOR_MIN_BYTE_COUNT, DMA_FROM_DEVICE);
1174+
11581175
return ERR_PTR(ret);
11591176
}
11601177

0 commit comments

Comments
 (0)