Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6808c5fb authored by Santosh Y's avatar Santosh Y Committed by Matthew Wilcox
Browse files

NVMe: Prevent possible NULL pointer dereference



kmalloc() used by the nvme_alloc_iod() to allocate memory for 'iod'
can fail. So check the return value.

Signed-off-by: default avatarSantosh Y <santosh.sy@samsung.com>
Signed-off-by: default avatarMatthew Wilcox <matthew.r.wilcox@intel.com>
parent 4131f2fc
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -1488,7 +1488,11 @@ struct nvme_iod *nvme_map_user_pages(struct nvme_dev *dev, int write,
		goto put_pages;
		goto put_pages;
	}
	}


	err = -ENOMEM;
	iod = nvme_alloc_iod(count, length, GFP_KERNEL);
	iod = nvme_alloc_iod(count, length, GFP_KERNEL);
	if (!iod)
		goto put_pages;

	sg = iod->sg;
	sg = iod->sg;
	sg_init_table(sg, count);
	sg_init_table(sg, count);
	for (i = 0; i < count; i++) {
	for (i = 0; i < count; i++) {
@@ -1501,7 +1505,6 @@ struct nvme_iod *nvme_map_user_pages(struct nvme_dev *dev, int write,
	sg_mark_end(&sg[i - 1]);
	sg_mark_end(&sg[i - 1]);
	iod->nents = count;
	iod->nents = count;


	err = -ENOMEM;
	nents = dma_map_sg(&dev->pci_dev->dev, sg, count,
	nents = dma_map_sg(&dev->pci_dev->dev, sg, count,
				write ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
				write ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
	if (!nents)
	if (!nents)