All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiasheng Jiang <jiasheng@iscas.ac.cn>
To: jejb@linux.ibm.com, martin.petersen@oracle.com, yanaijie@huawei.com
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jiasheng Jiang <jiasheng@iscas.ac.cn>
Subject: [PATCH] scsi: aic94xx: Add missing check for dma_map_sg()
Date: Mon, 17 Apr 2023 14:46:31 +0800	[thread overview]
Message-ID: <20230417064631.1939-1-jiasheng@iscas.ac.cn> (raw)

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


                 reply	other threads:[~2023-04-17  6:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230417064631.1939-1-jiasheng@iscas.ac.cn \
    --to=jiasheng@iscas.ac.cn \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=yanaijie@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.