Skip to content

Commit 3a69cad

Browse files
committed
hw/block/nvme: fix ref counting in nvme_format_ns
Max noticed that since blk_aio_pwrite_zeroes() may invoke the callback before returning, the callbacks will never see *count == 0 and thus never free the count variable or decrement num_formats causing a CQE to never be posted. Coverity (CID 1451082) also picked up on the fact that count would not be free'ed if the namespace was of zero size. Fix both of these issues by explicitly checking *count and finalize for the given namespace if --(*count) is zero. Enqueing a CQE if there are no AIOs outstanding after this case is already handled by nvme_format() by inspecting *num_formats. Reported-by: Max Reitz <mreitz@redhat.com> Reported-by: Coverity (CID 1451082) Fixes: dc04d25 ("hw/block/nvme: add support for the format nvm command") Signed-off-by: Klaus Jensen <k.jensen@samsung.com> Reviewed-by: Gollu Appalanaidu <anaidu.gollu@samsung.com>
1 parent 9561353 commit 3a69cad

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

hw/block/nvme.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5009,9 +5009,15 @@ static uint16_t nvme_format_ns(NvmeCtrl *n, NvmeNamespace *ns, uint8_t lbaf,
50095009

50105010
}
50115011

5012-
(*count)--;
5012+
if (--(*count)) {
5013+
return NVME_NO_COMPLETE;
5014+
}
50135015

5014-
return NVME_NO_COMPLETE;
5016+
g_free(count);
5017+
ns->status = 0x0;
5018+
(*num_formats)--;
5019+
5020+
return NVME_SUCCESS;
50155021
}
50165022

50175023
static uint16_t nvme_format(NvmeCtrl *n, NvmeRequest *req)

0 commit comments

Comments
 (0)