Refine error check in clCreateProgramFromSource() and clCreateKernel()
authorRuiling Song <ruiling.song@intel.com>
Thu, 13 Jun 2013 01:40:17 +0000 (09:40 +0800)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Fri, 14 Jun 2013 09:01:08 +0000 (17:01 +0800)
Signed-off-by: Ruiling Song <ruiling.song@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
src/cl_api.c
src/cl_program.c

index fd707e5..f14bee4 100644 (file)
@@ -616,8 +616,17 @@ clCreateProgramWithSource(cl_context     context,
 {
   cl_program program = NULL;
   cl_int err = CL_SUCCESS;
+  cl_uint i;
 
   CHECK_CONTEXT (context);
+  INVALID_VALUE_IF (count == 0);
+  INVALID_VALUE_IF (strings == NULL);
+  for(i = 0; i < count; i++) {
+    if(UNLIKELY(strings[i] == NULL)) {
+      err = CL_INVALID_VALUE;
+      goto error;
+    }
+  }
   program = cl_program_create_from_source(context,
                                           count,
                                           strings,
@@ -691,10 +700,7 @@ clBuildProgram(cl_program            program,
   /* Everything is easy. We only support one device anyway */
   if (num_devices != 0) {
     assert(program->ctx);
-    if (UNLIKELY(device_list[0] != program->ctx->device)) {
-      err = CL_INVALID_DEVICE;
-      goto error;
-    }
+    INVALID_DEVICE_IF (device_list[0] != program->ctx->device);
   }
 
   /* TODO support create program from binary */
@@ -752,6 +758,7 @@ clCreateKernel(cl_program   program,
     err = CL_INVALID_PROGRAM_EXECUTABLE;
     goto error;
   }
+  INVALID_VALUE_IF (kernel_name == NULL);
   kernel = cl_program_create_kernel(program, kernel_name, &err);
 
 error:
index 0c48ef3..6acf31f 100644 (file)
@@ -236,8 +236,6 @@ cl_program_create_from_source(cl_context ctx,
   cl_uint i;
 
   assert(ctx);
-  INVALID_VALUE_IF (count == 0);
-  INVALID_VALUE_IF (strings == NULL);
 
   // the real compilation step will be done at build time since we do not have
   // yet the compilation options
@@ -297,11 +295,6 @@ cl_program_create_kernel(cl_program p, const char *name, cl_int *errcode_ret)
   cl_int err = CL_SUCCESS;
   uint32_t i = 0;
 
-  if (UNLIKELY(name == NULL)) {
-    err = CL_INVALID_KERNEL_NAME;
-    goto error;
-  }
-
   /* Find the program first */
   for (i = 0; i < p->ker_n; ++i) {
     assert(p->ker[i]);