Refine error check in clGetPlatformIDs() and clGetPlatformInfo()
authorRuiling Song <ruiling.song@intel.com>
Thu, 6 Jun 2013 07:07:16 +0000 (15:07 +0800)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Thu, 6 Jun 2013 09:38:16 +0000 (17:38 +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_khr_icd.c
src/cl_platform_id.c

index 5ef95b7..e710147 100644 (file)
@@ -42,6 +42,11 @@ clGetPlatformIDs(cl_uint          num_entries,
                  cl_platform_id * platforms,
                  cl_uint *        num_platforms)
 {
+  if(UNLIKELY(platforms == NULL && num_platforms == NULL))
+    return CL_INVALID_VALUE;
+  if(UNLIKELY(num_entries == 0 && platforms != NULL))
+    return CL_INVALID_VALUE;
+
   return cl_get_platform_ids(num_entries, platforms, num_platforms);
 }
 
@@ -52,6 +57,10 @@ clGetPlatformInfo(cl_platform_id    platform,
                   void *            param_value,
                   size_t *          param_value_size_ret)
 {
+  /* Only one platform. This is easy */
+  if (UNLIKELY(platform != NULL && platform != intel_platform))
+    return CL_INVALID_PLATFORM;
+
   return cl_get_platform_info(platform,
                               param_name,
                               param_value_size,
index 5f0180a..d601134 100644 (file)
@@ -43,7 +43,7 @@ clIcdGetPlatformIDsKHR(cl_uint          num_entries,
                  cl_platform_id * platforms,
                  cl_uint *        num_platforms)
 {
-  return cl_get_platform_ids(num_entries, platforms, num_platforms);
+  return clGetPlatformIDs(num_entries, platforms, num_platforms);
 }
 
 struct _cl_icd_dispatch const cl_khr_icd_dispatch = {
index 2f66064..2e0a86a 100644 (file)
@@ -51,22 +51,11 @@ cl_get_platform_ids(cl_uint          num_entries,
 {
   if (num_platforms != NULL)
     *num_platforms = 1;
-  if (UNLIKELY(platforms == NULL))
-    return CL_SUCCESS;
-  if (UNLIKELY(num_entries == 0))
-    return CL_INVALID_VALUE;
-  if (UNLIKELY(num_platforms == NULL && platforms == NULL))
-    return CL_SUCCESS;
-#if 0
-  if (UNLIKELY(num_platforms == NULL && platforms != NULL))
-    return CL_INVALID_VALUE;
-#endif
-  if (UNLIKELY(num_platforms != NULL && platforms == NULL))
-    return CL_INVALID_VALUE;
 
   cl_intel_platform_extension_init(intel_platform);
   /* Easy right now, only one platform is supported */
-  *platforms = intel_platform;
+  if(platforms)
+    *platforms = intel_platform;
   intel_platform->extensions_sz = strlen(intel_platform->extensions) + 1;
   return CL_SUCCESS;
 }
@@ -95,10 +84,6 @@ cl_get_platform_info(cl_platform_id    platform,
                      void *            param_value,
                      size_t *          param_value_size_ret)
 {
-  /* Only one platform. This is easy */
-  if (UNLIKELY(platform != NULL && platform != intel_platform))
-    return CL_INVALID_PLATFORM;
-
   if (param_value == NULL) {
     switch (param_name) {
       GET_FIELD_SZ (PLATFORM_PROFILE,    profile);