Module Name:    src
Committed By:   riastradh
Date:           Wed Jul 24 03:02:21 UTC 2013

Modified Files:
        src/sys/external/bsd/drm2/drm [riastradh-drm2]: drm_memory.c

Log Message:
Fix sense of refcount decrement conditional in drm_iounmap.

Add some kasserts just in case.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 src/sys/external/bsd/drm2/drm/drm_memory.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/drm/drm_memory.c
diff -u src/sys/external/bsd/drm2/drm/drm_memory.c:1.1.2.4 src/sys/external/bsd/drm2/drm/drm_memory.c:1.1.2.5
--- src/sys/external/bsd/drm2/drm/drm_memory.c:1.1.2.4	Wed Jul 24 02:47:50 2013
+++ src/sys/external/bsd/drm2/drm/drm_memory.c	Wed Jul 24 03:02:21 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_memory.c,v 1.1.2.4 2013/07/24 02:47:50 riastradh Exp $	*/
+/*	$NetBSD: drm_memory.c,v 1.1.2.5 2013/07/24 03:02:21 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_memory.c,v 1.1.2.4 2013/07/24 02:47:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_memory.c,v 1.1.2.5 2013/07/24 03:02:21 riastradh Exp $");
 
 /* XXX Cargo-culted from the old drm_memory.c.  */
 
@@ -121,6 +121,8 @@ drm_ioremap(struct drm_device *dev, stru
 		}
 
 		/* Mark it used and make a subregion just for the request.  */
+		if (bm->bm_mapped == UINT_MAX)
+			return NULL;
 		bm->bm_mapped++;
 		error = bus_space_subregion(bst, bm->bm_bsh,
 		    map->offset - bm->bm_base, map->size,
@@ -130,6 +132,7 @@ drm_ioremap(struct drm_device *dev, stru
 			 * Back out: unmark it and, if nobody else was
 			 * using it, unmap it.
 			 */
+			KASSERT(bm->bm_mapped > 0);
 			if (--bm->bm_mapped == 0)
 				bus_space_unmap(bst, bm->bm_bsh,
 				    bm->bm_size);
@@ -166,6 +169,8 @@ drm_ioremap(struct drm_device *dev, stru
 				continue;
 
 			/* Mark it used and return it.  */
+			if (bm->bm_mapped == UINT_MAX)
+				return NULL;
 			bm->bm_mapped++;
 
 			/* XXX size is an input/output parameter too...?  */
@@ -185,6 +190,7 @@ drm_ioremap(struct drm_device *dev, stru
 				return NULL; /* XXX Why not continue?  */
 
 			/* Got it.  Allocate this bus map.  */
+			KASSERT(bm->bm_mapped == 0);
 			bm->bm_mapped++;
 			bm->bm_base = map->offset;
 			bm->bm_size = map->size;
@@ -215,7 +221,7 @@ drm_iounmap(struct drm_device *dev, stru
 	 */
 	if (bm != NULL) {
 		KASSERT(bm->bm_mapped > 0);
-		if (--bm->bm_mapped)
+		if (--bm->bm_mapped == 0)
 			bus_space_unmap(bst, bm->bm_bsh, bm->bm_size);
 	}
 }

Reply via email to