rc_pingpong: Move buffer allocation after PD setup In preparation for the follow-up patch, move ctx->buf allocation later in pp_init_ctx(). Signed-off-by: Jiri Pirko <jiri@nvidia.com>
diff --git a/libibverbs/examples/rc_pingpong.c b/libibverbs/examples/rc_pingpong.c index 9781c4f..c6b0526 100644 --- a/libibverbs/examples/rc_pingpong.c +++ b/libibverbs/examples/rc_pingpong.c
@@ -344,20 +344,11 @@ ctx->send_flags = IBV_SEND_SIGNALED; ctx->rx_depth = rx_depth; - ctx->buf = memalign(page_size, size); - if (!ctx->buf) { - fprintf(stderr, "Couldn't allocate work buf.\n"); - goto clean_ctx; - } - - /* FIXME memset(ctx->buf, 0, size); */ - memset(ctx->buf, 0x7b, size); - ctx->context = ibv_open_device(ib_dev); if (!ctx->context) { fprintf(stderr, "Couldn't get context for %s\n", ibv_get_device_name(ib_dev)); - goto clean_buffer; + goto clean_ctx; } if (use_event) { @@ -431,6 +422,15 @@ } } + ctx->buf = memalign(page_size, size); + if (!ctx->buf) { + fprintf(stderr, "Couldn't allocate work buf.\n"); + goto clean_dm; + } + + /* FIXME memset(ctx->buf, 0, size); */ + memset(ctx->buf, 0x7b, size); + if (implicit_odp) { ctx->mr = ibv_reg_mr(ctx->pd, NULL, SIZE_MAX, access_flags); } else { @@ -441,7 +441,7 @@ if (!ctx->mr) { fprintf(stderr, "Couldn't register MR\n"); - goto clean_dm; + goto clean_buffer; } if (prefetch_mr) { @@ -557,6 +557,9 @@ clean_mr: ibv_dereg_mr(ctx->mr); +clean_buffer: + free(ctx->buf); + clean_dm: if (ctx->dm) ibv_free_dm(ctx->dm); @@ -571,9 +574,6 @@ clean_device: ibv_close_device(ctx->context); -clean_buffer: - free(ctx->buf); - clean_ctx: free(ctx); @@ -597,6 +597,8 @@ return 1; } + free(ctx->buf); + if (ctx->dm) { if (ibv_free_dm(ctx->dm)) { fprintf(stderr, "Couldn't free DM\n"); @@ -621,7 +623,6 @@ return 1; } - free(ctx->buf); free(ctx); return 0;