Skip to content

Commit 7ecd7e2

Browse files
Gioh Kimjgunthorpe
authored andcommitted
RDMA/rtrs-clt: Fix memory leak of not-freed sess->stats and stats->pcpu_stats
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>
1 parent 5b73b79 commit 7ecd7e2

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
@@ -2765,6 +2765,8 @@ struct rtrs_clt *rtrs_clt_open(struct rtrs_clt_ops *ops,
27652765
if (err) {
27662766
list_del_rcu(&sess->s.entry);
27672767
rtrs_clt_close_conns(sess, true);
2768+
free_percpu(sess->stats->pcpu_stats);
2769+
kfree(sess->stats);
27682770
free_sess(sess);
27692771
goto close_all_sess;
27702772
}
@@ -2773,6 +2775,8 @@ struct rtrs_clt *rtrs_clt_open(struct rtrs_clt_ops *ops,
27732775
if (err) {
27742776
list_del_rcu(&sess->s.entry);
27752777
rtrs_clt_close_conns(sess, true);
2778+
free_percpu(sess->stats->pcpu_stats);
2779+
kfree(sess->stats);
27762780
free_sess(sess);
27772781
goto close_all_sess;
27782782
}
@@ -3048,6 +3052,8 @@ int rtrs_clt_create_path_from_sysfs(struct rtrs_clt *clt,
30483052
close_sess:
30493053
rtrs_clt_remove_path_from_arr(sess);
30503054
rtrs_clt_close_conns(sess, true);
3055+
free_percpu(sess->stats->pcpu_stats);
3056+
kfree(sess->stats);
30513057
free_sess(sess);
30523058

30533059
return err;

0 commit comments

Comments
 (0)