summaryrefslogtreecommitdiff
path: root/amdgpu
diff options
context:
space:
mode:
authorTom St Denis <tom.stdenis@amd.com>2015-10-09 12:46:40 -0400
committerAlex Deucher <alexander.deucher@amd.com>2015-10-22 12:36:55 -0400
commitb176372af4c773de188fae67e334e2a83c5706e3 (patch)
tree6c20579f62bd32d016c699eb851bc8fe3c9a364b /amdgpu
parent1a6a8f34a0b17ac03f42bac416e5d289f9c3248f (diff)
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>
Diffstat (limited to 'amdgpu')
-rw-r--r--amdgpu/amdgpu_bo.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index 348da003..1a5a4011 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -591,6 +591,12 @@ int amdgpu_bo_list_create(amdgpu_device_handle dev,
if (!list)
return -ENOMEM;
+ *result = malloc(sizeof(struct amdgpu_bo_list));
+ if (!*result) {
+ free(list);
+ return -ENOMEM;
+ }
+
memset(&args, 0, sizeof(args));
args.in.operation = AMDGPU_BO_LIST_OP_CREATE;
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,
&args, sizeof(args));
free(list);
- if (r)
+ if (r) {
+ free(*result);
return r;
+ }
- *result = malloc(sizeof(struct amdgpu_bo_list));
(*result)->dev = dev;
(*result)->handle = args.out.list_handle;
return 0;