summaryrefslogtreecommitdiffstats
path: root/kernel/dma/mapping.c
diff options
context:
space:
mode:
authorThomas Tai <thomas.tai@oracle.com>2020-09-17 18:43:03 +0200
committerChristoph Hellwig <hch@lst.de>2020-09-17 18:43:20 +0200
commitf959dcd6ddfd29235030e8026471ac1b022ad2b0 (patch)
treeb3bb71e9171c97f693240bdeb3e9ad2f0a5d580c /kernel/dma/mapping.c
parenta92df4f62fda02e6b141e2b0bb52ccc486264b1c (diff)
downloadlinux-f959dcd6ddfd29235030e8026471ac1b022ad2b0.tar.gz
linux-f959dcd6ddfd29235030e8026471ac1b022ad2b0.tar.bz2
linux-f959dcd6ddfd29235030e8026471ac1b022ad2b0.zip
dma-direct: Fix potential NULL pointer dereference
When booting the kernel v5.9-rc4 on a VM, the kernel would panic when printing a warning message in swiotlb_map(). The dev->dma_mask must not be a NULL pointer when calling the dma mapping layer. A NULL pointer check can potentially avoid the panic. Signed-off-by: Thomas Tai <thomas.tai@oracle.com> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'kernel/dma/mapping.c')
-rw-r--r--kernel/dma/mapping.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index 848c95c27d79..9a045e51df17 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -144,6 +144,10 @@ dma_addr_t dma_map_page_attrs(struct device *dev, struct page *page,
dma_addr_t addr;
BUG_ON(!valid_dma_direction(dir));
+
+ if (WARN_ON_ONCE(!dev->dma_mask))
+ return DMA_MAPPING_ERROR;
+
if (dma_map_direct(dev, ops))
addr = dma_direct_map_page(dev, page, offset, size, dir, attrs);
else
@@ -179,6 +183,10 @@ int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg, int nents,
int ents;
BUG_ON(!valid_dma_direction(dir));
+
+ if (WARN_ON_ONCE(!dev->dma_mask))
+ return 0;
+
if (dma_map_direct(dev, ops))
ents = dma_direct_map_sg(dev, sg, nents, dir, attrs);
else
@@ -213,6 +221,9 @@ dma_addr_t dma_map_resource(struct device *dev, phys_addr_t phys_addr,
BUG_ON(!valid_dma_direction(dir));
+ if (WARN_ON_ONCE(!dev->dma_mask))
+ return DMA_MAPPING_ERROR;
+
/* Don't allow RAM to be mapped */
if (WARN_ON_ONCE(pfn_valid(PHYS_PFN(phys_addr))))
return DMA_MAPPING_ERROR;