RDMA/rtrs-srv: suppress warnings passing zero to 'PTR_ERR'
Subsystems (2)
PATCH 1/1 RDMA/rtrs-srv: suppress warnings passing zero to 'PTR_ERR'
smatch warnings:drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805 rtrs_rdma_connect() warn: passing zero to 'PTR_ERR'
Smatch seems confused by the refcount_read condition, so just treat it seperately.
--- drivers/infiniband/ulp/rtrs/rtrs-srv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-srv.c +6 -2
@@ -1799,12 +1799,16 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, } recon_cnt =le16_to_cpu (msg->recon_cnt); srv =get_or_create_srv (ctx, &msg->paths_uuid, msg->first_conn); +if (IS_ERR (srv)) { + err =PTR_ERR (srv); + goto reject_w_err; + }/* * "refcount == 0" happens if a previous thread calls get_or_create_srv * allocate srv, but chunks of srv are not allocated yet. */ -if (IS_ERR (srv) ||refcount_read (&srv->refcount) ==0 ) { - err =PTR_ERR (srv); +if (refcount_read (&srv->refcount) ==0 ) { + err = -EBUSY ; goto reject_w_err; }mutex_lock (&srv->paths_mutex);
Signature · 1 line
2.25.1
Quoted 23 lines · Jack Wang
smatch warnings:
drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805rtrs_rdma_connect()warn: passing zero to 'PTR_ERR'Smatch seems confused by the
refcount_readcondition, so just treat it seperately.Fixes f0751419d3a1 ("RDMA/rtrs: Only allow addition of path to an already established session")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Jack Wang <[email protected]>--- drivers/infiniband/ulp/rtrs/rtrs-srv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/infiniband/ulp/rtrs/rtrs-srv.c +1
-0@@ -1799,12 +1799,16 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, } recon_cnt =le16_to_cpu (msg->recon_cnt); srv =get_or_create_srv (ctx, &msg->paths_uuid, msg->first_conn); +if (IS_ERR (srv)) {
drivers/infiniband/ulp/rtrs/rtrs-srv.c static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, · line 1810
Quoted 10 lines
drivers/infiniband/ulp/rtrs/rtrs-srv.c +4
-2+ err =PTR_ERR (srv); + goto reject_w_err; + }/* * "refcount == 0" happens if a previous thread calls get_or_create_srv * allocate srv, but chunks of srv are not allocated yet. */ -if (IS_ERR (srv) ||refcount_read (&srv->refcount) ==0 ) { - err =PTR_ERR (srv); +if (refcount_read (&srv->refcount) ==0 ) {
I would say that "list_add(&srv->ctx_list, &ctx->srv_list);" line in the get_or_create_srv() is performed too early, relying on zero in the refcount doesn't look great.
Thanks
Hi Leon,
Quoted 30 lines · Leon Romanovsky
Quoted 28 lines · Jack Wang
smatch warnings:
drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805rtrs_rdma_connect()warn: passing zero to 'PTR_ERR'Smatch seems confused by the
refcount_readcondition, so just treat it seperately.Fixes f0751419d3a1 ("RDMA/rtrs: Only allow addition of path to an already established session")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Jack Wang <[email protected]>--- drivers/infiniband/ulp/rtrs/rtrs-srv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/infiniband/ulp/rtrs/rtrs-srv.c +4
-0@@ -1799,12 +1799,16 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, } recon_cnt =le16_to_cpu (msg->recon_cnt); srv =get_or_create_srv (ctx, &msg->paths_uuid, msg->first_conn); +if (IS_ERR (srv)) { + err =PTR_ERR (srv); + goto reject_w_err; + }/* * "refcount == 0" happens if a previous thread calls get_or_create_srv
Quoted 8 lines
drivers/infiniband/ulp/rtrs/rtrs-srv.c static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, · line 1810
Quoted 5 lines
drivers/infiniband/ulp/rtrs/rtrs-srv.c +1
-2* allocate srv, but chunks of srv are not allocated yet. */ -if (IS_ERR (srv) ||refcount_read (&srv->refcount) ==0 ) { - err =PTR_ERR (srv); +if (refcount_read (&srv->refcount) ==0 ) {I would say that "
list_add(&srv->ctx_list, &ctx->srv_list);" line in theget_or_create_srv()is performed too early,
Moving list_add down to the end was the initial code, but we noticed the memory allocation could take quite
some time when system under memory pressure, hence we changed it in d715ff8acbd5 ("RDMA/rtrs-srv: Don't guard the whole __alloc_srv with srv_mutex")
Thanks for the comment.
Quoted 40 lines · Jinpu Wang
Hi Leon,
Quoted 30 lines · Leon Romanovsky
Quoted 28 lines · Jack Wang
smatch warnings:
drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805rtrs_rdma_connect()warn: passing zero to 'PTR_ERR'Smatch seems confused by the
refcount_readcondition, so just treat it seperately.Fixes f0751419d3a1 ("RDMA/rtrs: Only allow addition of path to an already established session")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Jack Wang <[email protected]>--- drivers/infiniband/ulp/rtrs/rtrs-srv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/infiniband/ulp/rtrs/rtrs-srv.c +4
-0@@ -1799,12 +1799,16 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, } recon_cnt =le16_to_cpu (msg->recon_cnt); srv =get_or_create_srv (ctx, &msg->paths_uuid, msg->first_conn); +if (IS_ERR (srv)) { + err =PTR_ERR (srv); + goto reject_w_err; + }/* * "refcount == 0" happens if a previous thread calls get_or_create_srv Quoted 8 lines
drivers/infiniband/ulp/rtrs/rtrs-srv.c static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, · line 1810
Quoted 5 lines
drivers/infiniband/ulp/rtrs/rtrs-srv.c +1
-2* allocate srv, but chunks of srv are not allocated yet. */ -if (IS_ERR (srv) ||refcount_read (&srv->refcount) ==0 ) { - err =PTR_ERR (srv); +if (refcount_read (&srv->refcount) ==0 ) {I would say that "
list_add(&srv->ctx_list, &ctx->srv_list);" line in theget_or_create_srv()is performed too early,
Quoted 5 lines
Moving
list_adddown to the end was the initial code, but we noticed the memory allocation could take quite
some time when system under memory pressure, hence we changed it ind715ff8acbd5("RDMA/rtrs-srv: Don't guard the whole__alloc_srvwithsrv_mutex")
You don't need to hold lock during allocation, only during search in the list.
Thanks
Quoted 2 lines
Thanks for the comment.
Quoted 42 lines · Leon Romanovsky
Quoted 40 lines · Jinpu Wang
Hi Leon,
Quoted 38 lines · Leon Romanovsky
Quoted 23 lines · Jack Wang
smatch warnings:
drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805rtrs_rdma_connect()warn: passing zero to 'PTR_ERR'Smatch seems confused by the
refcount_readcondition, so just treat it seperately.Fixes f0751419d3a1 ("RDMA/rtrs: Only allow addition of path to an already established session")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Jack Wang <[email protected]>--- drivers/infiniband/ulp/rtrs/rtrs-srv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/infiniband/ulp/rtrs/rtrs-srv.c +1
-0@@ -1799,12 +1799,16 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, } recon_cnt =le16_to_cpu (msg->recon_cnt); srv =get_or_create_srv (ctx, &msg->paths_uuid, msg->first_conn); +if (IS_ERR (srv)) {drivers/infiniband/ulp/rtrs/rtrs-srv.c static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, · line 1810
Quoted 10 lines
drivers/infiniband/ulp/rtrs/rtrs-srv.c +4
-2+ err =PTR_ERR (srv); + goto reject_w_err; + }/* * "refcount == 0" happens if a previous thread calls get_or_create_srv * allocate srv, but chunks of srv are not allocated yet. */ -if (IS_ERR (srv) ||refcount_read (&srv->refcount) ==0 ) { - err =PTR_ERR (srv); +if (refcount_read (&srv->refcount) ==0 ) {I would say that "
list_add(&srv->ctx_list, &ctx->srv_list);" line in theget_or_create_srv()is performed too early,
Quoted 7 lines
Quoted 5 lines
Moving
list_adddown to the end was the initial code, but we noticed the memory allocation could take quite
some time when system under memory pressure, hence we changed it ind715ff8acbd5("RDMA/rtrs-srv: Don't guard the whole__alloc_srvwithsrv_mutex")You don't need to hold lock during allocation, only during search in the list.
Thanks, I will try and test.
Quoted 5 lines
Thanks
Quoted 2 lines
Thanks for the comment.