diff mbox series

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

Message ID 20220819060801.10443-3-jinpu.wang@ionos.com (mailing list archive)
State Rejected
Headers show
Series None | expand

Commit Message

Jinpu Wang Aug. 19, 2022, 6:07 a.m. UTC
dma_map_sg return 0 on error, in case of error set
EIO as return code.

Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Kees Cook <keescook@chromium.org>
Cc: "Håkon Bugge" <haakon.bugge@oracle.com>
Cc: linux-rdma@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
---
 drivers/infiniband/hw/mthca/mthca_memfree.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Kees Cook Aug. 19, 2022, 10:19 p.m. UTC | #1
On Fri, Aug 19, 2022 at 08:07:44AM +0200, Jack Wang wrote:
> dma_map_sg return 0 on error, in case of error set
> EIO as return code.
> 
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Leon Romanovsky <leon@kernel.org>
> Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: "Håkon Bugge" <haakon.bugge@oracle.com>
> Cc: linux-rdma@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Jack Wang <jinpu.wang@ionos.com>

Reviewed-by: Kees Cook <keescook@chromium.org>
Leon Romanovsky Aug. 21, 2022, 11:46 a.m. UTC | #2
On Fri, Aug 19, 2022 at 08:07:44AM +0200, Jack Wang wrote:
> dma_map_sg return 0 on error, in case of error set
> EIO as return code.
> 
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Leon Romanovsky <leon@kernel.org>
> Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: "Håkon Bugge" <haakon.bugge@oracle.com>
> Cc: linux-rdma@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
> ---
>  drivers/infiniband/hw/mthca/mthca_memfree.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
> index f2734a5c5f26..44fd5fdf64d5 100644
> --- a/drivers/infiniband/hw/mthca/mthca_memfree.c
> +++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
> @@ -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) {

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

>  		unpin_user_page(pages[0]);
> +		ret = -EIO;
>  		goto out;
>  	}
>  
> -- 
> 2.34.1
>
Dan Carpenter Aug. 22, 2022, 5:11 a.m. UTC | #3
On Fri, Aug 19, 2022 at 08:07:44AM +0200, Jack Wang wrote:
> 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
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index f2734a5c5f26..44fd5fdf64d5 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -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;
 	}