Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Jun 2009 16:40:48 +0000 (UTC)
From:      Robert Noland <rnoland@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r194539 - head/sys/dev/drm
Message-ID:  <200906201640.n5KGemmF081182@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rnoland
Date: Sat Jun 20 16:40:48 2009
New Revision: 194539
URL: http://svn.freebsd.org/changeset/base/194539

Log:
  realloc() behaves identically to malloc when passed a NULL object pointer
  
  If an error does occur we would have left max_context with an incorrect
  value.
  
  MFC after:	3 days

Modified:
  head/sys/dev/drm/drm_context.c

Modified: head/sys/dev/drm/drm_context.c
==============================================================================
--- head/sys/dev/drm/drm_context.c	Sat Jun 20 16:39:25 2009	(r194538)
+++ head/sys/dev/drm/drm_context.c	Sat Jun 20 16:40:48 2009	(r194539)
@@ -72,34 +72,23 @@ int drm_ctxbitmap_next(struct drm_device
 	}
 
 	set_bit(bit, dev->ctx_bitmap);
-	DRM_DEBUG("drm_ctxbitmap_next bit : %d\n", bit);
+	DRM_DEBUG("bit : %d\n", bit);
 	if ((bit+1) > dev->max_context) {
-		dev->max_context = (bit+1);
-		if (dev->context_sareas != NULL) {
-			drm_local_map_t **ctx_sareas;
-
-			ctx_sareas = realloc(dev->context_sareas,
-			    dev->max_context * sizeof(*dev->context_sareas),
-			    DRM_MEM_SAREA, M_NOWAIT);
-			if (ctx_sareas == NULL) {
-				clear_bit(bit, dev->ctx_bitmap);
-				DRM_UNLOCK();
-				return -1;
-			}
-			dev->context_sareas = ctx_sareas;
-			dev->context_sareas[bit] = NULL;
-		} else {
-			/* max_context == 1 at this point */
-			dev->context_sareas = malloc(dev->max_context * 
-			    sizeof(*dev->context_sareas), DRM_MEM_SAREA,
-			    M_NOWAIT);
-			if (dev->context_sareas == NULL) {
-				clear_bit(bit, dev->ctx_bitmap);
-				DRM_UNLOCK();
-				return -1;
-			}
-			dev->context_sareas[bit] = NULL;
+		drm_local_map_t **ctx_sareas;
+		int max_ctx = (bit+1);
+
+		ctx_sareas = realloc(dev->context_sareas,
+		    max_ctx * sizeof(*dev->context_sareas),
+		    DRM_MEM_SAREA, M_NOWAIT);
+		if (ctx_sareas == NULL) {
+			clear_bit(bit, dev->ctx_bitmap);
+			DRM_DEBUG("failed to allocate bit : %d\n", bit);
+			DRM_UNLOCK();
+			return -1;
 		}
+		dev->max_context = max_ctx;
+		dev->context_sareas = ctx_sareas;
+		dev->context_sareas[bit] = NULL;
 	}
 	DRM_UNLOCK();
 	return bit;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906201640.n5KGemmF081182>