Skip to content

Commit

Permalink
RDMA/rtrs: Fix some signedness bugs in error handling
Browse files Browse the repository at this point in the history
The problem is that "req->sg_cnt" is an unsigned int so if "nr" is
negative, it gets type promoted to a high positive value and the condition
is false.  This patch fixes it by handling negatives separately.

Fixes: 6a98d71 ("RDMA/rtrs: client: main functionality")
Link: https://lore.kernel.org/r/20200519133223.GN2078@kadam
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
  • Loading branch information
Dan Carpenter authored and Jason Gunthorpe committed May 19, 2020
1 parent 23bbd58 commit b386cd6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions drivers/infiniband/ulp/rtrs/rtrs-clt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,11 +1047,10 @@ static int rtrs_map_sg_fr(struct rtrs_clt_io_req *req, size_t count)

/* Align the MR to a 4K page size to match the block virt boundary */
nr = ib_map_mr_sg(req->mr, req->sglist, count, NULL, SZ_4K);
if (unlikely(nr < req->sg_cnt)) {
if (nr < 0)
return nr;
if (nr < 0)
return nr;
if (unlikely(nr < req->sg_cnt))
return -EINVAL;
}
ib_update_fast_reg_key(req->mr, ib_inc_rkey(req->mr->rkey));

return nr;
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/ulp/rtrs/rtrs-srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ static int map_cont_bufs(struct rtrs_srv_sess *sess)
}
nr = ib_map_mr_sg(mr, sgt->sgl, sgt->nents,
NULL, max_chunk_size);
if (nr < sgt->nents) {
if (nr < 0 || nr < sgt->nents) {
err = nr < 0 ? nr : -EINVAL;
goto dereg_mr;
}
Expand Down

0 comments on commit b386cd6

Please sign in to comment.