[Mesa-dev] [PATCH 6/7] i965: Clean up error handling for context creation.

Eric Anholt eric at anholt.net
Thu Sep 26 20:36:01 PDT 2013


The intel_screen.c used to be a dispatch to one of 3 driver functions, but
was down to 1, so it was kind of a waste.  In addition, it was trying to
free all of the data that might have been partially freed in the kernel
3.6 check (which comes after intelInitContext, and thus might have had
driverPrivate set and result in intelDestroyContext() doing work on the
freed data).  By moving the driverPrivate setup earlier, we can use
intelDestroyContext() consistently and avoid such problems in the future.
---
 src/mesa/drivers/dri/i965/brw_context.c   |  4 ++--
 src/mesa/drivers/dri/i965/intel_context.c |  6 +++---
 src/mesa/drivers/dri/i965/intel_screen.c  | 28 +---------------------------
 3 files changed, 6 insertions(+), 32 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index f60d4df..6c768b3 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -310,7 +310,7 @@ brwCreateContext(int api,
                           mesaVis, driContextPriv,
 			  sharedContextPrivate, &functions,
 			  error)) {
-      ralloc_free(brw);
+      intelDestroyContext(driContextPriv);
       return false;
    }
 
@@ -331,7 +331,7 @@ brwCreateContext(int api,
 
       if (!brw->hw_ctx) {
          fprintf(stderr, "Gen6+ requires Kernel 3.6 or later.\n");
-         ralloc_free(brw);
+         intelDestroyContext(driContextPriv);
          return false;
       }
    }
diff --git a/src/mesa/drivers/dri/i965/intel_context.c b/src/mesa/drivers/dri/i965/intel_context.c
index 3eb5b8b..850d9a0 100644
--- a/src/mesa/drivers/dri/i965/intel_context.c
+++ b/src/mesa/drivers/dri/i965/intel_context.c
@@ -426,6 +426,9 @@ intelInitContext(struct brw_context *brw,
    brw->intelScreen = intelScreen;
    brw->bufmgr = intelScreen->bufmgr;
 
+   driContextPriv->driverPrivate = brw;
+   brw->driContext = driContextPriv;
+
    if (!_mesa_initialize_context(&brw->ctx, api, mesaVis, shareCtx,
                                  functions)) {
       *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY;
@@ -433,9 +436,6 @@ intelInitContext(struct brw_context *brw,
       return false;
    }
 
-   driContextPriv->driverPrivate = brw;
-   brw->driContext = driContextPriv;
-
    brw->gen = intelScreen->gen;
 
    const int devID = intelScreen->deviceID;
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index 94b1e3c..df9edb7 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -980,32 +980,6 @@ intelDestroyBuffer(__DRIdrawable * driDrawPriv)
     _mesa_reference_framebuffer(&fb, NULL);
 }
 
-static GLboolean
-intelCreateContext(gl_api api,
-		   const struct gl_config * mesaVis,
-                   __DRIcontext * driContextPriv,
-		   unsigned major_version,
-		   unsigned minor_version,
-		   uint32_t flags,
-		   unsigned *error,
-                   void *sharedContextPrivate)
-{
-   bool success = false;
-
-   success = brwCreateContext(api, mesaVis,
-                              driContextPriv,
-                              major_version, minor_version, flags,
-                              error, sharedContextPrivate);
-
-   if (success)
-      return true;
-
-   if (driContextPriv->driverPrivate != NULL)
-      intelDestroyContext(driContextPriv);
-
-   return false;
-}
-
 static bool
 intel_init_bufmgr(struct intel_screen *intelScreen)
 {
@@ -1367,7 +1341,7 @@ intelReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
 const struct __DriverAPIRec driDriverAPI = {
    .InitScreen		 = intelInitScreen2,
    .DestroyScreen	 = intelDestroyScreen,
-   .CreateContext	 = intelCreateContext,
+   .CreateContext	 = brwCreateContext,
    .DestroyContext	 = intelDestroyContext,
    .CreateBuffer	 = intelCreateBuffer,
    .DestroyBuffer	 = intelDestroyBuffer,
-- 
1.8.4.rc3



More information about the mesa-dev mailing list