OSDN Git Service

etnaviv: move pctx initialisation to avoid a null dereference
authorChristian Gmeiner <christian.gmeiner@gmail.com>
Wed, 8 Feb 2017 12:07:25 +0000 (13:07 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Wed, 1 Mar 2017 13:34:41 +0000 (13:34 +0000)
In case ctx->stream == NULL the fail label gets executed where
pctx gets dereferenced - too bad pctx is NULL in that case.

Caught by Coverity, reported to me by imirkin.

Cc: "17.0" <mesa-stable@lists.freedesktop.org>
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
(cherry picked from commit a0b16a08905d68da07668a42eeb464b4f30bf3e5)

src/gallium/drivers/etnaviv/etnaviv_context.c

index d767cd1..88580c1 100644 (file)
@@ -251,20 +251,20 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
 {
    struct etna_context *ctx = CALLOC_STRUCT(etna_context);
    struct etna_screen *screen;
-   struct pipe_context *pctx = NULL;
+   struct pipe_context *pctx;
 
    if (ctx == NULL)
       return NULL;
 
+   pctx = &ctx->base;
+   pctx->priv = ctx;
+   pctx->screen = pscreen;
+
    screen = etna_screen(pscreen);
    ctx->stream = etna_cmd_stream_new(screen->pipe, 0x2000, &etna_cmd_stream_reset_notify, ctx);
    if (ctx->stream == NULL)
       goto fail;
 
-   pctx = &ctx->base;
-   pctx->priv = ctx;
-   pctx->screen = pscreen;
-
    /* context ctxate setup */
    ctx->specs = screen->specs;
    ctx->screen = screen;