Module Name:    src
Committed By:   riastradh
Date:           Mon Aug 27 14:13:46 UTC 2018

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

Log Message:
There may not be an old list.

Nihil ex nihilo -- don't dereference null.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/linux/linux_reservation.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_reservation.c
diff -u src/sys/external/bsd/drm2/linux/linux_reservation.c:1.5 src/sys/external/bsd/drm2/linux/linux_reservation.c:1.6
--- src/sys/external/bsd/drm2/linux/linux_reservation.c:1.5	Mon Aug 27 14:13:00 2018
+++ src/sys/external/bsd/drm2/linux/linux_reservation.c	Mon Aug 27 14:13:46 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_reservation.c,v 1.5 2018/08/27 14:13:00 riastradh Exp $	*/
+/*	$NetBSD: linux_reservation.c,v 1.6 2018/08/27 14:13:46 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.5 2018/08/27 14:13:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.6 2018/08/27 14:13:46 riastradh Exp $");
 
 #include <linux/fence.h>
 #include <linux/reservation.h>
@@ -411,13 +411,15 @@ reservation_object_add_shared_fence(stru
 		/* Commit the update.  */
 		reservation_object_write_commit(robj, &ticket);
 	} else {
-		KASSERT(list->shared_count < prealloc->shared_max);
+		uint32_t shared_count = (list == NULL? 0 : list->shared_count);
+
+		KASSERT(shared_count < prealloc->shared_max);
 
 		/*
 		 * Copy the fences over, but replace if we find one
 		 * with the same context number.
 		 */
-		for (i = 0; i < list->shared_count; i++) {
+		for (i = 0; i < shared_count; i++) {
 			if (replace == NULL &&
 			    list->shared[i]->context == fence->context) {
 				replace = list->shared[i];
@@ -426,7 +428,7 @@ reservation_object_add_shared_fence(stru
 				prealloc->shared[i] = list->shared[i];
 			}
 		}
-		prealloc->shared_count = list->shared_count;
+		prealloc->shared_count = shared_count;
 
 		/* If we didn't find one, add it at the end.  */
 		if (replace == NULL)
@@ -443,11 +445,12 @@ reservation_object_add_shared_fence(stru
 		reservation_object_write_commit(robj, &ticket);
 
 		/*
-		 * Free the old list when it is convenient.  (We are
-		 * not in a position at this point to sleep waiting for
-		 * activity on all CPUs.)
+		 * If there is an old list, free it when convenient.
+		 * (We are not in a position at this point to sleep
+		 * waiting for activity on all CPUs.)
 		 */
-		objlist_defer_free(list);
+		if (list != NULL)
+			objlist_defer_free(list);
 	}
 
 	/* Release a fence if we replaced it.  */

Reply via email to