[PATCH] dma-buf: handle NULL src_list in reservation_object_copy_fences

Christian König deathsimple at vodafone.de
Thu Aug 10 13:41:35 UTC 2017


From: Christian König <christian.koenig at amd.com>

The list of shared fences can be NULL and that needs to be handled as well.

Signed-off-by: Christian König <christian.koenig at amd.com>
---
 drivers/dma-buf/reservation.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
index 302c137..dec3a81 100644
--- a/drivers/dma-buf/reservation.c
+++ b/drivers/dma-buf/reservation.c
@@ -279,23 +279,25 @@ int reservation_object_copy_fences(struct reservation_object *dst,
 
 	src_list = reservation_object_get_list(src);
 
-	/*
-	 * resize dst->fence or allocate if it doesn't exist,
-	 * noop if already correct size
-	 */
-	size = offsetof(typeof(*src_list), shared[src_list->shared_count]);
-	dst_list = kmalloc(size, GFP_KERNEL);
-	if (!dst_list)
-		return -ENOMEM;
+	if (src_list) {
+		size = offsetof(typeof(*src_list),
+				shared[src_list->shared_count]);
+		dst_list = kmalloc(size, GFP_KERNEL);
+		if (!dst_list)
+			return -ENOMEM;
+
+		dst_list->shared_count = src_list->shared_count;
+		dst_list->shared_max = src_list->shared_count;
+		for (i = 0; i < src_list->shared_count; ++i)
+			dst_list->shared[i] =
+				dma_fence_get(src_list->shared[i]);
+	} else {
+		dst_list = NULL;
+	}
 
 	kfree(dst->staged);
 	dst->staged = NULL;
 
-	dst_list->shared_count = src_list->shared_count;
-	dst_list->shared_max = src_list->shared_count;
-	for (i = 0; i < src_list->shared_count; ++i)
-		dst_list->shared[i] = dma_fence_get(src_list->shared[i]);
-
 	src_list = reservation_object_get_list(dst);
 
 	old = reservation_object_get_excl(dst);
-- 
2.7.4



More information about the amd-gfx mailing list