anv/allocator: Return a null state for zero-size allocations
Reviewed-by: Juan A. Suarez Romero <jasuarez@igalia.com>
This commit is contained in:
parent
45e1829274
commit
e049dea5b2
|
@ -710,6 +710,9 @@ anv_state_pool_alloc_no_vg(struct anv_state_pool *pool,
|
||||||
struct anv_state
|
struct anv_state
|
||||||
anv_state_pool_alloc(struct anv_state_pool *pool, size_t size, size_t align)
|
anv_state_pool_alloc(struct anv_state_pool *pool, size_t size, size_t align)
|
||||||
{
|
{
|
||||||
|
if (size == 0)
|
||||||
|
return ANV_STATE_NULL;
|
||||||
|
|
||||||
struct anv_state state = anv_state_pool_alloc_no_vg(pool, size, align);
|
struct anv_state state = anv_state_pool_alloc_no_vg(pool, size, align);
|
||||||
VG(VALGRIND_MEMPOOL_ALLOC(pool, state.map, size));
|
VG(VALGRIND_MEMPOOL_ALLOC(pool, state.map, size));
|
||||||
return state;
|
return state;
|
||||||
|
@ -731,6 +734,9 @@ anv_state_pool_free_no_vg(struct anv_state_pool *pool, struct anv_state state)
|
||||||
void
|
void
|
||||||
anv_state_pool_free(struct anv_state_pool *pool, struct anv_state state)
|
anv_state_pool_free(struct anv_state_pool *pool, struct anv_state state)
|
||||||
{
|
{
|
||||||
|
if (state.alloc_size == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
VG(VALGRIND_MEMPOOL_FREE(pool, state.map));
|
VG(VALGRIND_MEMPOOL_FREE(pool, state.map));
|
||||||
anv_state_pool_free_no_vg(pool, state);
|
anv_state_pool_free_no_vg(pool, state);
|
||||||
}
|
}
|
||||||
|
@ -791,6 +797,9 @@ struct anv_state
|
||||||
anv_state_stream_alloc(struct anv_state_stream *stream,
|
anv_state_stream_alloc(struct anv_state_stream *stream,
|
||||||
uint32_t size, uint32_t alignment)
|
uint32_t size, uint32_t alignment)
|
||||||
{
|
{
|
||||||
|
if (size == 0)
|
||||||
|
return ANV_STATE_NULL;
|
||||||
|
|
||||||
struct anv_state_stream_block *sb = stream->block;
|
struct anv_state_stream_block *sb = stream->block;
|
||||||
|
|
||||||
struct anv_state state;
|
struct anv_state state;
|
||||||
|
|
|
@ -490,6 +490,8 @@ struct anv_state {
|
||||||
void *map;
|
void *map;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 })
|
||||||
|
|
||||||
struct anv_fixed_size_state_pool {
|
struct anv_fixed_size_state_pool {
|
||||||
size_t state_size;
|
size_t state_size;
|
||||||
union anv_free_list free_list;
|
union anv_free_list free_list;
|
||||||
|
|
Loading…
Reference in New Issue