Mesa (master): zink: do not dereference NULL pointer

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Apr 14 15:15:13 UTC 2021


Module: Mesa
Branch: master
Commit: 9de05fd36bc7efcda35f6fc107a58b837bc0403b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9de05fd36bc7efcda35f6fc107a58b837bc0403b

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Wed Apr 14 15:44:16 2021 +0200

zink: do not dereference NULL pointer

If first_frame_done isn't set, but fence is NULL, we end up dereferncing
that NULL-pointer.

This can happen in the case where the first submitted batch has no work,
and pfence was passed as a NULL-pointer.

While we're at it, simplify the check with the surrounding code, which
also checks for a NULL-pointer here.

Fixes: e93ca92d4ae ("zink: force explicit fence only on first frame flush")
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10235>

---

 src/gallium/drivers/zink/zink_context.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index 36e93f43831..315619dc246 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -1885,17 +1885,19 @@ zink_flush(struct pipe_context *pctx,
             util_queue_fence_signal(&mfence->ready);
       }
    }
-   if (fence && !(flags & (PIPE_FLUSH_DEFERRED | PIPE_FLUSH_ASYNC)))
-      sync_flush(ctx, zink_batch_state(fence));
-
-   if (flags & PIPE_FLUSH_END_OF_FRAME && !(flags & TC_FLUSH_ASYNC) && !deferred) {
-      /* if the first frame has not yet occurred, we need an explicit fence here
-       * in some cases in order to correctly draw the first frame, though it's
-       * unknown at this time why this is the case
-       */
-      if (!ctx->first_frame_done)
-         zink_vkfence_wait(screen, fence, PIPE_TIMEOUT_INFINITE);
-      ctx->first_frame_done = true;
+   if (fence) {
+      if (!(flags & (PIPE_FLUSH_DEFERRED | PIPE_FLUSH_ASYNC)))
+         sync_flush(ctx, zink_batch_state(fence));
+
+      if (flags & PIPE_FLUSH_END_OF_FRAME && !(flags & TC_FLUSH_ASYNC) && !deferred) {
+         /* if the first frame has not yet occurred, we need an explicit fence here
+         * in some cases in order to correctly draw the first frame, though it's
+         * unknown at this time why this is the case
+         */
+         if (!ctx->first_frame_done)
+            zink_vkfence_wait(screen, fence, PIPE_TIMEOUT_INFINITE);
+         ctx->first_frame_done = true;
+      }
    }
 }
 



More information about the mesa-commit mailing list