[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220819060801.10443-16-jinpu.wang@ionos.com>
Date: Fri, 19 Aug 2022 08:07:57 +0200
From: Jack Wang <jinpu.wang@...os.com>
To: linux-kernel@...r.kernel.org
Cc: James Smart <james.smart@...adcom.com>,
Keith Busch <kbusch@...nel.org>, Jens Axboe <axboe@...com>,
Christoph Hellwig <hch@....de>,
Sagi Grimberg <sagi@...mberg.me>,
linux-nvme@...ts.infradead.org
Subject: [PATCH v1 15/19] nvme-fc: Fix the error check for dma_map_sg
dma_map_sg return 0 on error, add missing check.
Cc: James Smart <james.smart@...adcom.com>
Cc: Keith Busch <kbusch@...nel.org>
Cc: Jens Axboe <axboe@...com>
Cc: Christoph Hellwig <hch@....de>
Cc: Sagi Grimberg <sagi@...mberg.me>
Cc: linux-nvme@...ts.infradead.org
Cc: linux-kernel@...r.kernel.org
Signed-off-by: Jack Wang <jinpu.wang@...os.com>
---
drivers/nvme/host/fc.c | 2 +-
drivers/nvme/target/fc.c | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index 127abaf9ba5d..95050f2e0a06 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -2616,7 +2616,7 @@ nvme_fc_map_data(struct nvme_fc_ctrl *ctrl, struct request *rq,
WARN_ON(op->nents > blk_rq_nr_phys_segments(rq));
freq->sg_cnt = fc_dma_map_sg(ctrl->lport->dev, freq->sg_table.sgl,
op->nents, rq_dma_dir(rq));
- if (unlikely(freq->sg_cnt <= 0)) {
+ if (unlikely(!freq->sg_cnt)) {
sg_free_table_chained(&freq->sg_table, NVME_INLINE_SG_CNT);
freq->sg_cnt = 0;
return -EFAULT;
diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index ab2627e17bb9..3749ca28860b 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -2089,6 +2089,11 @@ nvmet_fc_alloc_tgt_pgs(struct nvmet_fc_fcp_iod *fod)
((fod->io_dir == NVMET_FCP_WRITE) ?
DMA_FROM_DEVICE : DMA_TO_DEVICE));
/* note: write from initiator perspective */
+ if (!fod->data_sg_cnt) {
+ sgl_free(fod->data_sg);
+ fod->data_sg = NULL;
+ goto out;
+ }
fod->next_sg = fod->data_sg;
return 0;
--
2.34.1
Powered by blists - more mailing lists