the memory object should be checked whether valid in context buffers before being set as kernel arguments.
v2: rename the function from mem_in_buffers to is_valid_mem, move the
magic header check into it.
Signed-off-by: Luo Xionghu <xionghu.luo@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
enum gbe_arg_type arg_type; /* kind of argument */
size_t arg_sz; /* size of the argument */
cl_mem mem = NULL; /* for __global, __constant and image arguments */
+ cl_context ctx = k->program->ctx;
if (UNLIKELY(index >= k->arg_n))
return CL_INVALID_ARG_INDEX;
if(value != NULL)
mem = *(cl_mem*)value;
if(value != NULL && mem) {
- if (UNLIKELY(mem->magic != CL_MAGIC_MEM_HEADER))
+ if( CL_SUCCESS != is_valid_mem(mem, ctx->buffers))
return CL_INVALID_MEM_OBJECT;
if (UNLIKELY((arg_type == GBE_ARG_IMAGE && !IS_IMAGE(mem))
}
+LOCAL cl_int
+is_valid_mem(cl_mem mem, cl_mem buffers)
+{
+ cl_mem tmp = buffers;
+ while(tmp){
+ if(mem == tmp){
+ if (UNLIKELY(mem->magic != CL_MAGIC_MEM_HEADER))
+ return CL_INVALID_MEM_OBJECT;
+ return CL_SUCCESS;
+ }
+ tmp = tmp->next;
+ }
+ return CL_INVALID_MEM_OBJECT;
+}
+
LOCAL cl_mem
cl_mem_new_buffer(cl_context ctx,
cl_mem_flags flags,
/* Query information about an image */
extern cl_int cl_get_image_info(cl_mem, cl_image_info, size_t, void *, size_t *);
+/* Query whether mem is in buffers */
+extern cl_int is_valid_mem(cl_mem mem, cl_mem buffers);
+
/* Create a new memory object and initialize it with possible user data */
extern cl_mem cl_mem_new_buffer(cl_context, cl_mem_flags, size_t, void*, cl_int*);