Date: Fri, 22 Jan 2021 12:30:22 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: b195e1730e51 - stable/12 - MFC 376e130b4707: Fix memory leaks in error paths in krping. Message-ID: <202101221230.10MCUMPD000683@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=b195e1730e517cd5b43f6174efdda183163d9feb commit b195e1730e517cd5b43f6174efdda183163d9feb 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:08:42 +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 e9a379984dec..75c874411bb3 100644 --- a/sys/contrib/rdma/krping/krping.c +++ b/sys/contrib/rdma/krping/krping.c @@ -992,9 +992,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; @@ -1006,28 +1008,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; @@ -1046,7 +1048,7 @@ static void wlat_test(struct krping_cb *cb) if (cb->state == ERROR) { printk(KERN_ERR PFX "state = ERROR, bailing\n"); - return; + goto done; } } } @@ -1061,7 +1063,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(); @@ -1086,7 +1088,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 @@ -1098,7 +1100,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; } } } @@ -1122,6 +1124,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); @@ -1134,9 +1137,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; @@ -1148,28 +1153,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; @@ -1190,7 +1195,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(); @@ -1215,7 +1220,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 @@ -1224,7 +1229,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; } } } @@ -1248,6 +1253,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?202101221230.10MCUMPD000683>