[PATCH 1/2] dma-buf: add dma_fence_chain_for_each_unwrap helper

Chris Wilson chris at chris-wilson.co.uk
Tue Jul 30 19:23:39 UTC 2019


Quoting Christian König (2019-07-30 13:15:53)
> +/**
> + * dma_fence_chain_unwrap - unwrap chain node
> + * @fence: fence which could be a chain node
> + *
> + * If the paramter is a chain node return the cotained fence, otherwise return
> + * the parameter itself.
> + */

s/paramter/parameter/
s/cotained/contained/

> +static inline struct dma_fence *
> +dma_fence_chain_unwrap(struct dma_fence *fence)
> +{
> +       struct dma_fence_chain *chain = to_dma_fence_chain(fence);
> +
> +       if (!chain)
> +               return fence;
> +
> +       return chain->fence;
> +}

> +/**
> + * dma_fence_chain_for_each_unwrap - iterate over all unwrapped fences in chain
> + * @fence: the unwrapped fence
> + * @iter: current fence
> + * @head: starting point
> + *
> + * Iterate over all fences in the chain with unwrapping. We keep a reference to
> + * the current fence while inside the loop which must be dropped when breaking
> + * out.
> + */
> +#define dma_fence_chain_for_each_unwrap(fence, iter, head)     \
> +       for (iter = dma_fence_get(head),                        \
> +            fence = dma_fence_chain_unwrap(iter);              \
> +            iter; iter = dma_fence_chain_walk(iter),           \
> +            fence = dma_fence_chain_unwrap(iter))

Why not
for (iter = dma_fence_get(head);
	(fence = dma_fence_chain_unwrap(iter));
	iter = dma_fence_chain_walk(iter))
? It doesn't look like dma_fence_chain_unwrap() can legally return NULL,
but if you pass NULL to unwrap it returns NULL.

I'd vote for dma_fence_chain_for_each_fence() in the spirit of
list_for_each_entry().
-Chris


More information about the dri-devel mailing list