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>
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;
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)