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 <konrad.sztyber@intel.com>
Change-Id: Iac05ef0ba605e2f40d0026ad1b131c28d29f7314
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12845
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
This commit is contained in:
Konrad Sztyber 2022-05-31 15:43:54 +02:00 committed by Tomasz Zawadzki
parent 14adf7f70f
commit 1f3bd08fa0

View File

@ -1126,22 +1126,23 @@ nvme_tcp_pdu_payload_handle(struct nvme_tcp_qpair *tqpair,
uint32_t *reaped) uint32_t *reaped)
{ {
int rc = 0; int rc = 0;
struct nvme_tcp_pdu *pdu; struct nvme_tcp_pdu *pdu = tqpair->recv_pdu;
uint32_t crc32c; uint32_t crc32c;
struct nvme_tcp_poll_group *tgroup; 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); assert(tqpair->recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
pdu = tqpair->recv_pdu;
SPDK_DEBUGLOG(nvme, "enter\n"); SPDK_DEBUGLOG(nvme, "enter\n");
tcp_req = pdu->req; /* The request can be NULL, e.g. in case of C2HTermReq */
/* Increase the expected data offset */ if (spdk_likely(tcp_req != NULL)) {
tcp_req->expected_datao += pdu->data_len; tcp_req->expected_datao += pdu->data_len;
}
/* check data digest if need */ /* check data digest if need */
if (pdu->ddgst_enable) { 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); tgroup = nvme_tcp_poll_group(tqpair->qpair.poll_group);
/* Only suport this limitated case for the first step */ /* Only suport this limitated case for the first step */
if ((nvme_qpair_get_state(&tqpair->qpair) >= NVME_QPAIR_CONNECTED) && if ((nvme_qpair_get_state(&tqpair->qpair) >= NVME_QPAIR_CONNECTED) &&