int dma_resv_copy_fences()

in dma-resv.c [488:538]


int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)
{
	struct dma_resv_iter cursor;
	struct dma_resv_list *list;
	struct dma_fence *f, *excl;

	dma_resv_assert_held(dst);

	list = NULL;
	excl = NULL;

	dma_resv_iter_begin(&cursor, src, true);
	dma_resv_for_each_fence_unlocked(&cursor, f) {

		if (dma_resv_iter_is_restarted(&cursor)) {
			dma_resv_list_free(list);
			dma_fence_put(excl);

			if (cursor.shared_count) {
				list = dma_resv_list_alloc(cursor.shared_count);
				if (!list) {
					dma_resv_iter_end(&cursor);
					return -ENOMEM;
				}

				list->shared_count = 0;

			} else {
				list = NULL;
			}
			excl = NULL;
		}

		dma_fence_get(f);
		if (dma_resv_iter_is_exclusive(&cursor))
			excl = f;
		else
			RCU_INIT_POINTER(list->shared[list->shared_count++], f);
	}
	dma_resv_iter_end(&cursor);

	write_seqcount_begin(&dst->seq);
	excl = rcu_replace_pointer(dst->fence_excl, excl, dma_resv_held(dst));
	list = rcu_replace_pointer(dst->fence, list, dma_resv_held(dst));
	write_seqcount_end(&dst->seq);

	dma_resv_list_free(list);
	dma_fence_put(excl);

	return 0;
}