Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dma-buf: Add dma_fence_array_for_each (v2)

Add a helper to iterate over all fences in a dma_fence_array object.

v2 (Jason Ekstrand)
- Return NULL from dma_fence_array_first if head == NULL. This matches
the iterator behavior of dma_fence_chain_for_each in that it iterates
zero times if head == NULL.
- Return NULL from dma_fence_array_next if index > array->num_fences.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Christian König <christian.koenig@amd.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210610210925.642582-2-jason@jlekstrand.net
Signed-off-by: Christian König <christian.koenig@amd.com>

authored by

Christian König and committed by
Christian König
caaf2ae7 7344bad7

+44
+27
drivers/dma-buf/dma-fence-array.c
··· 219 219 return true; 220 220 } 221 221 EXPORT_SYMBOL(dma_fence_match_context); 222 + 223 + struct dma_fence *dma_fence_array_first(struct dma_fence *head) 224 + { 225 + struct dma_fence_array *array; 226 + 227 + if (!head) 228 + return NULL; 229 + 230 + array = to_dma_fence_array(head); 231 + if (!array) 232 + return head; 233 + 234 + return array->fences[0]; 235 + } 236 + EXPORT_SYMBOL(dma_fence_array_first); 237 + 238 + struct dma_fence *dma_fence_array_next(struct dma_fence *head, 239 + unsigned int index) 240 + { 241 + struct dma_fence_array *array = to_dma_fence_array(head); 242 + 243 + if (!array || index >= array->num_fences) 244 + return NULL; 245 + 246 + return array->fences[index]; 247 + } 248 + EXPORT_SYMBOL(dma_fence_array_next);
+17
include/linux/dma-fence-array.h
··· 61 61 return container_of(fence, struct dma_fence_array, base); 62 62 } 63 63 64 + /** 65 + * dma_fence_array_for_each - iterate over all fences in array 66 + * @fence: current fence 67 + * @index: index into the array 68 + * @head: potential dma_fence_array object 69 + * 70 + * Test if @array is a dma_fence_array object and if yes iterate over all fences 71 + * in the array. If not just iterate over the fence in @array itself. 72 + */ 73 + #define dma_fence_array_for_each(fence, index, head) \ 74 + for (index = 0, fence = dma_fence_array_first(head); fence; \ 75 + ++(index), fence = dma_fence_array_next(head, index)) 76 + 64 77 struct dma_fence_array *dma_fence_array_create(int num_fences, 65 78 struct dma_fence **fences, 66 79 u64 context, unsigned seqno, 67 80 bool signal_on_any); 68 81 69 82 bool dma_fence_match_context(struct dma_fence *fence, u64 context); 83 + 84 + struct dma_fence *dma_fence_array_first(struct dma_fence *head); 85 + struct dma_fence *dma_fence_array_next(struct dma_fence *head, 86 + unsigned int index); 70 87 71 88 #endif /* __LINUX_DMA_FENCE_ARRAY_H */