[PATCH libdrm 2/3] test/amdgpu: add proper error handling

Zhang, Jerry(Junwei) Jerry.Zhang at amd.com
Tue Sep 18 06:07:47 UTC 2018


On 09/14/2018 09:09 PM, Christian König wrote:
> Otherwise the calling function won't notice that something is wrong.
>
> Signed-off-by: Christian König <christian.koenig at amd.com>
> ---
>   tests/amdgpu/amdgpu_test.h | 23 ++++++++++++++++++++++-
>   1 file changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h
> index f2ece3c3..d1e14e23 100644
> --- a/tests/amdgpu/amdgpu_test.h
> +++ b/tests/amdgpu/amdgpu_test.h
> @@ -219,17 +219,31 @@ static inline amdgpu_bo_handle gpu_mem_alloc(
>   
>   	r = amdgpu_bo_alloc(device_handle, &req, &buf_handle);
>   	CU_ASSERT_EQUAL(r, 0);
> +	if (r)
> +		return NULL;
>   
>   	r = amdgpu_va_range_alloc(device_handle,
>   				  amdgpu_gpu_va_range_general,
>   				  size, alignment, 0, vmc_addr,
>   				  va_handle, 0);
>   	CU_ASSERT_EQUAL(r, 0);
> +	if (r)
> +		goto error_free_bo;
>   
>   	r = amdgpu_bo_va_op(buf_handle, 0, size, *vmc_addr, 0, AMDGPU_VA_OP_MAP);
>   	CU_ASSERT_EQUAL(r, 0);

We may also add error check for bo map.

Regards,
Jerry
>   
>   	return buf_handle;
> +
> +error_free_va:
> +	r = amdgpu_va_range_free(*va_handle);
> +	CU_ASSERT_EQUAL(r, 0);
> +
> +error_free_bo:
> +	r = amdgpu_bo_free(buf_handle);
> +	CU_ASSERT_EQUAL(r, 0);
> +
> +	return NULL;
>   }
>   
>   static inline int gpu_mem_free(amdgpu_bo_handle bo,
> @@ -239,16 +253,23 @@ static inline int gpu_mem_free(amdgpu_bo_handle bo,
>   {
>   	int r;
>   
> +	if (!bo)
> +		return 0;
> +
>   	r = amdgpu_bo_va_op(bo, 0, size, vmc_addr, 0, AMDGPU_VA_OP_UNMAP);
>   	CU_ASSERT_EQUAL(r, 0);
> +	if (r)
> +		return r;
>   
>   	r = amdgpu_va_range_free(va_handle);
>   	CU_ASSERT_EQUAL(r, 0);
> +	if (r)
> +		return r;
>   
>   	r = amdgpu_bo_free(bo);
>   	CU_ASSERT_EQUAL(r, 0);
>   
> -	return 0;
> +	return r;
>   }
>   
>   static inline int



More information about the amd-gfx mailing list