Skip to content

Commit 6cbc167

Browse files
Gioh Kimgregkh
authored andcommitted
RDMA/rtrs-clt: Fix memory leak of not-freed sess->stats and stats->pcpu_stats
[ Upstream commit 7ecd7e2 ] sess->stats and sess->stats->pcpu_stats objects are freed when sysfs entry is removed. If something wrong happens and session is closed before sysfs entry is created, sess->stats and sess->stats->pcpu_stats objects are not freed. This patch adds freeing of them at three places: 1. When client uses wrong address and session creation fails. 2. When client fails to create a sysfs entry. 3. When client adds wrong address via sysfs add_path. Fixes: 215378b ("RDMA/rtrs: client: sysfs interface functions") Link: https://lore.kernel.org/r/20210528113018.52290-21-jinpu.wang@ionos.com Signed-off-by: Gioh Kim <gi-oh.kim@ionos.com> Signed-off-by: Jack Wang <jinpu.wang@ionos.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6569ae1 commit 6cbc167

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,6 +2706,8 @@ struct rtrs_clt *rtrs_clt_open(struct rtrs_clt_ops *ops,
27062706
if (err) {
27072707
list_del_rcu(&sess->s.entry);
27082708
rtrs_clt_close_conns(sess, true);
2709+
free_percpu(sess->stats->pcpu_stats);
2710+
kfree(sess->stats);
27092711
free_sess(sess);
27102712
goto close_all_sess;
27112713
}
@@ -2714,6 +2716,8 @@ struct rtrs_clt *rtrs_clt_open(struct rtrs_clt_ops *ops,
27142716
if (err) {
27152717
list_del_rcu(&sess->s.entry);
27162718
rtrs_clt_close_conns(sess, true);
2719+
free_percpu(sess->stats->pcpu_stats);
2720+
kfree(sess->stats);
27172721
free_sess(sess);
27182722
goto close_all_sess;
27192723
}
@@ -2973,6 +2977,8 @@ int rtrs_clt_create_path_from_sysfs(struct rtrs_clt *clt,
29732977
close_sess:
29742978
rtrs_clt_remove_path_from_arr(sess);
29752979
rtrs_clt_close_conns(sess, true);
2980+
free_percpu(sess->stats->pcpu_stats);
2981+
kfree(sess->stats);
29762982
free_sess(sess);
29772983

29782984
return err;

0 commit comments

Comments
 (0)