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)
committerChristian Gmeiner <christian.gmeiner@gmail.com>
Tue, 21 Feb 2017 20:14:27 +0000 (21:14 +0100)
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>
src/gallium/drivers/etnaviv/etnaviv_context.c

index 62297a050476b4e8018b38948c0d28b488eaaa00..5566e0ed38e1a0fb41308f4c7d0105c9d7460206 100644 (file)
@@ -267,16 +267,11 @@ 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;
 
-   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;
@@ -285,6 +280,11 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
       goto fail;
    pctx->const_uploader = pctx->stream_uploader;
 
+   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;
+
    /* context ctxate setup */
    ctx->specs = screen->specs;
    ctx->screen = screen;