clEnqueueNDRangeKernel: fix for segfault caused by empty local_work_size
authorMario Kicherer <dev@kicherer.org>
Tue, 7 May 2013 19:57:37 +0000 (21:57 +0200)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Wed, 8 May 2013 05:53:58 +0000 (13:53 +0800)
Without this fix, an empty local_work_size that is allowed by specification
causes a segfault. Merged the block with a further check below.

Signed-off-by: Mario Kicherer <dev@kicherer.org>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
src/cl_api.c

index c9aba20..1009f9a 100644 (file)
@@ -1073,13 +1073,6 @@ clEnqueueNDRangeKernel(cl_command_queue  command_queue,
     goto error;
   }
 
-  /* Local size must be non-null */
-  for (i = 0; i < work_dim; ++i)
-    if (UNLIKELY(local_work_size[i] == 0)) {
-      err = CL_INVALID_WORK_GROUP_SIZE;
-      goto error;
-    }
-
   /* Check offset values. We add a non standard restriction. The offsets must
    * also be evenly divided by the local sizes
    */
@@ -1089,16 +1082,16 @@ clEnqueueNDRangeKernel(cl_command_queue  command_queue,
         err = CL_INVALID_GLOBAL_OFFSET;
         goto error;
       }
-      if (UNLIKELY(global_work_offset[i] % local_work_size[i])) {
+      if (UNLIKELY(local_work_size != NULL && global_work_offset[i] % local_work_size[i])) {
         err = CL_INVALID_GLOBAL_OFFSET;
         goto error;
       }
     }
 
-  /* Local sizes must divide global sizes */
+  /* Local sizes must be non-null and divide global sizes */
   if (local_work_size != NULL) 
     for (i = 0; i < work_dim; ++i) 
-      if (UNLIKELY(global_work_size[i] % local_work_size[i])) {
+      if (UNLIKELY(local_work_size[i] == 0 || global_work_size[i] % local_work_size[i])) {
         err = CL_INVALID_WORK_GROUP_SIZE;
         goto error;
       }