util: Fix bookkeeping of linear node sizes

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: 591db9a9a5 ("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>
This commit is contained in:
Caio Oliveira 2023-09-25 14:46:49 -07:00 committed by Marge Bot
parent 6d00c2f78c
commit d27b135b3a

View 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);