From a6893a50c8ae5b68e4175366dac718ee9f6fa9d1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 6 Jul 2017 11:35:37 +0200 Subject: [PATCH] etnaviv: don't dereference etna_resource pointer if allocation fails The check for the pointer being non-NULL was being done too late. Signed-off-by: Aleksander Morgado Reviewed-by: Christian Gmeiner --- src/gallium/drivers/etnaviv/etnaviv_resource.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c b/src/gallium/drivers/etnaviv/etnaviv_resource.c index 97e0a15597f..a709482c1b6 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c @@ -320,9 +320,9 @@ etna_resource_from_handle(struct pipe_screen *pscreen, struct winsys_handle *handle, unsigned usage) { struct etna_screen *screen = etna_screen(pscreen); - struct etna_resource *rsc = CALLOC_STRUCT(etna_resource); - struct etna_resource_level *level = &rsc->levels[0]; - struct pipe_resource *prsc = &rsc->base; + struct etna_resource *rsc; + struct etna_resource_level *level; + struct pipe_resource *prsc; struct pipe_resource *ptiled = NULL; DBG("target=%d, format=%s, %ux%ux%u, array_size=%u, last_level=%u, " @@ -331,9 +331,13 @@ etna_resource_from_handle(struct pipe_screen *pscreen, tmpl->height0, tmpl->depth0, tmpl->array_size, tmpl->last_level, tmpl->nr_samples, tmpl->usage, tmpl->bind, tmpl->flags); + rsc = CALLOC_STRUCT(etna_resource); if (!rsc) return NULL; + level = &rsc->levels[0]; + prsc = &rsc->base; + *prsc = *tmpl; pipe_reference_init(&prsc->reference, 1); -- 2.30.2