[Beignet] [PATCH 1/3] Refine error check in clGetPlatformIDs() and clGetPlatformInfo()

Ruiling Song ruiling.song at intel.com
Thu Jun 6 00:07:16 PDT 2013


Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
 src/cl_api.c         |    9 +++++++++
 src/cl_khr_icd.c     |    2 +-
 src/cl_platform_id.c |   19 ++-----------------
 3 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/src/cl_api.c b/src/cl_api.c
index 5ef95b7..e710147 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -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,
diff --git a/src/cl_khr_icd.c b/src/cl_khr_icd.c
index 5f0180a..d601134 100644
--- a/src/cl_khr_icd.c
+++ b/src/cl_khr_icd.c
@@ -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 = {
diff --git a/src/cl_platform_id.c b/src/cl_platform_id.c
index 2f66064..2e0a86a 100644
--- a/src/cl_platform_id.c
+++ b/src/cl_platform_id.c
@@ -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);
-- 
1.7.9.5



More information about the Beignet mailing list