Skip to content

Commit

Permalink
RDMA/irdma: Check return value from ib_umem_find_best_pgsz
Browse files Browse the repository at this point in the history
iwmr->page_size stores the return from ib_umem_find_best_pgsz and maybe
zero when used in ib_umem_num_dma_blocks thus causing a divide by zero
error.

Fix this by erroring out of irdma_reg_user when 0 is returned from
ib_umem_find_best_pgsz.

Link: https://lore.kernel.org/r/[email protected]
Reported-by: coverity-bot <[email protected]>
Addresses-Coverity-ID: 1505149 ("Integer handling issues")
Fixes: b48c24c ("RDMA/irdma: Implement device supported verb APIs")
Signed-off-by: Shiraz Saleem <[email protected]>
Signed-off-by: Tatyana Nikolova <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>
  • Loading branch information
shirazsaleem authored and jgunthorpe committed Jun 22, 2021
1 parent f176199 commit c4eb44f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/infiniband/hw/irdma/verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2783,10 +2783,16 @@ static struct ib_mr *irdma_reg_user_mr(struct ib_pd *pd, u64 start, u64 len,
iwmr->ibmr.iova = virt;
iwmr->page_size = PAGE_SIZE;

if (req.reg_type == IRDMA_MEMREG_TYPE_MEM)
if (req.reg_type == IRDMA_MEMREG_TYPE_MEM) {
iwmr->page_size = ib_umem_find_best_pgsz(region,
SZ_4K | SZ_2M | SZ_1G,
virt);
if (unlikely(!iwmr->page_size)) {
kfree(iwmr);
ib_umem_release(region);
return ERR_PTR(-EOPNOTSUPP);
}
}
iwmr->len = region->length;
iwpbl->user_base = virt;
palloc = &iwpbl->pble_alloc;
Expand Down

0 comments on commit c4eb44f

Please sign in to comment.