From 6a520ae6444d524e7ab7011cfe2efd235812a852 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Tue, 21 Dec 2021 23:32:30 +0000 Subject: [PATCH] nvme: simplify get_log_page_completion Return if outstanding_commands > 0. This reduces indentation for the rest of the code in the function and simplifies the diff for an upcoming patch. Signed-off-by: Jim Harris Change-Id: I49f09eff7c0908829819e6b797c922211c56e7db Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10812 Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Shuhei Matsumoto Reviewed-by: Changpeng Liu --- lib/nvme/nvme_discovery.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/nvme/nvme_discovery.c b/lib/nvme/nvme_discovery.c index 71917277f7..54896544a4 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