[Mesa-dev] [PATCH 1/3] clover: Check invalid flag combinations in clCreateBuffer.

Francisco Jerez currojerez at riseup.net
Sun Dec 15 23:53:19 PST 2013


Jan Vesely <jan.vesely at rutgers.edu> writes:

> Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
> ---
>  src/gallium/state_trackers/clover/api/memory.cpp | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/src/gallium/state_trackers/clover/api/memory.cpp b/src/gallium/state_trackers/clover/api/memory.cpp
> index 785a509..15f5b7f 100644
> --- a/src/gallium/state_trackers/clover/api/memory.cpp
> +++ b/src/gallium/state_trackers/clover/api/memory.cpp
> @@ -43,6 +43,21 @@ clCreateBuffer(cl_context d_ctx, cl_mem_flags flags, size_t size,
>                   CL_MEM_COPY_HOST_PTR))
>        throw error(CL_INVALID_VALUE);
>  
> +   if ((flags & CL_MEM_WRITE_ONLY) && (flags & CL_MEM_READ_ONLY))
> +      throw error(CL_INVALID_VALUE);
> +
> +   if ((flags & CL_MEM_READ_WRITE) && (flags & CL_MEM_READ_ONLY))
> +      throw error(CL_INVALID_VALUE);
> +
> +   if ((flags & CL_MEM_READ_WRITE) && (flags & CL_MEM_WRITE_ONLY))
> +      throw error(CL_INVALID_VALUE);
> +
> +   if ((flags & CL_MEM_COPY_HOST_PTR) && (flags & CL_MEM_USE_HOST_PTR))
> +      throw error(CL_INVALID_VALUE);
> +
> +   if ((flags & CL_MEM_ALLOC_HOST_PTR) && (flags & CL_MEM_USE_HOST_PTR))
> +      throw error(CL_INVALID_VALUE);
> +

Wouldn't it be easier to do something like:

|   if (util_bitcount(flags & (CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY |
|                              CL_MEM_READ_WRITE)) > 1)
|      throw error(CL_INVALID_VALUE);
|
|   if ((flags & CL_MEM_USE_HOST_PTR) &&
|       (flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR)))
|      throw error(CL_INVALID_VALUE);

With that fixed, Reviewed-by: Francisco Jerez <currojerez at riseup.net>

>     ret_error(r_errcode, CL_SUCCESS);
>     return new root_buffer(ctx, flags, size, host_ptr);
>  
> -- 
> 1.8.3.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 229 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20131216/a33de083/attachment.pgp>


More information about the mesa-dev mailing list