[PATCH] scsi: aic94xx: Add missing check for dma_map_sg()

From: Jiasheng Jiang
Date: Mon Apr 17 2023 - 02:46:44 EST


Add check for dma_map_sg() and return error if it fails.
Moreover, unmap the first buffer when the second dma_map_sg() fails.

Fixes: 2908d778ab3e ("[SCSI] aic94xx: new driver")
Signed-off-by: Jiasheng Jiang <jiasheng@xxxxxxxxxxx>
---
drivers/scsi/aic94xx/aic94xx_task.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/aic94xx/aic94xx_task.c b/drivers/scsi/aic94xx/aic94xx_task.c
index 7f0208300110..0ff7aac0bb29 100644
--- a/drivers/scsi/aic94xx/aic94xx_task.c
+++ b/drivers/scsi/aic94xx/aic94xx_task.c
@@ -419,11 +419,20 @@ static int asd_build_smp_ascb(struct asd_ascb *ascb, struct sas_task *task,
struct asd_ha_struct *asd_ha = ascb->ha;
struct domain_device *dev = task->dev;
struct scb *scb;
+ int num;

- dma_map_sg(&asd_ha->pcidev->dev, &task->smp_task.smp_req, 1,
+ num = dma_map_sg(&asd_ha->pcidev->dev, &task->smp_task.smp_req, 1,
DMA_TO_DEVICE);
- dma_map_sg(&asd_ha->pcidev->dev, &task->smp_task.smp_resp, 1,
+ if (num == 0)
+ return -ENOMEM;
+
+ num = dma_map_sg(&asd_ha->pcidev->dev, &task->smp_task.smp_resp, 1,
DMA_FROM_DEVICE);
+ if (num == 0) {
+ dma_unmap_sg(&asd_ha->pcidev->dev, &task->smp_task.smp_req, 1,
+ DMA_TO_DEVICE);
+ return -ENOMEM;
+ }

scb = ascb->scb;

--
2.25.1