amdgpu: Cleanly handle ENOMEM on result in amdgpu_bo_list_create()
Move the allocation of result prior to the IOCTL so we can cleanly backtrack if the allocation fails. Signed-off-by: Tom St Denis <tom.stdenis@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com>main
parent
1a6a8f34a0
commit
b176372af4
|
@ -591,6 +591,12 @@ int amdgpu_bo_list_create(amdgpu_device_handle dev,
|
||||||
if (!list)
|
if (!list)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
*result = malloc(sizeof(struct amdgpu_bo_list));
|
||||||
|
if (!*result) {
|
||||||
|
free(list);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
memset(&args, 0, sizeof(args));
|
memset(&args, 0, sizeof(args));
|
||||||
args.in.operation = AMDGPU_BO_LIST_OP_CREATE;
|
args.in.operation = AMDGPU_BO_LIST_OP_CREATE;
|
||||||
args.in.bo_number = number_of_resources;
|
args.in.bo_number = number_of_resources;
|
||||||
|
@ -608,10 +614,11 @@ int amdgpu_bo_list_create(amdgpu_device_handle dev,
|
||||||
r = drmCommandWriteRead(dev->fd, DRM_AMDGPU_BO_LIST,
|
r = drmCommandWriteRead(dev->fd, DRM_AMDGPU_BO_LIST,
|
||||||
&args, sizeof(args));
|
&args, sizeof(args));
|
||||||
free(list);
|
free(list);
|
||||||
if (r)
|
if (r) {
|
||||||
|
free(*result);
|
||||||
return r;
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
*result = malloc(sizeof(struct amdgpu_bo_list));
|
|
||||||
(*result)->dev = dev;
|
(*result)->dev = dev;
|
||||||
(*result)->handle = args.out.list_handle;
|
(*result)->handle = args.out.list_handle;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue