summaryrefslogtreecommitdiff
path: root/src/cl_kernel.c
diff options
context:
space:
mode:
authorYang Rong <rong.r.yang@intel.com>2014-05-19 13:52:19 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-05-19 12:46:56 +0800
commit065cf032a7df7e72d0c90a7cd894f2de9f001255 (patch)
treebd412a526a879f8969c6ddf8524334a4b2412cb3 /src/cl_kernel.c
parent2cfa1d3e30f276b0f50f97b2fa661f31289acd2b (diff)
downloadbeignet-065cf032a7df7e72d0c90a7cd894f2de9f001255.tar.gz
Fix a crash when clSetKernelArg of parameter point to NULL value.
Per OCL spec, if the arg_value of clSetKernelArg is a memory object, it can be NULL or point to NULL. Driver only handle NULL case, will crash if point to NULL. Correct it. Signed-off-by: Yang Rong <rong.r.yang@intel.com> Reviewed-by: Junyan He <junyan.he@inbox.com>
Diffstat (limited to 'src/cl_kernel.c')
-rw-r--r--src/cl_kernel.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/cl_kernel.c b/src/cl_kernel.c
index ecb5e958..a45e281a 100644
--- a/src/cl_kernel.c
+++ b/src/cl_kernel.c
@@ -98,7 +98,7 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value)
uint32_t offset; /* where to patch */
enum gbe_arg_type arg_type; /* kind of argument */
size_t arg_sz; /* size of the argument */
- cl_mem mem; /* for __global, __constant and image arguments */
+ cl_mem mem = NULL; /* for __global, __constant and image arguments */
if (UNLIKELY(index >= k->arg_n))
return CL_INVALID_ARG_INDEX;
@@ -133,8 +133,9 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value)
// should be image, GLOBAL_PTR, CONSTANT_PTR
if (UNLIKELY(value == NULL && arg_type == GBE_ARG_IMAGE))
return CL_INVALID_ARG_VALUE;
- if(value != NULL) {
+ if(value != NULL)
mem = *(cl_mem*)value;
+ if(value != NULL && mem) {
if (UNLIKELY(mem->magic != CL_MAGIC_MEM_HEADER))
return CL_INVALID_MEM_OBJECT;
@@ -178,7 +179,10 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value)
return CL_SUCCESS;
}
- if(value == NULL) {
+ if(value != NULL)
+ mem = *(cl_mem*) value;
+
+ if(value == NULL || mem == NULL) {
/* for buffer object GLOBAL_PTR CONSTANT_PTR, it maybe NULL */
int32_t offset = gbe_kernel_get_curbe_offset(k->opaque, GBE_CURBE_KERNEL_ARGUMENT, index);
*((uint32_t *)(k->curbe + offset)) = 0;