dma-direct: don't crash on device without dma_mask
authorChristoph Hellwig <hch@lst.de>
Tue, 29 May 2018 14:15:12 +0000 (16:15 +0200)
committerChristoph Hellwig <hch@lst.de>
Thu, 31 May 2018 16:35:36 +0000 (18:35 +0200)
Print a useful warning instead.

Reported-by: Finn Thain <fthain@telegraphics.com.au>
Tested-by: Finn Thain <fthain@telegraphics.com.au>
Signed-off-by: Christoph Hellwig <hch@lst.de>
lib/dma-direct.c

index a48f94eff62eb411895bc52caca2d25a2eca764c..8be8106270c245ff299c5ef50fcc5a6689ef896b 100644 (file)
@@ -34,6 +34,13 @@ check_addr(struct device *dev, dma_addr_t dma_addr, size_t size,
                const char *caller)
 {
        if (unlikely(dev && !dma_capable(dev, dma_addr, size))) {
+               if (!dev->dma_mask) {
+                       dev_err(dev,
+                               "%s: call on device without dma_mask\n",
+                               caller);
+                       return false;
+               }
+
                if (*dev->dma_mask >= DMA_BIT_MASK(32)) {
                        dev_err(dev,
                                "%s: overflow %pad+%zu of device mask %llx\n",