From 1f3bd08fa03c1dd28faf88552e6735cd8b70e47f Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Tue, 31 May 2022 15:43:54 +0200 Subject: [PATCH] nvme/tcp: check tcp_req for NULL in pdu_payload_handle For a C2HTermReq PDU, there's no associated tcp_req, so we need to check it for NULL before dereferencing it. Also, while here, moved some of the assignments to the declarations to reduce the number of boilerplate lines. Signed-off-by: Konrad Sztyber Change-Id: Iac05ef0ba605e2f40d0026ad1b131c28d29f7314 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12845 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk --- lib/nvme/nvme_tcp.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/nvme/nvme_tcp.c b/lib/nvme/nvme_tcp.c index d1d35e9b6..34f18be31 100644 --- a/lib/nvme/nvme_tcp.c +++ b/lib/nvme/nvme_tcp.c @@ -1126,22 +1126,23 @@ nvme_tcp_pdu_payload_handle(struct nvme_tcp_qpair *tqpair, uint32_t *reaped) { int rc = 0; - struct nvme_tcp_pdu *pdu; + struct nvme_tcp_pdu *pdu = tqpair->recv_pdu; uint32_t crc32c; struct nvme_tcp_poll_group *tgroup; - struct nvme_tcp_req *tcp_req; + struct nvme_tcp_req *tcp_req = pdu->req; assert(tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD); - pdu = tqpair->recv_pdu; - SPDK_DEBUGLOG(nvme, "enter\n"); - tcp_req = pdu->req; - /* Increase the expected data offset */ - tcp_req->expected_datao += pdu->data_len; + /* The request can be NULL, e.g. in case of C2HTermReq */ + if (spdk_likely(tcp_req != NULL)) { + tcp_req->expected_datao += pdu->data_len; + } /* check data digest if need */ if (pdu->ddgst_enable) { + /* But if the data digest is enabled, tcp_req cannot be NULL */ + assert(tcp_req != NULL); tgroup = nvme_tcp_poll_group(tqpair->qpair.poll_group); /* Only suport this limitated case for the first step */ if ((nvme_qpair_get_state(&tqpair->qpair) >= NVME_QPAIR_CONNECTED) &&