2022-08-26 10:04:23

by Jinpu Wang

[permalink] [raw]
Subject: [PATCH 1/2] infiniband/mthca: Fix dma_map_sg error check

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]>
Cc: [email protected]
Cc: [email protected]
Fixes: 56483ec1b702 ("[PATCH] IB uverbs: add mthca user doorbell record support")
Signed-off-by: Jack Wang <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
---
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) {
unpin_user_page(pages[0]);
+ ret = -EIO;
goto out;
}

--
2.34.1


2022-08-28 10:44:50

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH 1/2] infiniband/mthca: Fix dma_map_sg error check

On Fri, Aug 26, 2022 at 11:56:14AM +0200, Jack Wang wrote:
> 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]>
> Cc: [email protected]
> Cc: [email protected]
> Fixes: 56483ec1b702 ("[PATCH] IB uverbs: add mthca user doorbell record support")
> Signed-off-by: Jack Wang <[email protected]>
> Reviewed-by: Kees Cook <[email protected]>
> ---
> drivers/infiniband/hw/mthca/mthca_memfree.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)

Same answer as was here
https://lore.kernel.org/all/YwIbI3ktmEiLsy6s@unreal

Thanks

2022-08-29 05:50:18

by Jinpu Wang

[permalink] [raw]
Subject: Re: [PATCH 1/2] infiniband/mthca: Fix dma_map_sg error check

On Sun, Aug 28, 2022 at 12:10 PM Leon Romanovsky <[email protected]> wrote:
>
> On Fri, Aug 26, 2022 at 11:56:14AM +0200, Jack Wang wrote:
> > 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]>
> > Cc: [email protected]
> > Cc: [email protected]
> > Fixes: 56483ec1b702 ("[PATCH] IB uverbs: add mthca user doorbell record support")
> > Signed-off-by: Jack Wang <[email protected]>
> > Reviewed-by: Kees Cook <[email protected]>
> > ---
> > drivers/infiniband/hw/mthca/mthca_memfree.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
>
> Same answer as was here
> https://lore.kernel.org/all/YwIbI3ktmEiLsy6s@unreal
>
> Thanks
ok, I see you are firm on this, we can skip the patch