lib/nvme: add value check to fix value inversion

When payload_size is 0, we may get wrong cdw10 because of the calculate: 0 - 1,
add value check to fix value inversion bug.

Signed-off-by: sunshihao <sunshihao@huawei.com>
Change-Id: I3bcd38ba981c854ff917282341d32aac47d22b76
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7443
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: <dongx.yi@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
sunshihao520 2021-04-16 17:19:31 +08:00 committed by Tomasz Zawadzki
parent 32999ab917
commit 2fc1ccae77

View File

@ -988,7 +988,9 @@ nvme_ctrlr_cmd_directive(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
cmd->opc = opc_type;
cmd->nsid = nsid;
cmd->cdw10 = (payload_size >> 2) - 1;
if ((payload_size >> 2) > 0) {
cmd->cdw10 = (payload_size >> 2) - 1;
}
cmd->cdw11_bits.directive.doper = doper;
cmd->cdw11_bits.directive.dtype = dtype;
cmd->cdw11_bits.directive.dspec = dspec;