Nvme: Fix dma_map_sg error check
Subsystems (3)
cover Nvme: Fix dma_map_sg error check
Hi, all,
While working on a bugfix on RTRS[1], I noticed there are quite a few other drivers have the same problem, due to the fact dma_map_sg return 0 on error, not like most of the cases, return negative value for error.
I "grep -A 5 dma_map_sg' in kernel tree, and audit/fix the one I feel is buggy, hence this patchset. As suggested by Christoph, this is for Nvme subsystem.
Thanks!
[1] https://lore.kernel.org/linux-rdma/[email protected]/T/#t
Jack Wang (2):
nvme-rdma: Fix error check for ib_dma_map_sg
nvme-fc: Fix the error check for dma_map_sg
drivers/nvme/host/fc.c | 2 +- drivers/nvme/host/rdma.c | 4 ++-- drivers/nvme/target/fc.c | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 nvme-rdma: Fix error check for ib_dma_map_sg
ib_dma_map_sg return 0 on error.
--- drivers/nvme/host/rdma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/rdma.c +2 -2
@@ -1551,7 +1551,7 @@ static int nvme_rdma_dma_map_req(struct ib_device *ibdev, struct request *rq, *count =ib_dma_map_sg (ibdev, req->data_sgl.sg_table.sgl, req->data_sgl.nents,rq_dma_dir (rq)); -if (unlikely (*count <=0 )) { +if (unlikely (!*count)) { ret = -EIO ; goto out_free_table; }
@@ -1574,7 +1574,7 @@ static int nvme_rdma_dma_map_req(struct ib_device *ibdev, struct request *rq, req->metadata_sgl->sg_table.sgl, req->metadata_sgl->nents, rq_dma_dir(rq)); -if (unlikely (*pi_count <=0 )) { +if (unlikely (!*pi_count)) { ret = -EIO ; goto out_free_pi_table; }
Signature · 1 line
2.34.1
PATCH 2/2 nvme-fc: Fix the error check for dma_map_sg
In reply to Jack Wangdma_map_sg return 0 on error, add missing check.
--- drivers/nvme/host/fc.c | 2 +- drivers/nvme/target/fc.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/nvme/host/fc.c +1 -1
@@ -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 ;
drivers/nvme/target/fc.c +5 -0
@@ -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 ;
Signature · 1 line
2.34.1