]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nvme-pci: add missing condition check for existence of mapped data
authorLeon Romanovsky <leonro@nvidia.com>
Wed, 24 Jul 2024 10:31:14 +0000 (13:31 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 3 Aug 2024 07:01:08 +0000 (09:01 +0200)
[ Upstream commit c31fad1470389666ac7169fe43aa65bf5b7e2cfd ]

nvme_map_data() is called when request has physical segments, hence
the nvme_unmap_data() should have same condition to avoid dereference.

Fixes: 4aedb705437f ("nvme-pci: split metadata handling from nvme_map_data / nvme_unmap_data")
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Nitesh Shetty <nj.shetty@samsung.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/host/pci.c

index 9e9b05e79c474b2628d563477b2ca636a0e42398..5a93f021ca4f1d01add648a3bc63e6b291bc6ff9 100644 (file)
@@ -863,7 +863,8 @@ static blk_status_t nvme_prep_rq(struct nvme_dev *dev, struct request *req)
        nvme_start_request(req);
        return BLK_STS_OK;
 out_unmap_data:
-       nvme_unmap_data(dev, req);
+       if (blk_rq_nr_phys_segments(req))
+               nvme_unmap_data(dev, req);
 out_free_cmd:
        nvme_cleanup_cmd(req);
        return ret;