From: Ruiling Song Date: Thu, 13 Jun 2013 01:40:17 +0000 (+0800) Subject: Refine error check in clCreateProgramFromSource() and clCreateKernel() X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8a6f1bfc48317a15faa2dd111df0d2566f73801a;p=contrib%2Fbeignet.git Refine error check in clCreateProgramFromSource() and clCreateKernel() Signed-off-by: Ruiling Song Reviewed-by: Zhigang Gong --- diff --git a/src/cl_api.c b/src/cl_api.c index fd707e5..f14bee4 100644 --- a/src/cl_api.c +++ b/src/cl_api.c @@ -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: diff --git a/src/cl_program.c b/src/cl_program.c index 0c48ef3..6acf31f 100644 --- a/src/cl_program.c +++ b/src/cl_program.c @@ -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]);