[Mesa-dev] [PATCH 2/2] st/mesa: do proper error checking for u_upload_alloc() calls

Jose Fonseca jfonseca at vmware.com
Fri Jan 25 01:36:43 PST 2013


Series is 
Reviewed-by: Jose Fonseca <jfonseca at vmware.com>

----- Original Message -----
> We weren't properly checking the return value of these calls (and
> calls to u_upload_data()) to detect OOM errors.
> ---
>  src/mesa/state_tracker/st_cb_bitmap.c     |    5 ++---
>  src/mesa/state_tracker/st_cb_clear.c      |    5 ++---
>  src/mesa/state_tracker/st_cb_drawpixels.c |    5 ++---
>  src/mesa/state_tracker/st_cb_drawtex.c    |    7 +++----
>  src/mesa/state_tracker/st_draw.c          |   21
>  +++++++++++++++++----
>  5 files changed, 26 insertions(+), 17 deletions(-)
> 
> diff --git a/src/mesa/state_tracker/st_cb_bitmap.c
> b/src/mesa/state_tracker/st_cb_bitmap.c
> index 843dc5b..63dbdb2 100644
> --- a/src/mesa/state_tracker/st_cb_bitmap.c
> +++ b/src/mesa/state_tracker/st_cb_bitmap.c
> @@ -350,9 +350,8 @@ setup_bitmap_vertex_data(struct st_context *st,
> bool normalized,
>        tBot = (GLfloat) height;
>     }
>  
> -   u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]),
> vbuf_offset, vbuf,
> -		  (void**)&vertices);
> -   if (!vbuf) {
> +   if (u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]),
> +                      vbuf_offset, vbuf, (void **) &vertices) !=
> PIPE_OK) {
>        return;
>     }
>  
> diff --git a/src/mesa/state_tracker/st_cb_clear.c
> b/src/mesa/state_tracker/st_cb_clear.c
> index d01236e..a5aa8f4 100644
> --- a/src/mesa/state_tracker/st_cb_clear.c
> +++ b/src/mesa/state_tracker/st_cb_clear.c
> @@ -141,9 +141,8 @@ draw_quad(struct st_context *st,
>     GLuint i, offset;
>     float (*vertices)[2][4];  /**< vertex pos + color */
>  
> -   u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), &offset,
> &vbuf,
> -		  (void**)&vertices);
> -   if (!vbuf) {
> +   if (u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]),
> +                      &offset, &vbuf, (void **) &vertices) !=
> PIPE_OK) {
>        return;
>     }
>  
> diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c
> b/src/mesa/state_tracker/st_cb_drawpixels.c
> index 65f1160..c944b81 100644
> --- a/src/mesa/state_tracker/st_cb_drawpixels.c
> +++ b/src/mesa/state_tracker/st_cb_drawpixels.c
> @@ -568,9 +568,8 @@ draw_quad(struct gl_context *ctx, GLfloat x0,
> GLfloat y0, GLfloat z,
>     struct pipe_resource *buf = NULL;
>     unsigned offset;
>  
> -   u_upload_alloc(st->uploader, 0, 4 * sizeof(verts[0]), &offset,
> &buf,
> -		  (void**)&verts);
> -   if (!buf) {
> +   if (u_upload_alloc(st->uploader, 0, 4 * sizeof(verts[0]),
> &offset,
> +                      &buf, (void **) &verts) != PIPE_OK) {
>        return;
>     }
>  
> diff --git a/src/mesa/state_tracker/st_cb_drawtex.c
> b/src/mesa/state_tracker/st_cb_drawtex.c
> index 269068d..5ca0970 100644
> --- a/src/mesa/state_tracker/st_cb_drawtex.c
> +++ b/src/mesa/state_tracker/st_cb_drawtex.c
> @@ -148,10 +148,9 @@ st_DrawTex(struct gl_context *ctx, GLfloat x,
> GLfloat y, GLfloat z,
>        GLfloat *vbuf = NULL;
>        GLuint attr;
>  
> -      u_upload_alloc(st->uploader, 0,
> -		     numAttribs * 4 * 4 * sizeof(GLfloat),
> -		     &offset, &vbuffer, (void**)&vbuf);
> -      if (!vbuffer) {
> +      if (u_upload_alloc(st->uploader, 0,
> +                         numAttribs * 4 * 4 * sizeof(GLfloat),
> +                         &offset, &vbuffer, (void **) &vbuf) !=
> PIPE_OK) {
>           return;
>        }
>        
> diff --git a/src/mesa/state_tracker/st_draw.c
> b/src/mesa/state_tracker/st_draw.c
> index de539ca..de62264 100644
> --- a/src/mesa/state_tracker/st_draw.c
> +++ b/src/mesa/state_tracker/st_draw.c
> @@ -84,7 +84,12 @@ all_varyings_in_vbos(const struct gl_client_array
> *arrays[])
>  }
>  
>  
> -static void
> +/**
> + * Basically, translate Mesa's index buffer information into
> + * a pipe_index_buffer object.
> + * \return TRUE or FALSE for success/failure
> + */
> +static boolean
>  setup_index_buffer(struct st_context *st,
>                     const struct _mesa_index_buffer *ib,
>                     struct pipe_index_buffer *ibuffer)
> @@ -100,8 +105,12 @@ setup_index_buffer(struct st_context *st,
>        ibuffer->offset = pointer_to_offset(ib->ptr);
>     }
>     else if (st->indexbuf_uploader) {
> -      u_upload_data(st->indexbuf_uploader, 0, ib->count *
> ibuffer->index_size,
> -                    ib->ptr, &ibuffer->offset, &ibuffer->buffer);
> +      if (u_upload_data(st->indexbuf_uploader, 0,
> +                        ib->count * ibuffer->index_size, ib->ptr,
> +                        &ibuffer->offset, &ibuffer->buffer) !=
> PIPE_OK) {
> +         /* out of memory */
> +         return FALSE;
> +      }
>        u_upload_unmap(st->indexbuf_uploader);
>     }
>     else {
> @@ -110,6 +119,7 @@ setup_index_buffer(struct st_context *st,
>     }
>  
>     cso_set_index_buffer(st->cso_context, ibuffer);
> +   return TRUE;
>  }
>  
>  
> @@ -220,7 +230,10 @@ st_draw_vbo(struct gl_context *ctx,
>              vbo_get_minmax_indices(ctx, prims, ib, &min_index,
>              &max_index,
>                                     nr_prims);
>  
> -      setup_index_buffer(st, ib, &ibuffer);
> +      if (!setup_index_buffer(st, ib, &ibuffer)) {
> +         /* out of memory */
> +         return;
> +      }
>  
>        info.indexed = TRUE;
>        if (min_index != ~0 && max_index != ~0) {
> --
> 1.7.3.4
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
> 


More information about the mesa-dev mailing list