intel: Add some defense against bo allocation failure
authorChris Wilson <chris@chris-wilson.co.uk>
Fri, 4 Mar 2011 15:04:09 +0000 (15:04 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 7 Mar 2011 10:53:00 +0000 (10:53 +0000)
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
src/mesa/drivers/dri/intel/intel_regions.c

index 0857fa8ad70f6d6706bf88cad3b24b8de2e8ce61..a4da1ce4fa5857ab48a4aa59fb7c886c5134667d 100644 (file)
@@ -149,11 +149,6 @@ intel_region_alloc_internal(struct intel_screen *screen,
 {
    struct intel_region *region;
 
-   if (buffer == NULL) {
-      _DBG("%s <-- NULL\n", __FUNCTION__);
-      return NULL;
-   }
-
    region = calloc(sizeof(*region), 1);
    if (region == NULL)
       return region;
@@ -180,6 +175,7 @@ intel_region_alloc(struct intel_screen *screen,
    drm_intel_bo *buffer;
    unsigned long flags = 0;
    unsigned long aligned_pitch;
+   struct intel_region *region;
 
    if (expect_accelerated_upload)
       flags |= BO_ALLOC_FOR_RENDER;
@@ -187,9 +183,17 @@ intel_region_alloc(struct intel_screen *screen,
    buffer = drm_intel_bo_alloc_tiled(screen->bufmgr, "region",
                                     width, height, cpp,
                                     &tiling, &aligned_pitch, flags);
+   if (buffer == NULL)
+      return NULL;
 
-   return intel_region_alloc_internal(screen, cpp, width, height,
-                                     aligned_pitch / cpp, tiling, buffer);
+   region = intel_region_alloc_internal(screen, cpp, width, height,
+                                        aligned_pitch / cpp, tiling, buffer);
+   if (region == NULL) {
+      drm_intel_bo_unreference(buffer);
+      return NULL;
+   }
+
+   return region;
 }
 
 GLboolean