Date: Fri, 22 Jan 2021 12:48:33 GMT From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 8302e83a1c4e - stable/11 - MFC 376e130b4707: Fix memory leaks in error paths in krping. Message-ID: <202101221248.10MCmX1h019822@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/11 has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=8302e83a1c4e9afb22afc839bb86a76f9e3dacbb commit 8302e83a1c4e9afb22afc839bb86a76f9e3dacbb Author: Hans Petter Selasky <hselasky@FreeBSD.org> AuthorDate: 2021-01-08 11:22:18 +0000 Commit: Hans Petter Selasky <hselasky@FreeBSD.org> CommitDate: 2021-01-22 12:31:41 +0000 MFC 376e130b4707: Fix memory leaks in error paths in krping. Sponsored by: Mellanox Technologies // NVIDIA Networking --- sys/contrib/rdma/krping/krping.c | 52 ++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/sys/contrib/rdma/krping/krping.c b/sys/contrib/rdma/krping/krping.c index c734da36247f..46fa23f3a5e6 100644 --- a/sys/contrib/rdma/krping/krping.c +++ b/sys/contrib/rdma/krping/krping.c @@ -993,9 +993,11 @@ static void wlat_test(struct krping_cb *cb) volatile char *poll_buf = (char *) cb->start_buf; char *buf = (char *)cb->rdma_buf; struct timeval start_tv, stop_tv; - cycles_t *post_cycles_start, *post_cycles_stop; - cycles_t *poll_cycles_start, *poll_cycles_stop; - cycles_t *last_poll_cycles_start; + cycles_t *post_cycles_start = NULL; + cycles_t *post_cycles_stop = NULL; + cycles_t *poll_cycles_start = NULL; + cycles_t *poll_cycles_stop = NULL; + cycles_t *last_poll_cycles_start = NULL; cycles_t sum_poll = 0, sum_post = 0, sum_last_poll = 0; int i; int cycle_iters = 1000; @@ -1007,28 +1009,28 @@ static void wlat_test(struct krping_cb *cb) post_cycles_start = kmalloc(cycle_iters * sizeof(cycles_t), GFP_KERNEL); if (!post_cycles_start) { printk(KERN_ERR PFX "%s kmalloc failed\n", __FUNCTION__); - return; + goto done; } post_cycles_stop = kmalloc(cycle_iters * sizeof(cycles_t), GFP_KERNEL); if (!post_cycles_stop) { printk(KERN_ERR PFX "%s kmalloc failed\n", __FUNCTION__); - return; + goto done; } poll_cycles_start = kmalloc(cycle_iters * sizeof(cycles_t), GFP_KERNEL); if (!poll_cycles_start) { printk(KERN_ERR PFX "%s kmalloc failed\n", __FUNCTION__); - return; + goto done; } poll_cycles_stop = kmalloc(cycle_iters * sizeof(cycles_t), GFP_KERNEL); if (!poll_cycles_stop) { printk(KERN_ERR PFX "%s kmalloc failed\n", __FUNCTION__); - return; + goto done; } last_poll_cycles_start = kmalloc(cycle_iters * sizeof(cycles_t), GFP_KERNEL); if (!last_poll_cycles_start) { printk(KERN_ERR PFX "%s kmalloc failed\n", __FUNCTION__); - return; + goto done; } cb->rdma_sq_wr.wr.opcode = IB_WR_RDMA_WRITE; cb->rdma_sq_wr.rkey = cb->remote_rkey; @@ -1047,7 +1049,7 @@ static void wlat_test(struct krping_cb *cb) if (cb->state == ERROR) { printk(KERN_ERR PFX "state = ERROR, bailing\n"); - return; + goto done; } } } @@ -1062,7 +1064,7 @@ static void wlat_test(struct krping_cb *cb) printk(KERN_ERR PFX "Couldn't post send: scnt=%d\n", scnt); - return; + goto done; } if (scnt < cycle_iters) post_cycles_stop[scnt] = get_cycles(); @@ -1087,7 +1089,7 @@ static void wlat_test(struct krping_cb *cb) if (ne < 0) { printk(KERN_ERR PFX "poll CQ failed %d\n", ne); - return; + goto done; } if (wc.status != IB_WC_SUCCESS) { printk(KERN_ERR PFX @@ -1099,7 +1101,7 @@ static void wlat_test(struct krping_cb *cb) printk(KERN_ERR PFX "scnt=%d, rcnt=%d, ccnt=%d\n", scnt, rcnt, ccnt); - return; + goto done; } } } @@ -1123,6 +1125,7 @@ static void wlat_test(struct krping_cb *cb) scnt, cb->size, cycle_iters, (unsigned long long)sum_post, (unsigned long long)sum_poll, (unsigned long long)sum_last_poll); +done: kfree(post_cycles_start); kfree(post_cycles_stop); kfree(poll_cycles_start); @@ -1135,9 +1138,11 @@ static void bw_test(struct krping_cb *cb) int ccnt, scnt, rcnt; int iters=cb->count; struct timeval start_tv, stop_tv; - cycles_t *post_cycles_start, *post_cycles_stop; - cycles_t *poll_cycles_start, *poll_cycles_stop; - cycles_t *last_poll_cycles_start; + cycles_t *post_cycles_start = NULL; + cycles_t *post_cycles_stop = NULL; + cycles_t *poll_cycles_start = NULL; + cycles_t *poll_cycles_stop = NULL; + cycles_t *last_poll_cycles_start = NULL; cycles_t sum_poll = 0, sum_post = 0, sum_last_poll = 0; int i; int cycle_iters = 1000; @@ -1149,28 +1154,28 @@ static void bw_test(struct krping_cb *cb) post_cycles_start = kmalloc(cycle_iters * sizeof(cycles_t), GFP_KERNEL); if (!post_cycles_start) { printk(KERN_ERR PFX "%s kmalloc failed\n", __FUNCTION__); - return; + goto done; } post_cycles_stop = kmalloc(cycle_iters * sizeof(cycles_t), GFP_KERNEL); if (!post_cycles_stop) { printk(KERN_ERR PFX "%s kmalloc failed\n", __FUNCTION__); - return; + goto done; } poll_cycles_start = kmalloc(cycle_iters * sizeof(cycles_t), GFP_KERNEL); if (!poll_cycles_start) { printk(KERN_ERR PFX "%s kmalloc failed\n", __FUNCTION__); - return; + goto done; } poll_cycles_stop = kmalloc(cycle_iters * sizeof(cycles_t), GFP_KERNEL); if (!poll_cycles_stop) { printk(KERN_ERR PFX "%s kmalloc failed\n", __FUNCTION__); - return; + goto done; } last_poll_cycles_start = kmalloc(cycle_iters * sizeof(cycles_t), GFP_KERNEL); if (!last_poll_cycles_start) { printk(KERN_ERR PFX "%s kmalloc failed\n", __FUNCTION__); - return; + goto done; } cb->rdma_sq_wr.wr.opcode = IB_WR_RDMA_WRITE; cb->rdma_sq_wr.rkey = cb->remote_rkey; @@ -1191,7 +1196,7 @@ static void bw_test(struct krping_cb *cb) printk(KERN_ERR PFX "Couldn't post send: scnt=%d\n", scnt); - return; + goto done; } if (scnt < cycle_iters) post_cycles_stop[scnt] = get_cycles(); @@ -1216,7 +1221,7 @@ static void bw_test(struct krping_cb *cb) if (ne < 0) { printk(KERN_ERR PFX "poll CQ failed %d\n", ne); - return; + goto done; } if (wc.status != IB_WC_SUCCESS) { printk(KERN_ERR PFX @@ -1225,7 +1230,7 @@ static void bw_test(struct krping_cb *cb) printk(KERN_ERR PFX "Failed status %d: wr_id %d\n", wc.status, (int) wc.wr_id); - return; + goto done; } } } @@ -1249,6 +1254,7 @@ static void bw_test(struct krping_cb *cb) scnt, cb->size, cycle_iters, (unsigned long long)sum_post, (unsigned long long)sum_poll, (unsigned long long)sum_last_poll); +done: kfree(post_cycles_start); kfree(post_cycles_stop); kfree(poll_cycles_start);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101221248.10MCmX1h019822>