[PATCH] drm/etnaviv: Added error handling for dma_map_sgtable.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Added error handling for dma_map_sgtable.
If an error occurs, the sgt table is freed.

Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.

Fixes: 182354a526a0 ("drm: etnaviv: fix common struct sg_table related issues")
Signed-off-by: Danila Chernetsov <listdansp@xxxxxxx>
---
 drivers/gpu/drm/etnaviv/etnaviv_gem.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
index b5f73502e3dd..59d1684dafc4 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
@@ -17,7 +17,7 @@
 static struct lock_class_key etnaviv_shm_lock_class;
 static struct lock_class_key etnaviv_userptr_lock_class;
 
-static void etnaviv_gem_scatter_map(struct etnaviv_gem_object *etnaviv_obj)
+static int etnaviv_gem_scatter_map(struct etnaviv_gem_object *etnaviv_obj)
 {
 	struct drm_device *dev = etnaviv_obj->base.dev;
 	struct sg_table *sgt = etnaviv_obj->sgt;
@@ -27,7 +27,9 @@ static void etnaviv_gem_scatter_map(struct etnaviv_gem_object *etnaviv_obj)
 	 * because display controller, GPU, etc. are not coherent.
 	 */
 	if (etnaviv_obj->flags & ETNA_BO_CACHE_MASK)
-		dma_map_sgtable(dev->dev, sgt, DMA_BIDIRECTIONAL, 0);
+		return dma_map_sgtable(dev->dev, sgt, DMA_BIDIRECTIONAL, 0);
+
+	return 0;
 }
 
 static void etnaviv_gem_scatterlist_unmap(struct etnaviv_gem_object *etnaviv_obj)
@@ -113,7 +115,13 @@ struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *etnaviv_obj)
 
 		etnaviv_obj->sgt = sgt;
 
-		etnaviv_gem_scatter_map(etnaviv_obj);
+		ret = etnaviv_gem_scatter_map(etnaviv_obj);
+		if (ret < 0) {
+			sg_free_table(etnaviv_obj->sgt);
+			kfree(etnaviv_obj->sgt);
+			etnaviv_obj->sgt = NULL;
+			return ERR_PTR(ret);
+		}
 	}
 
 	return etnaviv_obj->pages;
-- 
2.25.1




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux