All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: aic94xx: Add missing check for dma_map_sg()
@ 2023-04-17  6:46 Jiasheng Jiang
  0 siblings, 0 replies; only message in thread
From: Jiasheng Jiang @ 2023-04-17  6:46 UTC (permalink / raw)
  To: jejb, martin.petersen, yanaijie; +Cc: linux-scsi, linux-kernel, Jiasheng Jiang

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@iscas.ac.cn>
---
 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-17  6:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-17  6:46 [PATCH] scsi: aic94xx: Add missing check for dma_map_sg() Jiasheng Jiang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.