diff options
author | Dmitry Tikhov | 2022-04-12 10:59:09 +0200 |
---|---|---|
committer | Klaus Jensen | 2022-06-03 21:48:24 +0200 |
commit | 1e64facc015e16d8e4efa239feaeda9e4e9aeb04 (patch) | |
tree | d0fc69fe0df895ba7fc7ef2dc4d4c58d2b912ca6 /hw/nvme | |
parent | Merge tag 'pull-request-2022-06-03' of https://gitlab.com/thuth/qemu into sta... (diff) | |
download | qemu-1e64facc015e16d8e4efa239feaeda9e4e9aeb04.tar.gz qemu-1e64facc015e16d8e4efa239feaeda9e4e9aeb04.tar.xz qemu-1e64facc015e16d8e4efa239feaeda9e4e9aeb04.zip |
hw/nvme: fix narrowing conversion
Since nlbas is of type int, it does not work with large namespace size
values, e.g., 9 TB size of file backing namespace and 8 byte metadata
with 4096 bytes lbasz gives negative nlbas value, which is later
promoted to negative int64_t type value and results in negative
ns->moff which breaks namespace
Signed-off-by: Dmitry Tikhov <ddtikhov@gmail.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Diffstat (limited to 'hw/nvme')
-rw-r--r-- | hw/nvme/ns.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c index 324f53ea0c..af6504fad2 100644 --- a/hw/nvme/ns.c +++ b/hw/nvme/ns.c @@ -29,7 +29,8 @@ void nvme_ns_init_format(NvmeNamespace *ns) { NvmeIdNs *id_ns = &ns->id_ns; BlockDriverInfo bdi; - int npdg, nlbas, ret; + int npdg, ret; + int64_t nlbas; ns->lbaf = id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)]; ns->lbasz = 1 << ns->lbaf.ds; @@ -42,7 +43,7 @@ void nvme_ns_init_format(NvmeNamespace *ns) id_ns->ncap = id_ns->nsze; id_ns->nuse = id_ns->ncap; - ns->moff = (int64_t)nlbas << ns->lbaf.ds; + ns->moff = nlbas << ns->lbaf.ds; npdg = ns->blkconf.discard_granularity / ns->lbasz; |