Commit d4eb23a9 authored by Emil Goode's avatar Emil Goode Committed by Greg Kroah-Hartman

staging: drm/omap: Add error handling

This patch adds fail checks for kmalloc and kzalloc calls
and also adds a error path that frees allocated pages by
introducing a call to _drm_gem_put_pages.
Signed-off-by: default avatarEmil Goode <emilgoode@gmail.com>
Signed-off-by: default avatarRob Clark <rob@ti.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 79e3f028
...@@ -226,7 +226,8 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj) ...@@ -226,7 +226,8 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)
struct drm_device *dev = obj->dev; struct drm_device *dev = obj->dev;
struct omap_gem_object *omap_obj = to_omap_bo(obj); struct omap_gem_object *omap_obj = to_omap_bo(obj);
struct page **pages; struct page **pages;
int i, npages = obj->size >> PAGE_SHIFT; int npages = obj->size >> PAGE_SHIFT;
int i, ret;
dma_addr_t *addrs; dma_addr_t *addrs;
WARN_ON(omap_obj->pages); WARN_ON(omap_obj->pages);
...@@ -246,18 +247,32 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj) ...@@ -246,18 +247,32 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)
*/ */
if (omap_obj->flags & (OMAP_BO_WC|OMAP_BO_UNCACHED)) { if (omap_obj->flags & (OMAP_BO_WC|OMAP_BO_UNCACHED)) {
addrs = kmalloc(npages * sizeof(addrs), GFP_KERNEL); addrs = kmalloc(npages * sizeof(addrs), GFP_KERNEL);
if (!addrs) {
ret = -ENOMEM;
goto free_pages;
}
for (i = 0; i < npages; i++) { for (i = 0; i < npages; i++) {
addrs[i] = dma_map_page(dev->dev, pages[i], addrs[i] = dma_map_page(dev->dev, pages[i],
0, PAGE_SIZE, DMA_BIDIRECTIONAL); 0, PAGE_SIZE, DMA_BIDIRECTIONAL);
} }
} else { } else {
addrs = kzalloc(npages * sizeof(addrs), GFP_KERNEL); addrs = kzalloc(npages * sizeof(addrs), GFP_KERNEL);
if (!addrs) {
ret = -ENOMEM;
goto free_pages;
}
} }
omap_obj->addrs = addrs; omap_obj->addrs = addrs;
omap_obj->pages = pages; omap_obj->pages = pages;
return 0; return 0;
free_pages:
_drm_gem_put_pages(obj, pages, true, false);
return ret;
} }
/** release backing pages */ /** release backing pages */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment