[Mesa-dev] [PATCH] etnaviv: don't dereference etna_resource pointer if allocation fails
Aleksander Morgado
aleksander at aleksander.es
Thu Jul 6 09:35:37 UTC 2017
The check for the pointer being non-NULL was being done too late.
Signed-off-by: Aleksander Morgado <aleksander at aleksander.es>
---
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 97e0a15597..a709482c1b 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.13.1
More information about the mesa-dev
mailing list