Fix dma_map_sg error check
Subsystems (30)
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
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
@@ -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
Re: [PATCH v1 01/19] mailbox: bcm-ferxrm-mailbox: Fix error check for dma_map_sg
Quoted 6 lines · Jack Wang
dma_map_sgreturn 0 on error, fix the error check, and return-EIOto caller.
This needs a Fixes tag.
regards,
dan carpenter
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_sgreturn 0 on error, fix the error check, and return-EIOto 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
PATCH 2/19 infiniband/mthca: Fix dma_map_sg error check
In reply to Jack Wangdma_map_sg return 0 on error, in case of error set EIO as return code.
--- drivers/infiniband/hw/mthca/mthca_memfree.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/infiniband/hw/mthca/mthca_memfree.c +4 -3
@@ -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
Re: [PATCH v1 02/19] infiniband/mthca: Fix dma_map_sg error check
Quoted 11 lines · Jack Wang
dma_map_sgreturn 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]>Signed-off-by Jack Wang <[email protected]>
Signature · 1 line
Kees Cook
Re: [PATCH v1 02/19] infiniband/mthca: Fix dma_map_sg error check
In reply to Jack WangQuoted 38 lines · Jack Wang
dma_map_sgreturn 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]>Signed-off-by Jack Wang <[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@@ -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
-0unpin_user_page (pages[0 ]); + ret = -EIO ; goto out; }Signature · 1 line
2.34.1
Re: [PATCH v1 02/19] infiniband/mthca: Fix dma_map_sg error check
In reply to Jack WangQuoted 3 lines · Jack Wang
dma_map_sgreturn 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
PATCH 3/19 HSI: omap_ssi_port: Fix dma_map_sg error check
In reply to Jack Wangdma_map_sg return 0 on error, in case of error return -EIO to caller.
--- drivers/hsi/controllers/omap_ssi_port.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hsi/controllers/omap_ssi_port.c +4 -4
@@ -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
PATCH 4/19 mtd: rawnand: stm32_fmc2: Fix dma_map_sg error check
In reply to Jack Wangdma_map_sg return 0 on error, in case of error return -EIO.
--- 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
@@ -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
Re: [PATCH v1 04/19] mtd: rawnand: stm32_fmc2: Fix dma_map_sg error check
Hi Jack,
Quoted 36 lines · Jack Wang
dma_map_sgreturn 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]>Signed-off-by Jack Wang <[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@@ -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
-1ret =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.
Re: [PATCH v1 04/19] mtd: rawnand: stm32_fmc2: Fix dma_map_sg error check
In reply to Jack WangQuoted 16 lines · Jack Wang
dma_map_sgreturn 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]>Signed-off-by Jack Wang <[email protected]>Reviewed-by Christophe Kerello <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
PATCH 5/19 mtd: rawnand: marvell: Fix error handle regarding dma_map_sg
In reply to Jack Wangdma_map_sg return 0 on error, in case of error return -EIO, also add the dma_unmap_sg as rollback on the following error.
--- drivers/mtd/nand/raw/marvell_nand.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/mtd/nand/raw/marvell_nand.c +7 -1
@@ -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
Re: [PATCH v1 05/19] mtd: rawnand: marvell: Fix error handle regarding dma_map_sg
Quoted 16 lines · Jack Wang
dma_map_sgreturn 0 on error, in case of error return-EIO, also add thedma_unmap_sgas 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
Signed-off-by Jack Wang <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
PATCH 6/19 usb/hcd: Fix dma_map_sg error check
In reply to Jack Wangdma_map_sg return 0 on error.
--- drivers/usb/core/hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/core/hcd.c +1 -1
@@ -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
PATCH 7/19 crypto: gemin: Fix error check for dma_map_sg
In reply to Jack Wangdma_map_sg return 0 on error.
--- drivers/crypto/gemini/sl3516-ce-cipher.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/gemini/sl3516-ce-cipher.c +3 -3
@@ -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
Re: [PATCH v1 07/19] crypto: gemin: Fix error check for dma_map_sg
Quoted 11 lines · Jack Wang
dma_map_sgreturn 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]>Signed-off-by Jack Wang <[email protected]>
Good catch!
Yours,
Linus Walleij
Herbert Xu
maintainerRe: [PATCH v1 07/19] crypto: gemin: Fix error check for dma_map_sg
In reply to Jack WangQuoted 11 lines · Jack Wang
dma_map_sgreturn 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]>Signed-off-by Jack Wang <[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
Re: [PATCH v1 07/19] crypto: gemin: Fix error check for dma_map_sg
In reply to Jack WangQuoted 11 lines · Jack Wang
dma_map_sgreturn 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]>Signed-off-by Jack Wang <[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
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_sgreturn 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]>Signed-off-by Jack Wang <[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
Acked-by Corentin Labbe <[email protected]>Tested-by Corentin Labbe <[email protected]>Thanks
Regards
Thx!
PATCH 8/19 crypto: sahara: Fix error check for dma_map_sg
In reply to Jack Wangdma_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
@@ -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
PATCH 9/19 crypto: qce: Fix dma_map_sg error check
In reply to Jack Wangdma_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
@@ -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
@@ -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
@@ -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
PATCH 10/19 crypto: amlogic: Fix dma_map_sg error check
In reply to Jack Wangdma_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
@@ -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
Re: [PATCH v1 10/19] crypto: amlogic: Fix dma_map_sg error check
Quoted 9 lines · Jack Wang
dma_map_sgreturn 0 on error.Cc Corentin Labbe <[email protected]>Cc Herbert Xu <[email protected]>Cc "David S. Miller" <[email protected]>
Quoted 5 lines
Signed-off-by Jack Wang <[email protected]>--- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Hello
Thanks
Regards
PATCH 11/19 crypto: allwinner: Fix dma_map_sg error check
In reply to Jack Wangdma_map_sg return 0 on error.
--- 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
@@ -208,7 +208,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_reqif (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
@@ -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
@@ -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
@@ -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
PATCH 12/19 crypto: ccree: Fix dma_map_sg error check
In reply to Jack Wangdma_map_sg return 0 on error, and dma_map_error is not supposed to use here.
--- drivers/crypto/ccree/cc_buffer_mgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccree/cc_buffer_mgr.c +1 -1
@@ -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
Gilad Ben-Yossef
maintainerRe: [PATCH v1 12/19] crypto: ccree: Fix dma_map_sg error check
Hi Jack,
Quoted 29 lines · Jack Wang
dma_map_sgreturn 0 on error, anddma_map_erroris not supposed to use here.Cc Gilad Ben-Yossef <[email protected]>Cc Herbert Xu <[email protected]>Cc "David S. Miller" <[email protected]>Signed-off-by Jack Wang <[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@@ -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!
PATCH 13/19 intel_th: Fix dma_map_sg error check
In reply to Jack Wangdma_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
@@ -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
PATCH 14/19 nvme-rdma: Fix error check for ib_dma_map_sg
In reply to Jack Wangib_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
Christoph Hellwig
maintainerRe: [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.
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!
Christoph Hellwig
maintainerRe: [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.
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.
PATCH 15/19 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
PATCH 16/19 scsi/qlogicpti: Fix dma_map_sg check
In reply to Jack WangAdd the missing error check for dma_map_sg.
--- drivers/scsi/qlogicpti.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/qlogicpti.c +2 -1
@@ -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
PATCH 17/19 mmc: meson-mx-sdhc: Fix error check for dma_map_sg
In reply to Jack Wangdma_map_sg return 0 on error.
--- 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
@@ -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
Martin Blumenstingl
reviewerRe: [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
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_lenvariable 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!
PATCH 18/19 mmc: jz4740_mmc: Fix error check for dma_map_sg
In reply to Jack Wangdma_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
@@ -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
PATCH 19/19 net/mlx4: Fix error check for dma_map_sg
In reply to Jack Wangdma_map_sg return 0 on error.
--- drivers/net/ethernet/mellanox/mlx4/icm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx4/icm.c +2 -2
@@ -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
Re: [PATCH v1 19/19] net/mlx4: Fix error check for dma_map_sg
Quoted 11 lines · Jack Wang
dma_map_sgreturn 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
Signed-off-by Jack Wang <[email protected]>--- drivers/net/ethernet/mellanox/mlx4/icm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Thanks,
Jakub Kicinski
maintainerRe: [PATCH v1 19/19] net/mlx4: Fix error check for dma_map_sg
In reply to Jack WangQuoted 1 line · On Fri, 19 Aug 2022 08:08:01 +0200 Jack Wang wrote:
dma_map_sgreturn 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.
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_sgreturn 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