diff --git a/lib/nvme/nvme_discovery.c b/lib/nvme/nvme_discovery.c index 71917277f..54896544a 100644 --- a/lib/nvme/nvme_discovery.c +++ b/lib/nvme/nvme_discovery.c @@ -48,6 +48,7 @@ static void get_log_page_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl) { struct nvme_discovery_ctx *ctx = cb_arg; + struct spdk_nvmf_discovery_log_page *log_page; if (spdk_nvme_cpl_is_error(cpl)) { /* Only save the cpl for the first error that we encounter. */ @@ -56,20 +57,20 @@ get_log_page_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl) } } ctx->outstanding_commands--; - if (ctx->outstanding_commands == 0) { - struct spdk_nvmf_discovery_log_page *log_page; - - if (!spdk_nvme_cpl_is_error(&ctx->cpl)) { - log_page = ctx->log_page; - } else { - /* We had an error, so don't return the log page to the caller. */ - log_page = NULL; - free(ctx->log_page); - } - - ctx->cb_fn(ctx->cb_arg, 0, &ctx->cpl, log_page); - free(ctx); + if (ctx->outstanding_commands > 0) { + return; } + + if (!spdk_nvme_cpl_is_error(&ctx->cpl)) { + log_page = ctx->log_page; + } else { + /* We had an error, so don't return the log page to the caller. */ + log_page = NULL; + free(ctx->log_page); + } + + ctx->cb_fn(ctx->cb_arg, 0, &ctx->cpl, log_page); + free(ctx); } static void