Skip to content

Commit

Permalink
NVMe: Prevent possible NULL pointer dereference
Browse files Browse the repository at this point in the history
kmalloc() used by the nvme_alloc_iod() to allocate memory for 'iod'
can fail. So check the return value.

Signed-off-by: Santosh Y <santosh.sy@samsung.com>
Signed-off-by: Matthew Wilcox <matthew.r.wilcox@intel.com>
  • Loading branch information
Santosh Y authored and Matthew Wilcox committed Jun 3, 2014
1 parent 4131f2f commit 6808c5f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/block/nvme-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,11 @@ struct nvme_iod *nvme_map_user_pages(struct nvme_dev *dev, int write,
goto put_pages;
}

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

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

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

0 comments on commit 6808c5f

Please sign in to comment.