fix piglit cl-api-set-kernel-arg fail.
authorLuo Xionghu <xionghu.luo@intel.com>
Thu, 11 Sep 2014 00:43:54 +0000 (08:43 +0800)
committerZhigang Gong <zhigang.gong@intel.com>
Thu, 11 Sep 2014 05:42:31 +0000 (13:42 +0800)
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>
src/cl_kernel.c
src/cl_mem.c
src/cl_mem.h

index 5ab9c55..d7c2f7c 100644 (file)
@@ -99,6 +99,7 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value)
   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;
@@ -136,7 +137,7 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value)
     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))
index 11411d9..077f1d7 100644 (file)
@@ -289,6 +289,21 @@ error:
 
 }
 
+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,
index 57f38f1..0ccbb5d 100644 (file)
@@ -177,6 +177,9 @@ extern cl_int cl_get_mem_object_info(cl_mem, cl_mem_info, size_t, void *, size_t
 /* 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*);