OSDN Git Service

IB/core: type promotion bug in rdma_rw_init_one_mr()
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 4 Jul 2018 09:32:12 +0000 (12:32 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Oct 2018 00:01:44 +0000 (17:01 -0700)
[ Upstream commit c2d7c8ff89b22ddefb1ac2986c0d48444a667689 ]

"nents" is an unsigned int, so if ib_map_mr_sg() returns a negative
error code then it's type promoted to a high unsigned int which is
treated as success.

Fixes: a060b5629ab0 ("IB/core: generic RDMA READ/WRITE API")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/infiniband/core/rw.c

index dbfd854..1d90a12 100644 (file)
@@ -87,7 +87,7 @@ static int rdma_rw_init_one_mr(struct ib_qp *qp, u8 port_num,
        }
 
        ret = ib_map_mr_sg(reg->mr, sg, nents, &offset, PAGE_SIZE);
-       if (ret < nents) {
+       if (ret < 0 || ret < nents) {
                ib_mr_pool_put(qp, &qp->rdma_mrs, reg->mr);
                return -EINVAL;
        }