Skip to contentSkip to conversation

dma-buf: handle NULL src_list in reservation_object_copy_fences

PATCH In review Christian König 3 participants 4 messages Aug 10, 2017 DMA buffer sharing framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-buf: handle NULL src_list in reservation_object_copy_fences

From: Christian König <[email protected]>

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

---
 drivers/dma-buf/reservation.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)
drivers/dma-buf/reservation.c +15 -13
index 302c137..dec3a81 100644
@@ -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);
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Christian König
Sent: Thursday, August 10, 2017 9:42 AM
To: [email protected]; [email protected]
Subject: [PATCH] dma-buf: handle NULL src_list in reservation_object_copy_fences

Quoted 5 lines

From: Christian König <[email protected]>

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

I'll squash this with the original patch for upstream.

Quoted 51 lines
---
 drivers/dma-buf/reservation.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)
drivers/dma-buf/reservation.c +15 -13
index 302c137..dec3a81 100644
@@ -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

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

Am 10.08.2017 um 16:40 schrieb Deucher, Alexander:

Quoted 8 lines
Quoted 8 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Christian König
Sent: Thursday, August 10, 2017 9:42 AM
To: [email protected]; [email protected]
Subject: [PATCH] dma-buf: handle NULL src_list in reservation_object_copy_fences

Quoted 8 lines
Quoted 5 lines

From: Christian König <[email protected]>

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

I'll squash this with the original patch for upstream.

Please note that I haven't tested this very well. You really need a prime setup for testing and that's not on my desk right now.

So please ping whoever reported that problem to retest.

Thanks,
Christian.

Quoted 52 lines
Quoted 52 lines
---
  drivers/dma-buf/reservation.c | 28 +++++++++++++++-------------
  1 file changed, 15 insertions(+), 13 deletions(-)
drivers/dma-buf/reservation.c +15 -13
index 302c137..dec3a81 100644
@@ -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

Quoted 8 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 24 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Thursday, August 10, 2017 10:44 AM
To: Deucher, Alexander; [email protected]; dri- [email protected]
Subject: Re: [PATCH] dma-buf: handle NULL src_list in reservation_object_copy_fences

Am 10.08.2017 um 16:40 schrieb Deucher, Alexander:

Quoted 2 lines
Quoted 2 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On

Behalf

Quoted 9 lines
Quoted 9 lines

Of Christian König
Sent: Thursday, August 10, 2017 9:42 AM
To: [email protected]; [email protected]
Subject: [PATCH] dma-buf: handle NULL src_list in reservation_object_copy_fences

From: Christian König <[email protected]>

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

well.

Quoted 2 lines
Quoted 2 lines
Quoted 8 lines
Quoted 3 lines

I'll squash this with the original patch for upstream.

Please note that I haven't tested this very well. You really need a prime setup for testing and that's not on my desk right now.

So please ping whoever reported that problem to retest.

FWIW, the issue was reported on a single card.

Alex

Quoted 5 lines

Thanks,
Christian.

Quoted 1 line
Quoted 61 lines
Quoted 5 lines

drivers/dma-

Quoted 5 lines
---
  drivers/dma-buf/reservation.c | 28 +++++++++++++++-------------
  1 file changed, 15 insertions(+), 13 deletions(-)
drivers/dma- renamed from drivers/dma-buf/reservation.c +0 -0

buf/reservation.c

Quoted 54 lines
Quoted 46 lines

index 302c137..dec3a81 100644

drivers/dma-buf/reservation.c +15 -13
@@ -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

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel