[Beignet] [PATCH] Fix several CL error code return bugs

Zhigang Gong zhigang.gong at linux.intel.com
Wed May 22 19:47:11 PDT 2013


LGTM. Pused. So after this commit, almost all the internal functions such as cl_xxx_xxx
will get a non-null errcode_ret parameter, you may consider to make another patch
to simplify those internal functions by using this assumption, thus we can remove
the redundant parameter checking code.

On Wed, May 22, 2013 at 09:02:20PM +0200, Dag Lem wrote:
> 
> Signed-off-by: Dag Lem <dag at nimrod.no>
> ---
>  src/cl_api.c     | 42 ++++++++++++++++++++++--------------------
>  src/cl_context.c |  1 +
>  2 files changed, 23 insertions(+), 20 deletions(-)
> 
> diff --git a/src/cl_api.c b/src/cl_api.c
> index a4e534a..f378296 100644
> --- a/src/cl_api.c
> +++ b/src/cl_api.c
> @@ -135,9 +135,10 @@ clCreateContextFromType(const cl_context_properties *  properties,
>                          void *                         user_data,
>                          cl_int *                       errcode_ret)
>  {
> +  cl_context context = NULL;
> +  cl_int err = CL_SUCCESS;
>    cl_device_id devices[1];
>    cl_uint num_devices = 1;
> -  cl_int err;
>  
>    err = cl_get_device_ids(NULL,
>                            device_type,
> @@ -145,16 +146,19 @@ clCreateContextFromType(const cl_context_properties *  properties,
>                            &devices[0],
>                            &num_devices);
>    if (err != CL_SUCCESS) {
> -    *errcode_ret = err;
> -    return NULL;
> +    goto error;
>    }
>  
> -  return cl_create_context(properties,
> -                           num_devices,
> -                           devices,
> -                           pfn_notify,
> -                           user_data,
> -                           errcode_ret);
> +  context = cl_create_context(properties,
> +                              num_devices,
> +                              devices,
> +                              pfn_notify,
> +                              user_data,
> +                              &err);
> +error:
> +  if (errcode_ret)
> +    *errcode_ret = err;
> +  return context;
>  }
>  
>  cl_int
> @@ -214,9 +218,11 @@ clCreateCommandQueue(cl_context                   context,
>    cl_command_queue queue = NULL;
>    cl_int err = CL_SUCCESS;
>    CHECK_CONTEXT (context);
> -  queue = cl_context_create_queue(context, device, properties, errcode_ret);
> +  queue = cl_context_create_queue(context, device, properties, &err);
>  error:
> -  return err == CL_SUCCESS ? queue : NULL;
> +  if (errcode_ret)
> +    *errcode_ret = err;
> +  return queue;
>  }
>  
>  cl_int
> @@ -349,7 +355,7 @@ clCreateImage2D(cl_context              context,
>                           image_format,
>                           &image_desc,
>                           host_ptr,
> -                         errcode_ret);
> +                         &err);
>  error:
>    if (errcode_ret)
>      *errcode_ret = err;
> @@ -385,7 +391,7 @@ clCreateImage3D(cl_context              context,
>                           image_format,
>                           &image_desc,
>                           host_ptr,
> -                         errcode_ret);
> +                         &err);
>  error:
>    if (errcode_ret)
>      *errcode_ret = err;
> @@ -668,14 +674,12 @@ clCreateKernel(cl_program   program,
>      err = CL_INVALID_PROGRAM_EXECUTABLE;
>      goto error;
>    }
> -  kernel = cl_program_create_kernel(program, kernel_name, errcode_ret);
> +  kernel = cl_program_create_kernel(program, kernel_name, &err);
>  
> -exit:
> -  return kernel;
>  error:
>    if (errcode_ret)
>      *errcode_ret = err;
> -  goto exit;
> +  return kernel;
>  }
>  
>  cl_int
> @@ -835,10 +839,8 @@ clFinish(cl_command_queue command_queue)
>    CHECK_QUEUE (command_queue);
>    err = cl_command_queue_finish(command_queue);
>  
> -exit:
> -  return err;
>  error:
> -  goto exit;
> +  return err;
>  }
>  
>  cl_int
> diff --git a/src/cl_context.c b/src/cl_context.c
> index 4a1925c..fc75d62 100644
> --- a/src/cl_context.c
> +++ b/src/cl_context.c
> @@ -225,6 +225,7 @@ exit:
>    return queue;
>  error:
>    cl_command_queue_delete(queue);
> +  queue = NULL;
>    goto exit;
>  }
>  
> -- 
> 1.8.1.4
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list