OSDN Git Service

hw/block/nvme: fix ref counting in nvme_format_ns
authorKlaus Jensen <k.jensen@samsung.com>
Mon, 22 Mar 2021 06:10:24 +0000 (07:10 +0100)
committerKlaus Jensen <k.jensen@samsung.com>
Mon, 29 Mar 2021 16:46:57 +0000 (18:46 +0200)
commit3a69cadbef7af23a566dbe2400043c247c3d50ca
tree2ea05b5ce90d74660e56869abb4f1548d04b981b
parent9561353ddc35215141adf181d4d8f6f0d9655cc0
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: dc04d25e2f3f ("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>
hw/block/nvme.c