diff mbox series

drm/etnaviv: Added error handling for dma_map_sgtable.

Message ID 20231126082514.1280691-1-listdansp@mail.ru (mailing list archive)
State New, archived
Headers show
Series drm/etnaviv: Added error handling for dma_map_sgtable. | expand

Commit Message

Danila Chernetsov Nov. 26, 2023, 8:25 a.m. UTC
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@mail.ru>
---
 drivers/gpu/drm/etnaviv/etnaviv_gem.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
diff mbox series

Patch

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;