int dma_resv_get_fences()

in dma-resv.c [554:600]


int dma_resv_get_fences(struct dma_resv *obj, struct dma_fence **fence_excl,
			unsigned int *shared_count, struct dma_fence ***shared)
{
	struct dma_resv_iter cursor;
	struct dma_fence *fence;

	*shared_count = 0;
	*shared = NULL;

	if (fence_excl)
		*fence_excl = NULL;

	dma_resv_iter_begin(&cursor, obj, true);
	dma_resv_for_each_fence_unlocked(&cursor, fence) {

		if (dma_resv_iter_is_restarted(&cursor)) {
			unsigned int count;

			while (*shared_count)
				dma_fence_put((*shared)[--(*shared_count)]);

			if (fence_excl)
				dma_fence_put(*fence_excl);

			count = cursor.shared_count;
			count += fence_excl ? 0 : 1;

			/* Eventually re-allocate the array */
			*shared = krealloc_array(*shared, count,
						 sizeof(void *),
						 GFP_KERNEL);
			if (count && !*shared) {
				dma_resv_iter_end(&cursor);
				return -ENOMEM;
			}
		}

		dma_fence_get(fence);
		if (dma_resv_iter_is_exclusive(&cursor) && fence_excl)
			*fence_excl = fence;
		else
			(*shared)[(*shared_count)++] = fence;
	}
	dma_resv_iter_end(&cursor);

	return 0;
}