Module Name:    src
Committed By:   riastradh
Date:           Sun Dec 19 12:13:45 UTC 2021

Modified Files:
        src/sys/external/bsd/drm2/linux: linux_dma_fence.c

Log Message:
drm: dma_fence_get allows fence to be null; fix assertion.

While here, update comments about semantics for dma_fence_get and
dma_fence_get_rcu (which does not allow null fence).


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/external/bsd/drm2/linux/linux_dma_fence.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/linux/linux_dma_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.25 src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.26
--- src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.25	Sun Dec 19 12:11:05 2021
+++ src/sys/external/bsd/drm2/linux/linux_dma_fence.c	Sun Dec 19 12:13:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_dma_fence.c,v 1.25 2021/12/19 12:11:05 riastradh Exp $	*/
+/*	$NetBSD: linux_dma_fence.c,v 1.26 2021/12/19 12:13:45 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.25 2021/12/19 12:11:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.26 2021/12/19 12:13:45 riastradh Exp $");
 
 #include <sys/atomic.h>
 #include <sys/condvar.h>
@@ -246,18 +246,21 @@ dma_fence_get_stub(void)
 /*
  * dma_fence_get(fence)
  *
- *	Acquire a reference to fence.  The fence must not be being
- *	destroyed.  Return the fence.
+ *	Acquire a reference to fence and return it, or return NULL if
+ *	fence is NULL.  The fence, if nonnull, must not be being
+ *	destroyed.
  */
 struct dma_fence *
 dma_fence_get(struct dma_fence *fence)
 {
 
+	if (fence == NULL)
+		return NULL;
+
 	KASSERTMSG(fence->f_magic != FENCE_MAGIC_BAD, "fence %p", fence);
 	KASSERTMSG(fence->f_magic == FENCE_MAGIC_GOOD, "fence %p", fence);
 
-	if (fence)
-		kref_get(&fence->refcount);
+	kref_get(&fence->refcount);
 	return fence;
 }
 
@@ -266,7 +269,7 @@ dma_fence_get(struct dma_fence *fence)
  *
  *	Attempt to acquire a reference to a fence that may be about to
  *	be destroyed, during a read section.  Return the fence on
- *	success, or NULL on failure.
+ *	success, or NULL on failure.  The fence must be nonnull.
  */
 struct dma_fence *
 dma_fence_get_rcu(struct dma_fence *fence)

Reply via email to