Skip to content

Commit 248014a

Browse files
jinpuwanggregkh
authored andcommitted
RDMA/rtrs-srv: Do not pass a valid pointer to PTR_ERR()
[ Upstream commit ed40852 ] smatch gives the warning: drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805 rtrs_rdma_connect() warn: passing zero to 'PTR_ERR' Which is trying to say smatch has shown that srv is not an error pointer and thus cannot be passed to PTR_ERR. The solution is to move the list_add() down after full initilization of rtrs_srv. To avoid holding the srv_mutex too long, only hold it during the list operation as suggested by Leon. Fixes: 03e9b33 ("RDMA/rtrs: Only allow addition of path to an already established session") Link: https://lore.kernel.org/r/20210216143807.65923-1-jinpu.wang@cloud.ionos.com Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Jack Wang <jinpu.wang@cloud.ionos.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d94d649 commit 248014a

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

‎drivers/infiniband/ulp/rtrs/rtrs-srv.c‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,21 +1364,18 @@ static struct rtrs_srv *get_or_create_srv(struct rtrs_srv_ctx *ctx,
13641364
return srv;
13651365
}
13661366
}
1367+
mutex_unlock(&ctx->srv_mutex);
13671368
/*
13681369
* If this request is not the first connection request from the
13691370
* client for this session then fail and return error.
13701371
*/
1371-
if (!first_conn) {
1372-
mutex_unlock(&ctx->srv_mutex);
1372+
if (!first_conn)
13731373
return ERR_PTR(-ENXIO);
1374-
}
13751374

13761375
/* need to allocate a new srv */
13771376
srv = kzalloc(sizeof(*srv), GFP_KERNEL);
1378-
if (!srv) {
1379-
mutex_unlock(&ctx->srv_mutex);
1377+
if (!srv)
13801378
return ERR_PTR(-ENOMEM);
1381-
}
13821379

13831380
INIT_LIST_HEAD(&srv->paths_list);
13841381
mutex_init(&srv->paths_mutex);
@@ -1388,8 +1385,6 @@ static struct rtrs_srv *get_or_create_srv(struct rtrs_srv_ctx *ctx,
13881385
srv->ctx = ctx;
13891386
device_initialize(&srv->dev);
13901387
srv->dev.release = rtrs_srv_dev_release;
1391-
list_add(&srv->ctx_list, &ctx->srv_list);
1392-
mutex_unlock(&ctx->srv_mutex);
13931388

13941389
srv->chunks = kcalloc(srv->queue_depth, sizeof(*srv->chunks),
13951390
GFP_KERNEL);
@@ -1402,6 +1397,9 @@ static struct rtrs_srv *get_or_create_srv(struct rtrs_srv_ctx *ctx,
14021397
goto err_free_chunks;
14031398
}
14041399
refcount_set(&srv->refcount, 1);
1400+
mutex_lock(&ctx->srv_mutex);
1401+
list_add(&srv->ctx_list, &ctx->srv_list);
1402+
mutex_unlock(&ctx->srv_mutex);
14051403

14061404
return srv;
14071405

@@ -1816,11 +1814,7 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id,
18161814
}
18171815
recon_cnt = le16_to_cpu(msg->recon_cnt);
18181816
srv = get_or_create_srv(ctx, &msg->paths_uuid, msg->first_conn);
1819-
/*
1820-
* "refcount == 0" happens if a previous thread calls get_or_create_srv
1821-
* allocate srv, but chunks of srv are not allocated yet.
1822-
*/
1823-
if (IS_ERR(srv) || refcount_read(&srv->refcount) == 0) {
1817+
if (IS_ERR(srv)) {
18241818
err = PTR_ERR(srv);
18251819
goto reject_w_err;
18261820
}

0 commit comments

Comments
 (0)