util: Fix bookkeeping of linear node sizes
authorCaio Oliveira <caio.oliveira@intel.com>
Mon, 25 Sep 2023 21:46:49 +0000 (14:46 -0700)
committerMarge Bot <emma+marge@anholt.net>
Tue, 26 Sep 2023 02:53:27 +0000 (02:53 +0000)
When creating a new node, we were clobbering the original size
requested, and use that as offset, so the node would always be full.

Fixes: 591db9a9a54 ("util: Remove per-buffer header in linear alloc for release mode")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25382>

src/util/ralloc.c

index b74bae2..b760ddb 100644 (file)
@@ -1010,11 +1010,12 @@ linear_alloc_child(linear_ctx *ctx, unsigned size)
 
    if (unlikely(ctx->offset + size > ctx->size)) {
       /* allocate a new node */
-      if (likely(size < MIN_LINEAR_BUFSIZE))
-         size = MIN_LINEAR_BUFSIZE;
+      unsigned node_size = size;
+      if (likely(node_size < MIN_LINEAR_BUFSIZE))
+         node_size = MIN_LINEAR_BUFSIZE;
       
       const unsigned canary_size = get_node_canary_size();
-      const unsigned full_size = canary_size + size;
+      const unsigned full_size = canary_size + node_size;
 
       /* linear context is also a ralloc context */
       char *ptr = ralloc_size(ctx, full_size);
@@ -1022,7 +1023,7 @@ linear_alloc_child(linear_ctx *ctx, unsigned size)
          return NULL;
 
       ctx->offset = 0;
-      ctx->size = size;
+      ctx->size = node_size;
       ctx->latest = ptr + canary_size;
 #ifndef NDEBUG
       linear_node_canary *canary = get_node_canary(ctx->latest);