pan/cs: Fix cs_builder allocation failure robustness

There's more than one error-path out of cs_alloc_ins_block(), but only
one of them got the discar_instr_slot treatment. Instead of plugging
this in one more time, let's move this handling up to cs_alloc_ins(),
where we can easily whack two birds with one stone. This makes us
consistently return NULL on error here.

At the same time, we need to patch up cs_flush_block_instrs() here,
because we don't actually set the buffer invalid here. So let's
check for NULL here instead, which is the new contract.

Fixes: 0e6aaab00a ("pan/cs: add block to handle registers backup in exception handler")
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Tested-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Eric R. Smith <eric.smith@collabora.com>
(cherry picked from commit 3006c2a7b6)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32852>
This commit is contained in:
Boris Brezillon
2024-11-28 16:26:23 +01:00
committed by Dylan Baker
parent e4276eca9b
commit d72bf5b122
2 changed files with 4 additions and 4 deletions

View File

@@ -3634,7 +3634,7 @@
"description": "pan/cs: Fix cs_builder allocation failure robustness",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 3,
"main_sha": null,
"because_sha": "0e6aaab00ae58a03a279d88d587b1a4721c1c2b9",
"notes": null

View File

@@ -524,7 +524,7 @@ cs_alloc_ins_block(struct cs_builder *b, uint32_t num_instrs)
return util_dynarray_grow(&b->blocks.instrs, uint64_t, num_instrs);
if (!cs_reserve_instrs(b, num_instrs))
return &b->discard_instr_slot;
return NULL;
assert(b->cur_chunk.size + num_instrs - 1 < b->cur_chunk.buffer.capacity);
uint32_t pos = b->cur_chunk.pos;
@@ -545,7 +545,7 @@ cs_flush_block_instrs(struct cs_builder *b)
void *buffer = cs_alloc_ins_block(b, num_instrs);
if (likely(cs_is_valid(b)))
if (likely(buffer != NULL))
memcpy(buffer, b->blocks.instrs.data, b->blocks.instrs.size);
util_dynarray_clear(&b->blocks.instrs);
@@ -614,7 +614,7 @@ cs_alloc_ins(struct cs_builder *b)
* causing further cs_else_start() instructions to be invalid. */
cs_flush_pending_if(b);
return cs_alloc_ins_block(b, 1);
return cs_alloc_ins_block(b, 1) ?: &b->discard_instr_slot;
}
/* Call this when you are done building a command stream and want to prepare