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>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32428>
This commit is contained in:
Boris Brezillon 2024-11-28 16:26:23 +01:00 committed by Marge Bot
parent 41a2b86666
commit 3006c2a7b6

View file

@ -535,7 +535,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;
@ -564,7 +564,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)) {
/* If we have a LOAD_IP chain, we need to patch each LOAD_IP
* instruction before we copy the block to the final memory
* region. */
@ -654,7 +654,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