]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
drm/omap: use dma_mapping_error in omap_gem_attach_pages
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Tue, 5 Jan 2016 09:43:14 +0000 (11:43 +0200)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Thu, 3 Mar 2016 15:36:41 +0000 (17:36 +0200)
omap_gem_attach_pages() calls dma_map_page() but does not check the
possible error with dma_mapping_error(). If DMA-API debugging is
enabled, the debug layer will give a warning if dma_mapping_error() has
not been used.

This patch adds proper error handling to omap_gem_attach_pages().

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
drivers/gpu/drm/omapdrm/omap_gem.c

index 8495a1a4b61745524dd04045616d859b2ac566bb..cb541d6b3c2bec46719c5d03399e2fbfb9f42d52 100644 (file)
@@ -264,6 +264,19 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)
                for (i = 0; i < npages; i++) {
                        addrs[i] = dma_map_page(dev->dev, pages[i],
                                        0, PAGE_SIZE, DMA_BIDIRECTIONAL);
+
+                       if (dma_mapping_error(dev->dev, addrs[i])) {
+                               dev_warn(dev->dev,
+                                       "%s: failed to map page\n", __func__);
+
+                               for (i = i - 1; i >= 0; --i) {
+                                       dma_unmap_page(dev->dev, addrs[i],
+                                               PAGE_SIZE, DMA_BIDIRECTIONAL);
+                               }
+
+                               ret = -ENOMEM;
+                               goto free_addrs;
+                       }
                }
        } else {
                addrs = kzalloc(npages * sizeof(*addrs), GFP_KERNEL);
@@ -278,6 +291,8 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)
 
        return 0;
 
+free_addrs:
+       kfree(addrs);
 free_pages:
        drm_gem_put_pages(obj, pages, true, false);