Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 22843545b200 ("dma: mv_xor: Add support for DMA_INTERRUPT")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
Link: https://lore.kernel.org/r/20250701123753.46935-2-fourier.thomas@gmail.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Thomas Fourier and committed by
Vinod Koul
60095aca b330d77c

+19 -2
+19 -2
drivers/dma/mv_xor.c
··· 1061 1061 */ 1062 1062 mv_chan->dummy_src_addr = dma_map_single(dma_dev->dev, 1063 1063 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 + 1064 1067 mv_chan->dummy_dst_addr = dma_map_single(dma_dev->dev, 1065 1068 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 + 1066 1074 1067 1075 /* allocate coherent memory for hardware descriptors 1068 1076 * note: writecombine gives slightly better performance, but ··· 1079 1071 mv_chan->dma_desc_pool_virt = 1080 1072 dma_alloc_wc(&pdev->dev, MV_XOR_POOL_SIZE, &mv_chan->dma_desc_pool, 1081 1073 GFP_KERNEL); 1082 - if (!mv_chan->dma_desc_pool_virt) 1083 - return ERR_PTR(-ENOMEM); 1074 + if (!mv_chan->dma_desc_pool_virt) { 1075 + ret = -ENOMEM; 1076 + goto err_unmap_dst; 1077 + } 1084 1078 1085 1079 /* discover transaction capabilities from the platform data */ 1086 1080 dma_dev->cap_mask = cap_mask; ··· 1165 1155 err_free_dma: 1166 1156 dma_free_coherent(&pdev->dev, MV_XOR_POOL_SIZE, 1167 1157 mv_chan->dma_desc_pool_virt, mv_chan->dma_desc_pool); 1158 + err_unmap_dst: 1159 + dma_unmap_single(dma_dev->dev, mv_chan->dummy_dst_addr, 1160 + MV_XOR_MIN_BYTE_COUNT, DMA_TO_DEVICE); 1161 + err_unmap_src: 1162 + dma_unmap_single(dma_dev->dev, mv_chan->dummy_src_addr, 1163 + MV_XOR_MIN_BYTE_COUNT, DMA_FROM_DEVICE); 1164 + 1168 1165 return ERR_PTR(ret); 1169 1166 } 1170 1167