summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJammy Zhou <Jammy.Zhou@amd.com>2015-05-18 20:57:41 +0800
committerAlex Deucher <alexander.deucher@amd.com>2015-07-30 00:11:10 -0400
commitace7d68edacfa1d0f0cf1f6577f2b02d1768b4bb (patch)
tree001ecfcfa4ebb623b556e8aae5a4ed69e0500b18
parenta7e7c3dfc297d144b7e09ced48dbf39ebb4ad464 (diff)
amdgpu: replace alloca with calloc v2
use heap memory instead of stack memory to avoid potential stack overflow when a large number of resources are used for the bo_list. v2: some minor improvement Signed-off-by: Jammy Zhou <Jammy.Zhou@amd.com> Reviewed-by: Michel Dänzer <michel.daenzer@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com>
-rw-r--r--amdgpu/amdgpu_bo.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index d78bb9a8..3dfaf62f 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -666,7 +666,10 @@ int amdgpu_bo_list_create(amdgpu_device_handle dev,
unsigned i;
int r;
- list = alloca(sizeof(struct drm_amdgpu_bo_list_entry) * number_of_resources);
+ list = calloc(number_of_resources, sizeof(struct drm_amdgpu_bo_list_entry));
+
+ if (list == NULL)
+ return -ENOMEM;
memset(&args, 0, sizeof(args));
args.in.operation = AMDGPU_BO_LIST_OP_CREATE;
@@ -685,12 +688,14 @@ int amdgpu_bo_list_create(amdgpu_device_handle dev,
r = drmCommandWriteRead(dev->fd, DRM_AMDGPU_BO_LIST,
&args, sizeof(args));
if (r)
- return r;
+ goto out;
*result = calloc(1, sizeof(struct amdgpu_bo_list));
(*result)->dev = dev;
(*result)->handle = args.out.list_handle;
- return 0;
+out:
+ free(list);
+ return r;
}
int amdgpu_bo_list_destroy(amdgpu_bo_list_handle list)