Skip to contentSkip to conversation

Fix dma_map_sg error check

PATCH Applied Jack Wang 13 participants 43 messages Aug 19, 2022 – Sep 20, 2022

Subsystems (30)
Networking Network drivers SCSI USB +26 more subsystems
lore
Share & tools
lore

Jack Wang

author
#0 lore raw

cover 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 serry. All the patch are independent, so can go either through the maintainer tree once it is reviewed.

Thanks!

[1] https://lore.kernel.org/linux-rdma/[email protected]/T/#t

Jack Wang (19):
mailbox: bcm-ferxrm-mailbox: Fix error check for dma_map_sg infiniband/mthca: Fix dma_map_sg error check
HSI: omap_ssi_port: Fix dma_map_sg error check
mtd: rawnand: stm32_fmc2: Fix dma_map_sg error check
mtd: rawnand: marvell: Fix error handle regarding dma_map_sg usb/hcd: Fix dma_map_sg error check
crypto: gemin: Fix error check for dma_map_sg
crypto: sahara: Fix error check for dma_map_sg
crypto: qce: Fix dma_map_sg error check
crypto: amlogic: Fix dma_map_sg error check
crypto: allwinner: Fix dma_map_sg error check
crypto: ccree: Fix dma_map_sg error check
intel_th: Fix dma_map_sg error check
nvme-rdma: Fix error check for ib_dma_map_sg
nvme-fc: Fix the error check for dma_map_sg scsi/qlogicpti: Fix dma_map_sg check
mmc: meson-mx-sdhc: Fix error check for dma_map_sg
mmc: jz4740_mmc: Fix error check for dma_map_sg net/mlx4: Fix error check for dma_map_sg

 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 6 +++---
 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c   | 2 +-
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 4 ++--
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c   | 2 +-
 drivers/crypto/amlogic/amlogic-gxl-cipher.c         | 6 +++---
 drivers/crypto/ccree/cc_buffer_mgr.c                | 2 +-
 drivers/crypto/gemini/sl3516-ce-cipher.c            | 6 +++---
 drivers/crypto/qce/aead.c                           | 4 ++--
 drivers/crypto/qce/sha.c                            | 8 +++++---
 drivers/crypto/qce/skcipher.c                       | 8 ++++----
 drivers/crypto/sahara.c                             | 4 ++--
 drivers/hsi/controllers/omap_ssi_port.c             | 8 ++++----
 drivers/hwtracing/intel_th/msu.c                    | 2 +-
 drivers/infiniband/hw/mthca/mthca_memfree.c         | 7 ++++---
 drivers/mailbox/bcm-flexrm-mailbox.c                | 8 ++++----
 drivers/mmc/host/jz4740_mmc.c                       | 2 +-
 drivers/mmc/host/meson-mx-sdhc-mmc.c                | 2 +-
 drivers/mtd/nand/raw/marvell_nand.c                 | 8 +++++++-
 drivers/mtd/nand/raw/stm32_fmc2_nand.c              | 8 +++++---
 drivers/net/ethernet/mellanox/mlx4/icm.c            | 4 ++--
 drivers/nvme/host/fc.c                              | 2 +-
 drivers/nvme/host/rdma.c                            | 4 ++--
 drivers/nvme/target/fc.c                            | 5 +++++
 drivers/scsi/qlogicpti.c                            | 3 ++-
 drivers/usb/core/hcd.c                              | 2 +-
 25 files changed, 67 insertions(+), 50 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/19 mailbox: bcm-ferxrm-mailbox: Fix error check for dma_map_sg

dma_map_sg return 0 on error, fix the error check, and return -EIO to caller.

---
 drivers/mailbox/bcm-flexrm-mailbox.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/mailbox/bcm-flexrm-mailbox.c +4 -4
index fda16f76401e..bf6e86b0ed09 100644
@@ -622,15 +622,15 @@ static int flexrm_spu_dma_map(struct device *dev, struct brcm_message *msg)
 
 	rc = dma_map_sg(dev, msg->spu.src, sg_nents(msg->spu.src),
 			DMA_TO_DEVICE);
-	if (rc < 0)
-		return rc;
+	if (!rc)
+		return -EIO;
 
 	rc = dma_map_sg(dev, msg->spu.dst, sg_nents(msg->spu.dst),
 			DMA_FROM_DEVICE);
-	if (rc < 0) {
+	if (!rc) {
 		dma_unmap_sg(dev, msg->spu.src, sg_nents(msg->spu.src),
 			     DMA_TO_DEVICE);
-		return rc;
+		return -EIO;
 	}
 
 	return 0;
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v1 01/19] mailbox: bcm-ferxrm-mailbox: Fix error check for dma_map_sg

Quoted 6 lines · Jack Wang

dma_map_sg return 0 on error, fix the error check, and return -EIO to caller.

This needs a Fixes tag.

Fixes dbc049eee730 ("mailbox: Add driver for Broadcom FlexRM ring manager")

regards,
dan carpenter

author
#3 lore raw

Re: [PATCH v1 01/19] mailbox: bcm-ferxrm-mailbox: Fix error check for dma_map_sg

Quoted 5 lines · Dan Carpenter
Quoted 3 lines · Jack Wang

dma_map_sg return 0 on error, fix the error check, and return -EIO to caller.

Quoted 7 lines
Quoted 3 lines

This needs a Fixes tag.

Fixes dbc049eee730 ("mailbox: Add driver for Broadcom FlexRM ring manager")

Will add in the next version.
Thank you!

Quoted 4 lines

regards,
dan carpenter

author
#4 lore raw

PATCH 2/19 infiniband/mthca: Fix dma_map_sg error check

In reply to Jack Wang

dma_map_sg return 0 on error, in case of error set EIO as return code.

Cc Jason Gunthorpe <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Christophe JAILLET <[email protected]>
Cc Kees Cook <[email protected]>
Cc "Håkon Bugge" <[email protected]>
---
 drivers/infiniband/hw/mthca/mthca_memfree.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/infiniband/hw/mthca/mthca_memfree.c +4 -3
index f2734a5c5f26..44fd5fdf64d5 100644
@@ -189,7 +189,7 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages,
 						   chunk->npages,
 						   DMA_BIDIRECTIONAL);
 
-				if (chunk->nsg <= 0)
+				if (!chunk->nsg)
 					goto fail;
 			}
 
@@ -208,7 +208,7 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages,
 		chunk->nsg = dma_map_sg(&dev->pdev->dev, chunk->mem,
 					chunk->npages, DMA_BIDIRECTIONAL);
 
-		if (chunk->nsg <= 0)
+		if (!chunk->nsg)
 			goto fail;
 	}
 
@@ -482,8 +482,9 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
 
 	ret = dma_map_sg(&dev->pdev->dev, &db_tab->page[i].mem, 1,
 			 DMA_TO_DEVICE);
-	if (ret < 0) {
+	if (!ret) {
 		unpin_user_page(pages[0]);
+		ret = -EIO;
 		goto out;
 	}
 
Signature · 1 line
2.34.1
Reviewed-by on v1 2/19
#5 lore raw

Re: [PATCH v1 02/19] infiniband/mthca: Fix dma_map_sg error check

Quoted 11 lines · Jack Wang

dma_map_sg return 0 on error, in case of error set EIO as return code.

Cc Jason Gunthorpe <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Christophe JAILLET <[email protected]>
Cc Kees Cook <[email protected]>
Cc "Håkon Bugge" <[email protected]>
Signature · 1 line
Kees Cook
#6 lore raw

Re: [PATCH v1 02/19] infiniband/mthca: Fix dma_map_sg error check

In reply to Jack Wang
Quoted 38 lines · Jack Wang

dma_map_sg return 0 on error, in case of error set EIO as return code.

Cc Jason Gunthorpe <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Christophe JAILLET <[email protected]>
Cc Kees Cook <[email protected]>
Cc "Håkon Bugge" <[email protected]>
---
 drivers/infiniband/hw/mthca/mthca_memfree.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/infiniband/hw/mthca/mthca_memfree.c +2 -2
index f2734a5c5f26..44fd5fdf64d5 100644
@@ -189,7 +189,7 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages,
 						   chunk->npages,
 						   DMA_BIDIRECTIONAL);
 
-				if (chunk->nsg <= 0)
+				if (!chunk->nsg)
 					goto fail;
 			}
 
@@ -208,7 +208,7 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages,
 		chunk->nsg = dma_map_sg(&dev->pdev->dev, chunk->mem,
 					chunk->npages, DMA_BIDIRECTIONAL);
 
-		if (chunk->nsg <= 0)
+		if (!chunk->nsg)
 			goto fail;
 	}
 

drivers/infiniband/hw/mthca/mthca_memfree.c int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar, · line 485

Quoted 5 lines
drivers/infiniband/hw/mthca/mthca_memfree.c +1 -1
@@ -482,8 +482,9 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
 
 	ret = dma_map_sg(&dev->pdev->dev, &db_tab->page[i].mem, 1,
 			 DMA_TO_DEVICE);
-	if (ret < 0) {
+	if (!ret) {

This code is not equivalent to original code. mthca didn't count ret == 0 as an error. Most likely, it is a bug, but I don't want to change old and unmaintained driver without any real need.

Thanks

Quoted 8 lines
drivers/infiniband/hw/mthca/mthca_memfree.c +1 -0
 		unpin_user_page(pages[0]);
+		ret = -EIO;
 		goto out;
 	}
 
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v1 02/19] infiniband/mthca: Fix dma_map_sg error check

In reply to Jack Wang
Quoted 3 lines · Jack Wang

dma_map_sg return 0 on error, in case of error set EIO as return code.

The first two chunks are just cleanups but the third one is a bug fix so it needs a Fixes tag.

regards,
dan carpenter

author
#8 lore raw

PATCH 3/19 HSI: omap_ssi_port: Fix dma_map_sg error check

In reply to Jack Wang

dma_map_sg return 0 on error, in case of error return -EIO to caller.

Cc Sebastian Reichel <[email protected]>
Cc [email protected] (open list)
---
 drivers/hsi/controllers/omap_ssi_port.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hsi/controllers/omap_ssi_port.c +4 -4
index a0cb5be246e1..b9495b720f1b 100644
@@ -230,10 +230,10 @@ static int ssi_start_dma(struct hsi_msg *msg, int lch)
 	if (msg->ttype == HSI_MSG_READ) {
 		err = dma_map_sg(&ssi->device, msg->sgt.sgl, msg->sgt.nents,
 							DMA_FROM_DEVICE);
-		if (err < 0) {
+		if (!err) {
 			dev_dbg(&ssi->device, "DMA map SG failed !\n");
 			pm_runtime_put_autosuspend(omap_port->pdev);
-			return err;
+			return -EIO;
 		}
 		csdp = SSI_DST_BURST_4x32_BIT | SSI_DST_MEMORY_PORT |
 			SSI_SRC_SINGLE_ACCESS0 | SSI_SRC_PERIPHERAL_PORT |
@@ -247,10 +247,10 @@ static int ssi_start_dma(struct hsi_msg *msg, int lch)
 	} else {
 		err = dma_map_sg(&ssi->device, msg->sgt.sgl, msg->sgt.nents,
 							DMA_TO_DEVICE);
-		if (err < 0) {
+		if (!err) {
 			dev_dbg(&ssi->device, "DMA map SG failed !\n");
 			pm_runtime_put_autosuspend(omap_port->pdev);
-			return err;
+			return -EIO;
 		}
 		csdp = SSI_SRC_BURST_4x32_BIT | SSI_SRC_MEMORY_PORT |
 			SSI_DST_SINGLE_ACCESS0 | SSI_DST_PERIPHERAL_PORT |
Signature · 1 line
2.34.1
author
#9 lore raw

PATCH 4/19 mtd: rawnand: stm32_fmc2: Fix dma_map_sg error check

In reply to Jack Wang

dma_map_sg return 0 on error, in case of error return -EIO.

Cc Miquel Raynal <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Vignesh Raghavendra <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Alexandre Torgue <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Christophe Kerello <[email protected]>
Cc Cai Huoqing <[email protected]>
---
 drivers/mtd/nand/raw/stm32_fmc2_nand.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/stm32_fmc2_nand.c +5 -3
index 87c1c7dd97eb..a0c825af19fa 100644
@@ -862,8 +862,8 @@ static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf,
 
 	ret = dma_map_sg(nfc->dev, nfc->dma_data_sg.sgl,
 			 eccsteps, dma_data_dir);
-	if (ret < 0)
-		return ret;
+	if (!ret)
+		return -EIO;
 
 	desc_data = dmaengine_prep_slave_sg(dma_ch, nfc->dma_data_sg.sgl,
 					    eccsteps, dma_transfer_dir,
@@ -893,8 +893,10 @@ static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf,
 
 		ret = dma_map_sg(nfc->dev, nfc->dma_ecc_sg.sgl,
 				 eccsteps, dma_data_dir);
-		if (ret < 0)
+		if (!ret) {
+			ret = -EIO;
 			goto err_unmap_data;
+		}
 
 		desc_ecc = dmaengine_prep_slave_sg(nfc->dma_ecc_ch,
 						   nfc->dma_ecc_sg.sgl,
Signature · 1 line
2.34.1
Reviewed-by on v1 4/19
#10 lore raw

Re: [PATCH v1 04/19] mtd: rawnand: stm32_fmc2: Fix dma_map_sg error check

Hi Jack,

Quoted 36 lines · Jack Wang

dma_map_sg return 0 on error, in case of error return -EIO.

Cc Miquel Raynal <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Vignesh Raghavendra <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Alexandre Torgue <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Christophe Kerello <[email protected]>
Cc Cai Huoqing <[email protected]>
---
  drivers/mtd/nand/raw/stm32_fmc2_nand.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/stm32_fmc2_nand.c +2 -2
index 87c1c7dd97eb..a0c825af19fa 100644
@@ -862,8 +862,8 @@ static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf,
 
  	ret = dma_map_sg(nfc->dev, nfc->dma_data_sg.sgl,
  			 eccsteps, dma_data_dir);
-	if (ret < 0)
-		return ret;
+	if (!ret)
+		return -EIO;
 
  	desc_data = dmaengine_prep_slave_sg(dma_ch, nfc->dma_data_sg.sgl,
  					    eccsteps, dma_transfer_dir,
@@ -893,8 +893,10 @@ static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf,
 

drivers/mtd/nand/raw/stm32_fmc2_nand.c static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf, · line 902

Quoted 10 lines
drivers/mtd/nand/raw/stm32_fmc2_nand.c +3 -1
  		ret = dma_map_sg(nfc->dev, nfc->dma_ecc_sg.sgl,
  				 eccsteps, dma_data_dir);
-		if (ret < 0)
+		if (!ret) {
+			ret = -EIO;
  			goto err_unmap_data;
+		}
 
  		desc_ecc = dmaengine_prep_slave_sg(nfc->dma_ecc_ch,
  						   nfc->dma_ecc_sg.sgl,

Regards,
Christophe Kerello.

maintainer Applied
#11 lore raw

Re: [PATCH v1 04/19] mtd: rawnand: stm32_fmc2: Fix dma_map_sg error check

In reply to Jack Wang
Quoted 16 lines · Jack Wang

dma_map_sg return 0 on error, in case of error return -EIO.

Cc Miquel Raynal <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Vignesh Raghavendra <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Alexandre Torgue <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Christophe Kerello <[email protected]>
Cc Cai Huoqing <[email protected]>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

author
#12 lore raw

PATCH 5/19 mtd: rawnand: marvell: Fix error handle regarding dma_map_sg

In reply to Jack Wang

dma_map_sg return 0 on error, in case of error return -EIO, also add the dma_unmap_sg as rollback on the following error.

Cc Miquel Raynal <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Vignesh Raghavendra <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Alexandre Torgue <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Christophe Kerello <[email protected]>
Cc Cai Huoqing <[email protected]>
---
 drivers/mtd/nand/raw/marvell_nand.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/mtd/nand/raw/marvell_nand.c +7 -1
index 2455a581fd70..d9f2f1d0b5ef 100644
@@ -865,13 +865,19 @@ static int marvell_nfc_xfer_data_dma(struct marvell_nfc *nfc,
 	marvell_nfc_enable_dma(nfc);
 	/* Prepare the DMA transfer */
 	sg_init_one(&sg, nfc->dma_buf, dma_len);
-	dma_map_sg(nfc->dma_chan->device->dev, &sg, 1, direction);
+	ret = dma_map_sg(nfc->dma_chan->device->dev, &sg, 1, direction);
+	if (!ret) {
+		dev_err(nfc->dev, "Could not map DMA S/G list\n");
+		return -ENXIO;
+	}
+
 	tx = dmaengine_prep_slave_sg(nfc->dma_chan, &sg, 1,
 				     direction == DMA_FROM_DEVICE ?
 				     DMA_DEV_TO_MEM : DMA_MEM_TO_DEV,
 				     DMA_PREP_INTERRUPT);
 	if (!tx) {
 		dev_err(nfc->dev, "Could not prepare DMA S/G list\n");
+		dma_unmap_sg(nfc->dma_chan->device->dev, &sg, 1, direction);
 		return -ENXIO;
 	}
 
Signature · 1 line
2.34.1
maintainer Applied
#13 lore raw

Re: [PATCH v1 05/19] mtd: rawnand: marvell: Fix error handle regarding dma_map_sg

Quoted 16 lines · Jack Wang

dma_map_sg return 0 on error, in case of error return -EIO, also add the dma_unmap_sg as rollback on the following error.

Cc Miquel Raynal <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Vignesh Raghavendra <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Alexandre Torgue <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Christophe Kerello <[email protected]>
Cc Cai Huoqing <[email protected]>
Quoted 1 line

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

author
#14 lore raw

PATCH 6/19 usb/hcd: Fix dma_map_sg error check

In reply to Jack Wang

dma_map_sg return 0 on error.

Cc Greg Kroah-Hartman <[email protected]>
Cc Alan Stern <[email protected]>
Cc Kishon Vijay Abraham I <[email protected]>
Cc Alexey Sheplyakov <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Weitao Wang <[email protected]>
Cc Matthias Kaehlcke <[email protected]>
Cc Arnd Bergmann <[email protected]>
---
 drivers/usb/core/hcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/core/hcd.c +1 -1
index 94b305bbd621..90dd32a24e5b 100644
@@ -1474,7 +1474,7 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
 						urb->sg,
 						urb->num_sgs,
 						dir);
-				if (n <= 0)
+				if (!n)
 					ret = -EAGAIN;
 				else
 					urb->transfer_flags |= URB_DMA_MAP_SG;
Signature · 1 line
2.34.1
author
#15 lore raw

PATCH 7/19 crypto: gemin: Fix error check for dma_map_sg

In reply to Jack Wang

dma_map_sg return 0 on error.

Cc Corentin Labbe <[email protected]>
Cc Hans Ulli Kroll <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Herbert Xu <[email protected]>
Cc "David S. Miller" <[email protected]>
---
 drivers/crypto/gemini/sl3516-ce-cipher.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/gemini/sl3516-ce-cipher.c +3 -3
index 14d0d83d388d..34fea8aa91b6 100644
@@ -149,7 +149,7 @@ static int sl3516_ce_cipher(struct skcipher_request *areq)
 	if (areq->src == areq->dst) {
 		nr_sgs = dma_map_sg(ce->dev, areq->src, sg_nents(areq->src),
 				    DMA_BIDIRECTIONAL);
-		if (nr_sgs <= 0 || nr_sgs > MAXDESC / 2) {
+		if (!nr_sgs || nr_sgs > MAXDESC / 2) {
 			dev_err(ce->dev, "Invalid sg number %d\n", nr_sgs);
 			err = -EINVAL;
 			goto theend;
@@ -158,14 +158,14 @@ static int sl3516_ce_cipher(struct skcipher_request *areq)
 	} else {
 		nr_sgs = dma_map_sg(ce->dev, areq->src, sg_nents(areq->src),
 				    DMA_TO_DEVICE);
-		if (nr_sgs <= 0 || nr_sgs > MAXDESC / 2) {
+		if (!nr_sgs || nr_sgs > MAXDESC / 2) {
 			dev_err(ce->dev, "Invalid sg number %d\n", nr_sgs);
 			err = -EINVAL;
 			goto theend;
 		}
 		nr_sgd = dma_map_sg(ce->dev, areq->dst, sg_nents(areq->dst),
 				    DMA_FROM_DEVICE);
-		if (nr_sgd <= 0 || nr_sgd > MAXDESC) {
+		if (!nr_sgd || nr_sgd > MAXDESC) {
 			dev_err(ce->dev, "Invalid sg number %d\n", nr_sgd);
 			err = -EINVAL;
 			goto theend_sgs;
Signature · 1 line
2.34.1
Reviewed-by on v1 7/19
#16 lore raw

Re: [PATCH v1 07/19] crypto: gemin: Fix error check for dma_map_sg

Quoted 11 lines · Jack Wang

dma_map_sg return 0 on error.

Cc Corentin Labbe <[email protected]>
Cc Hans Ulli Kroll <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Herbert Xu <[email protected]>
Cc "David S. Miller" <[email protected]>

Good catch!

Yours,
Linus Walleij

maintainer
#17 lore raw

Re: [PATCH v1 07/19] crypto: gemin: Fix error check for dma_map_sg

In reply to Jack Wang
Quoted 11 lines · Jack Wang

dma_map_sg return 0 on error.

Cc Corentin Labbe <[email protected]>
Cc Hans Ulli Kroll <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Herbert Xu <[email protected]>
Cc "David S. Miller" <[email protected]>
Quoted 3 lines
---
 drivers/crypto/gemini/sl3516-ce-cipher.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Patches 7-12 applied. Thanks.

Signature · 8 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Acked-by Tested-by on v1 7/19
#18 lore raw

Re: [PATCH v1 07/19] crypto: gemin: Fix error check for dma_map_sg

In reply to Jack Wang
Quoted 11 lines · Jack Wang

dma_map_sg return 0 on error.

Cc Corentin Labbe <[email protected]>
Cc Hans Ulli Kroll <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Herbert Xu <[email protected]>
Cc "David S. Miller" <[email protected]>
Quoted 4 lines
---
 drivers/crypto/gemini/sl3516-ce-cipher.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Hello

There is a typo in subject gemin -> gemini.

Thanks
Regards

author
#19 lore raw

Re: [PATCH v1 07/19] crypto: gemin: Fix error check for dma_map_sg

Quoted 18 lines · LABBE Corentin
Quoted 11 lines · Jack Wang

dma_map_sg return 0 on error.

Cc Corentin Labbe <[email protected]>
Cc Hans Ulli Kroll <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Herbert Xu <[email protected]>
Cc "David S. Miller" <[email protected]>
Quoted 4 lines
---
 drivers/crypto/gemini/sl3516-ce-cipher.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 3 lines

Hello

There is a typo in subject gemin -> gemini.

indeed, maybe Herbert can fix the subject in his tree.

Quoted 6 lines

Thanks
Regards

Thx!

author
#20 lore raw

PATCH 8/19 crypto: sahara: Fix error check for dma_map_sg

In reply to Jack Wang

dma_map_sg return 0 on error, it returns the number of DMA address segments mapped (this may be shorter than <nents> passed in if some elements of the scatter/gather list are physically or virtually adjacent and an IOMMU maps them with a single entry).

---
 drivers/crypto/sahara.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/sahara.c +2 -2
index 457084b344c1..bb71aac30e2c 100644
@@ -487,13 +487,13 @@ static int sahara_hw_descriptor_create(struct sahara_dev *dev)
 
 	ret = dma_map_sg(dev->device, dev->in_sg, dev->nb_in_sg,
 			 DMA_TO_DEVICE);
-	if (ret != dev->nb_in_sg) {
+	if (!ret) {
 		dev_err(dev->device, "couldn't map in sg\n");
 		goto unmap_in;
 	}
 	ret = dma_map_sg(dev->device, dev->out_sg, dev->nb_out_sg,
 			 DMA_FROM_DEVICE);
-	if (ret != dev->nb_out_sg) {
+	if (!ret) {
 		dev_err(dev->device, "couldn't map out sg\n");
 		goto unmap_out;
 	}
Signature · 1 line
2.34.1
author
#21 lore raw

PATCH 9/19 crypto: qce: Fix dma_map_sg error check

In reply to Jack Wang

dma_map_sg return 0 on error, fix the error check and return -EIO to caller.

---
 drivers/crypto/qce/aead.c     | 4 ++--
 drivers/crypto/qce/sha.c      | 8 +++++---
 drivers/crypto/qce/skcipher.c | 8 ++++----
 3 files changed, 11 insertions(+), 9 deletions(-)
drivers/crypto/qce/aead.c +2 -2
index 97a530171f07..6eb4d2e35629 100644
@@ -450,8 +450,8 @@ qce_aead_async_req_handle(struct crypto_async_request *async_req)
 	if (ret)
 		return ret;
 	dst_nents = dma_map_sg(qce->dev, rctx->dst_sg, rctx->dst_nents, dir_dst);
-	if (dst_nents < 0) {
-		ret = dst_nents;
+	if (!dst_nents) {
+		ret = -EIO;
 		goto error_free;
 	}
 
drivers/crypto/qce/sha.c +5 -3
index 59159f5e64e5..37bafd7aeb79 100644
@@ -97,14 +97,16 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req)
 	}
 
 	ret = dma_map_sg(qce->dev, req->src, rctx->src_nents, DMA_TO_DEVICE);
-	if (ret < 0)
-		return ret;
+	if (!ret)
+		return -EIO;
 
 	sg_init_one(&rctx->result_sg, qce->dma.result_buf, QCE_RESULT_BUF_SZ);
 
 	ret = dma_map_sg(qce->dev, &rctx->result_sg, 1, DMA_FROM_DEVICE);
-	if (ret < 0)
+	if (!ret) {
+		ret = -EIO;
 		goto error_unmap_src;
+	}
 
 	ret = qce_dma_prep_sgs(&qce->dma, req->src, rctx->src_nents,
 			       &rctx->result_sg, 1, qce_ahash_done, async_req);
drivers/crypto/qce/skcipher.c +4 -4
index 3d27cd5210ef..5b493fdc1e74 100644
@@ -124,15 +124,15 @@ qce_skcipher_async_req_handle(struct crypto_async_request *async_req)
 	rctx->dst_sg = rctx->dst_tbl.sgl;
 
 	dst_nents = dma_map_sg(qce->dev, rctx->dst_sg, rctx->dst_nents, dir_dst);
-	if (dst_nents < 0) {
-		ret = dst_nents;
+	if (!dst_nents) {
+		ret = -EIO;
 		goto error_free;
 	}
 
 	if (diff_dst) {
 		src_nents = dma_map_sg(qce->dev, req->src, rctx->src_nents, dir_src);
-		if (src_nents < 0) {
-			ret = src_nents;
+		if (!src_nents) {
+			ret = -EIO;
 			goto error_unmap_dst;
 		}
 		rctx->src_sg = req->src;
Signature · 1 line
2.34.1
author
#22 lore raw

PATCH 10/19 crypto: amlogic: Fix dma_map_sg error check

In reply to Jack Wang

dma_map_sg return 0 on error.

---
 drivers/crypto/amlogic/amlogic-gxl-cipher.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/amlogic/amlogic-gxl-cipher.c +3 -3
index e79514fce731..af017a087ebf 100644
@@ -177,7 +177,7 @@ static int meson_cipher(struct skcipher_request *areq)
 	if (areq->src == areq->dst) {
 		nr_sgs = dma_map_sg(mc->dev, areq->src, sg_nents(areq->src),
 				    DMA_BIDIRECTIONAL);
-		if (nr_sgs < 0) {
+		if (!nr_sgs) {
 			dev_err(mc->dev, "Invalid SG count %d\n", nr_sgs);
 			err = -EINVAL;
 			goto theend;
@@ -186,14 +186,14 @@ static int meson_cipher(struct skcipher_request *areq)
 	} else {
 		nr_sgs = dma_map_sg(mc->dev, areq->src, sg_nents(areq->src),
 				    DMA_TO_DEVICE);
-		if (nr_sgs < 0 || nr_sgs > MAXDESC - 3) {
+		if (!nr_sgs || nr_sgs > MAXDESC - 3) {
 			dev_err(mc->dev, "Invalid SG count %d\n", nr_sgs);
 			err = -EINVAL;
 			goto theend;
 		}
 		nr_sgd = dma_map_sg(mc->dev, areq->dst, sg_nents(areq->dst),
 				    DMA_FROM_DEVICE);
-		if (nr_sgd < 0 || nr_sgd > MAXDESC - 3) {
+		if (!nr_sgd || nr_sgd > MAXDESC - 3) {
 			dev_err(mc->dev, "Invalid SG count %d\n", nr_sgd);
 			err = -EINVAL;
 			goto theend;
Signature · 1 line
2.34.1
maintainer Tested-by Acked-by on v1 10/19
#23 lore raw

Re: [PATCH v1 10/19] crypto: amlogic: Fix dma_map_sg error check

Quoted 9 lines · Jack Wang

dma_map_sg return 0 on error.

Quoted 5 lines
---
 drivers/crypto/amlogic/amlogic-gxl-cipher.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Hello

Thanks
Regards

author
#24 lore raw

PATCH 11/19 crypto: allwinner: Fix dma_map_sg error check

In reply to Jack Wang

dma_map_sg return 0 on error.

Cc Corentin Labbe <[email protected]>
Cc Herbert Xu <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Chen-Yu Tsai <[email protected]>
Cc Jernej Skrabec <[email protected]>
Cc Samuel Holland <[email protected]>
Cc Dan Carpenter <[email protected]>
Cc Minghao Chi <[email protected]>
Cc Peng Wu <[email protected]>
Cc Alexey Khoroshilov <[email protected]>
---
 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 6 +++---
 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c   | 2 +-
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 4 ++--
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c   | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +3 -3
index 74b4e910a38d..be7f46faef7e 100644
@@ -208,7 +208,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req
 
 	if (areq->src == areq->dst) {
 		nr_sgs = dma_map_sg(ce->dev, areq->src, ns, DMA_BIDIRECTIONAL);
-		if (nr_sgs <= 0 || nr_sgs > MAX_SG) {
+		if (!nr_sgs || nr_sgs > MAX_SG) {
 			dev_err(ce->dev, "Invalid sg number %d\n", nr_sgs);
 			err = -EINVAL;
 			goto theend_iv;
@@ -216,13 +216,13 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req
 		nr_sgd = nr_sgs;
 	} else {
 		nr_sgs = dma_map_sg(ce->dev, areq->src, ns, DMA_TO_DEVICE);
-		if (nr_sgs <= 0 || nr_sgs > MAX_SG) {
+		if (!nr_sgs || nr_sgs > MAX_SG) {
 			dev_err(ce->dev, "Invalid sg number %d\n", nr_sgs);
 			err = -EINVAL;
 			goto theend_iv;
 		}
 		nr_sgd = dma_map_sg(ce->dev, areq->dst, nd, DMA_FROM_DEVICE);
-		if (nr_sgd <= 0 || nr_sgd > MAX_SG) {
+		if (!nr_sgd || nr_sgd > MAX_SG) {
 			dev_err(ce->dev, "Invalid sg number %d\n", nr_sgd);
 			err = -EINVAL;
 			goto theend_sgs;
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c +1 -1
index 8b5b9b9d04c3..0e6843ec197f 100644
@@ -389,7 +389,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
 	cet->t_asym_ctl = 0;
 
 	nr_sgs = dma_map_sg(ce->dev, areq->src, ns, DMA_TO_DEVICE);
-	if (nr_sgs <= 0 || nr_sgs > MAX_SG) {
+	if (!nr_sgs || nr_sgs > MAX_SG) {
 		dev_err(ce->dev, "Invalid sg number %d\n", nr_sgs);
 		err = -EINVAL;
 		goto theend;
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c +2 -2
index 910d6751644c..fdcc98cdecaa 100644
@@ -232,13 +232,13 @@ static int sun8i_ss_cipher(struct skcipher_request *areq)
 		nr_sgd = nr_sgs;
 	} else {
 		nr_sgs = dma_map_sg(ss->dev, areq->src, nsgs, DMA_TO_DEVICE);
-		if (nr_sgs <= 0 || nr_sgs > 8) {
+		if (!nr_sgs || nr_sgs > 8) {
 			dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs);
 			err = -EINVAL;
 			goto theend_iv;
 		}
 		nr_sgd = dma_map_sg(ss->dev, areq->dst, nsgd, DMA_FROM_DEVICE);
-		if (nr_sgd <= 0 || nr_sgd > 8) {
+		if (!nr_sgd || nr_sgd > 8) {
 			dev_err(ss->dev, "Invalid sg number %d\n", nr_sgd);
 			err = -EINVAL;
 			goto theend_sgs;
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c +1 -1
index 36a82b22953c..fcb8c41cc957 100644
@@ -527,7 +527,7 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq)
 	rctx->method = ss->variant->alg_hash[algt->ss_algo_id];
 
 	nr_sgs = dma_map_sg(ss->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE);
-	if (nr_sgs <= 0 || nr_sgs > MAX_SG) {
+	if (!nr_sgs || nr_sgs > MAX_SG) {
 		dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs);
 		err = -EINVAL;
 		goto theend;
Signature · 1 line
2.34.1
author
#25 lore raw

PATCH 12/19 crypto: ccree: Fix dma_map_sg error check

In reply to Jack Wang

dma_map_sg return 0 on error, and dma_map_error is not supposed to use here.

Cc Gilad Ben-Yossef <[email protected]>
Cc Herbert Xu <[email protected]>
Cc "David S. Miller" <[email protected]>
---
 drivers/crypto/ccree/cc_buffer_mgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccree/cc_buffer_mgr.c +1 -1
index 6140e4927322..9efd88f871d1 100644
@@ -274,7 +274,7 @@ static int cc_map_sg(struct device *dev, struct scatterlist *sg,
 	}
 
 	ret = dma_map_sg(dev, sg, *nents, direction);
-	if (dma_mapping_error(dev, ret)) {
+	if (!ret) {
 		*nents = 0;
 		dev_err(dev, "dma_map_sg() sg buffer failed %d\n", ret);
 		return -ENOMEM;
Signature · 1 line
2.34.1
maintainer
#26 lore raw

Re: [PATCH v1 12/19] crypto: ccree: Fix dma_map_sg error check

Hi Jack,

Quoted 29 lines · Jack Wang

dma_map_sg return 0 on error, and dma_map_error is not supposed to use here.

Cc Gilad Ben-Yossef <[email protected]>
Cc Herbert Xu <[email protected]>
Cc "David S. Miller" <[email protected]>
---
 drivers/crypto/ccree/cc_buffer_mgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccree/cc_buffer_mgr.c +1 -2
index 6140e4927322..9efd88f871d1 100644
@@ -274,7 +274,7 @@ static int cc_map_sg(struct device *dev, struct scatterlist *sg,
        }
 
        ret = dma_map_sg(dev, sg, *nents, direction);
-       if (dma_mapping_error(dev, ret)) {
+       if (!ret) {
                *nents = 0;
                dev_err(dev, "dma_map_sg() sg buffer failed %d\n", ret);
                return -ENOMEM;
--
Quoted 2 lines

2.34.1

Good catch!

Thank you for the patch.

Gilad

Signature · 4 lines
Gilad Ben-Yossef
Chief Coffee Drinker

values of β will give rise to dom!
author
#27 lore raw

PATCH 13/19 intel_th: Fix dma_map_sg error check

In reply to Jack Wang

dma_map_sg return 0 on error.

---
 drivers/hwtracing/intel_th/msu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwtracing/intel_th/msu.c +1 -1
index 6c8215a47a60..b49237d56a60 100644
@@ -931,7 +931,7 @@ static int msc_buffer_contig_alloc(struct msc *msc, unsigned long size)
 
 	ret = dma_map_sg(msc_dev(msc)->parent->parent, msc->single_sgt.sgl, 1,
 			 DMA_FROM_DEVICE);
-	if (ret < 0)
+	if (!ret)
 		goto err_free_pages;
 
 	msc->nr_pages = nr_pages;
Signature · 1 line
2.34.1
author
#28 lore raw

PATCH 14/19 nvme-rdma: Fix error check for ib_dma_map_sg

In reply to Jack Wang

ib_dma_map_sg return 0 on error.

Cc Keith Busch <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Sagi Grimberg <[email protected]>
---
 drivers/nvme/host/rdma.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/rdma.c +2 -2
index 3100643be299..d70bccbcba3e 100644
@@ -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
#29 lore raw

Re: [PATCH v1 14/19] nvme-rdma: Fix error check for ib_dma_map_sg

Please don't send me just two random patches out of a series, as I have no way to review them. If the patches are independent, send them independently and if they depend on common prep work send the entire series to everyone.

author
#30 lore raw

Re: [PATCH v1 14/19] nvme-rdma: Fix error check for ib_dma_map_sg

Quoted 5 lines · Christoph Hellwig

Please don't send me just two random patches out of a series, as I have no way to review them. If the patches are independent, send them independently and if they depend on common prep work send the entire series to everyone.

Hi Christoph,

As mentioned in the cover letter, the bugfixes are all independent, for each of the drivers.

I will wait a bit to see if there is other comments, resend as you suggested later.

Thx!

#31 lore raw

Re: [PATCH v1 14/19] nvme-rdma: Fix error check for ib_dma_map_sg

Quoted 10 lines · Jinpu Wang
Quoted 5 lines · Christoph Hellwig

Please don't send me just two random patches out of a series, as I have no way to review them. If the patches are independent, send them independently and if they depend on common prep work send the entire series to everyone.

Hi Christoph,

As mentioned in the cover letter, the bugfixes are all independent, for each of the drivers.

I still haven't seen the cover letter as it was never sent to me. But if patches are independent please send a series per subsystem as that makes that very clear.

author
#32 lore raw

Re: [PATCH v1 14/19] nvme-rdma: Fix error check for ib_dma_map_sg

Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Jinpu Wang
Quoted 5 lines · Christoph Hellwig

Please don't send me just two random patches out of a series, as I have no way to review them. If the patches are independent, send them independently and if they depend on common prep work send the entire series to everyone.

Quoted 8 lines
Quoted 4 lines

Hi Christoph,

As mentioned in the cover letter, the bugfixes are all independent, for each of the drivers.

I still haven't seen the cover letter as it was never sent to me. But if patches are independent please send a series per subsystem as that makes that very clear.

Thanks for the hint, this definitely helps the subsystem maintainer to get a clear background.
I'll do it in the future.

author
#33 lore raw

PATCH 15/19 nvme-fc: Fix the error check for dma_map_sg

In reply to Jack Wang

dma_map_sg return 0 on error, add missing check.

Cc James Smart <[email protected]>
Cc Keith Busch <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Sagi Grimberg <[email protected]>
---
 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
index 127abaf9ba5d..95050f2e0a06 100644
@@ -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
index ab2627e17bb9..3749ca28860b 100644
@@ -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
author
#34 lore raw

PATCH 16/19 scsi/qlogicpti: Fix dma_map_sg check

In reply to Jack Wang

Add the missing error check for dma_map_sg.

Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
---
 drivers/scsi/qlogicpti.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/qlogicpti.c +2 -1
index 57f2f4135a06..8c961ff03fcd 100644
@@ -909,7 +909,8 @@ static inline int load_cmd(struct scsi_cmnd *Cmnd, struct Command_Entry *cmd,
 		sg_count = dma_map_sg(&qpti->op->dev, sg,
 				      scsi_sg_count(Cmnd),
 				      Cmnd->sc_data_direction);
-
+		if (!sg_count)
+			return -1;
 		ds = cmd->dataseg;
 		cmd->segment_cnt = sg_count;
 
Signature · 1 line
2.34.1
author
#35 lore raw

PATCH 17/19 mmc: meson-mx-sdhc: Fix error check for dma_map_sg

In reply to Jack Wang

dma_map_sg return 0 on error.

Cc Ulf Hansson <[email protected]>
Cc Neil Armstrong <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Jerome Brunet <[email protected]>
Cc Martin Blumenstingl <[email protected]>
---
 drivers/mmc/host/meson-mx-sdhc-mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/meson-mx-sdhc-mmc.c +1 -1
index e92e63cb5641..b32364f20c32 100644
@@ -388,7 +388,7 @@ static int meson_mx_sdhc_map_dma(struct mmc_host *mmc, struct mmc_request *mrq)
 
 	dma_len = dma_map_sg(mmc_dev(mmc), data->sg, data->sg_len,
 			     mmc_get_dma_dir(data));
-	if (dma_len <= 0) {
+	if (!dma_len) {
 		dev_err(mmc_dev(mmc), "dma_map_sg failed\n");
 		return -ENOMEM;
 	}
Signature · 1 line
2.34.1
#36 lore raw

Re: [PATCH v1 17/19] mmc: meson-mx-sdhc: Fix error check for dma_map_sg

Hello Jack,

first of all: thank you for this patch!

On Fri, Aug 19, 2022 at 8:08 AM Jack Wang <[email protected]> wrote:
[...]

drivers/mmc/host/meson-mx-sdhc-mmc.c static int meson_mx_sdhc_map_dma(struct mmc_host *mmc, struct mmc_request *mrq) · line 389

Quoted 3 lines
drivers/mmc/host/meson-mx-sdhc-mmc.c +0 -0
@@ -388,7 +388,7 @@ static int meson_mx_sdhc_map_dma(struct mmc_host *mmc, struct mmc_request *mrq)
 
        dma_len = dma_map_sg(mmc_dev(mmc), data->sg, data->sg_len,

Does it also make sense to change the type of the dma_len variable from (signed) int to "unsigned int" (a few lines above)?

Best regards,
Martin

author
#37 lore raw

Re: [PATCH v1 17/19] mmc: meson-mx-sdhc: Fix error check for dma_map_sg

Hi Martin,

Quoted 4 lines · Martin Blumenstingl

Hello Jack,

first of all: thank you for this patch!

welcome.

Quoted 8 lines · Jack Wang

[...]

drivers/mmc/host/meson-mx-sdhc-mmc.c static int meson_mx_sdhc_map_dma(struct mmc_host *mmc, struct mmc_request *mrq) · line 389

Quoted 3 lines
drivers/mmc/host/meson-mx-sdhc-mmc.c +0 -0
@@ -388,7 +388,7 @@ static int meson_mx_sdhc_map_dma(struct mmc_host *mmc, struct mmc_request *mrq)
 
        dma_len = dma_map_sg(mmc_dev(mmc), data->sg, data->sg_len,

Does it also make sense to change the type of the dma_len variable from (signed) int to "unsigned int" (a few lines above)?

I double checked, it seems a good idea, I will do it in v2.

Quoted 4 lines

Best regards,
Martin

Thx!

author
#38 lore raw

PATCH 18/19 mmc: jz4740_mmc: Fix error check for dma_map_sg

In reply to Jack Wang

dma_map_sg return 0 on error.

---
 drivers/mmc/host/jz4740_mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/jz4740_mmc.c +1 -1
index b1d563b2ed1b..666600055b06 100644
@@ -308,7 +308,7 @@ static int jz4740_mmc_prepare_dma_data(struct jz4740_mmc_host *host,
 			data->sg_len,
 			dir);
 
-	if (sg_count <= 0) {
+	if (!sg_count) {
 		dev_err(mmc_dev(host->mmc),
 			"Failed to map scatterlist for DMA operation\n");
 		return -EINVAL;
Signature · 1 line
2.34.1
author
#39 lore raw

PATCH 19/19 net/mlx4: Fix error check for dma_map_sg

In reply to Jack Wang

dma_map_sg return 0 on error.

Cc Tariq Toukan <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
---
 drivers/net/ethernet/mellanox/mlx4/icm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx4/icm.c +2 -2
index d89a3da89e5a..59b8b3c73582 100644
@@ -208,7 +208,7 @@ struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages,
 						chunk->sg, chunk->npages,
 						DMA_BIDIRECTIONAL);
 
-			if (chunk->nsg <= 0)
+			if (!chunk->nsg)
 				goto fail;
 		}
 
@@ -222,7 +222,7 @@ struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages,
 		chunk->nsg = dma_map_sg(&dev->persist->pdev->dev, chunk->sg,
 					chunk->npages, DMA_BIDIRECTIONAL);
 
-		if (chunk->nsg <= 0)
+		if (!chunk->nsg)
 			goto fail;
 	}
 
Signature · 1 line
2.34.1
Reviewed-by on v1 19/19
#40 lore raw

Re: [PATCH v1 19/19] net/mlx4: Fix error check for dma_map_sg

Quoted 11 lines · Jack Wang

dma_map_sg return 0 on error.

Cc Tariq Toukan <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Quoted 5 lines
---
 drivers/net/ethernet/mellanox/mlx4/icm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Thanks,

maintainer
#41 lore raw

Re: [PATCH v1 19/19] net/mlx4: Fix error check for dma_map_sg

In reply to Jack Wang
Quoted 1 line · On Fri, 19 Aug 2022 08:08:01 +0200 Jack Wang wrote:

dma_map_sg return 0 on error.

You need to resend it as an individual patch, not part of a series if you want it to be applied to the networking tree. Please keep Leon's review tag.

author
#42 lore raw

Re: [PATCH v1 19/19] net/mlx4: Fix error check for dma_map_sg

Quoted 7 lines · Jakub Kicinski
Quoted 1 line · On Fri, 19 Aug 2022 08:08:01 +0200 Jack Wang wrote:

dma_map_sg return 0 on error.

You need to resend it as an individual patch, not part of a series if you want it to be applied to the networking tree. Please keep Leon's review tag.

Got it. Will do