From 30af49f77d2b9b72cf68291cb51459cbc9fad7ef Mon Sep 17 00:00:00 2001 From: Weiguo Li Date: Thu, 24 Feb 2022 01:21:59 +0800 Subject: [PATCH] nvmf: avoid a null dereference before null check We do the null check for 'fc_req', but already dereferenced it before the check. Swap their position to avoid null dereference. Fixes issue #2395. Signed-off-by: Weiguo Li Change-Id: I33b9e6b51b54f6ada9c072cf7ab0acda2622472f Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11721 Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Community-CI: Mellanox Build Bot --- lib/nvmf/fc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/nvmf/fc.c b/lib/nvmf/fc.c index 075b75995a..bd339c9ce3 100644 --- a/lib/nvmf/fc.c +++ b/lib/nvmf/fc.c @@ -1586,12 +1586,13 @@ nvmf_fc_hwqp_handle_request(struct spdk_nvmf_fc_hwqp *hwqp, struct spdk_nvmf_fc_ void _nvmf_fc_request_free(struct spdk_nvmf_fc_request *fc_req) { - struct spdk_nvmf_fc_hwqp *hwqp = fc_req->hwqp; + struct spdk_nvmf_fc_hwqp *hwqp; struct spdk_nvmf_transport_poll_group *group; if (!fc_req) { return; } + hwqp = fc_req->hwqp; if (fc_req->xchg) { nvmf_fc_put_xchg(hwqp, fc_req->xchg);