On 12/2/26 10:01, Tvrtko Ursulin wrote:
> On 01/12/2026 16:55, Christian König wrote:
...
>> -struct dma_fence *dma_fence_unwrap_next(struct dma_fence_unwrap *cursor)
>> +void dma_fence_unwrap_next(struct dma_fence_unwrap *cursor,
>> + struct dma_fence **fence)
>> {
>> - struct dma_fence *tmp;
>> -
>> ++cursor->index;
>> - tmp = dma_fence_array_next(cursor->array, cursor->index);
>> - if (tmp)
>> - return tmp;
>> + *fence = dma_fence_array_next(cursor->array, cursor->index);
>> + if (*fence)
>> + return;
>> cursor->chain = dma_fence_chain_walk(cursor->chain);
>> - return __dma_fence_unwrap_array(cursor);
>> + __dma_fence_unwrap_array(cursor, fence);
>
> Did something require changing the prototype to return via argument pointer?
> I can't spot it straight away and if really did not, isn't it nicer to keep
> returning as return value?
In dma_fence_unwrap_next() function it is not a must have, but it is to get the
dma_fence_unwrap_first() function right. So I changed all uses for consistency.
>> diff --git a/drivers/gpu/drm/tegra/submit.c b/drivers/gpu/drm/tegra/submit.c
>> index 5db37856db123..3d4db12a8c13f 100644
>> --- a/drivers/gpu/drm/tegra/submit.c
>> +++ b/drivers/gpu/drm/tegra/submit.c
>> @@ -353,14 +353,13 @@ static int submit_get_syncpt(struct tegra_drm_context
>> *context, struct host1x_jo
>> static int submit_handle_in_fence(struct tegra_drm_context *context,
>> struct host1x *host1x,
>> struct dma_fence *fence, u32 *num_waits)
>> {
>> - struct dma_fence_unwrap iter;
>> struct host1x *fence_host1x;
>> struct dma_fence *f;
>> int err = 0;
>> *num_waits = 0;
>> - dma_fence_unwrap_for_each(f, &iter, fence) {
>> + dma_fence_unwrap_for_each(f, fence) {
>> long wait_err;
>> if (err)
>
> This one is if (err) continue which could be the same "keep iterating to
> avoid reference leaks" workaround as in pvr_sync_add_dep_to_job.
Good point, that can trivially be cleaned up as well.
>> diff --git a/include/linux/dma-fence-unwrap.h
>> b/include/linux/dma-fence-unwrap.h
>> index 7bfacdf79de21..1829e2a655b95 100644
>> --- a/include/linux/dma-fence-unwrap.h
>> +++ b/include/linux/dma-fence-unwrap.h
>> @@ -32,27 +32,33 @@ struct dma_fence_unwrap {
>> unsigned int index;
>> };
>> -struct dma_fence *dma_fence_unwrap_first(struct dma_fence *head,
>> - struct dma_fence_unwrap *cursor);
>> -struct dma_fence *dma_fence_unwrap_next(struct dma_fence_unwrap *cursor);
>> +struct dma_fence_unwrap dma_fence_unwrap_first(struct dma_fence *head,
>> + struct dma_fence **fence);
>> +void dma_fence_unwrap_next(struct dma_fence_unwrap *cursor,
>> + struct dma_fence **fence);
>> +void dma_fence_unwrap_cleanup(struct dma_fence_unwrap *cursor);
>> +
>> +/* Helper for dma_fence_unwrap_for_each(). Internal use only. */
>> +#define __dma_fence_unwrap_for_each(fence, cursor, head) \
>> + for (struct dma_fence_unwrap cursor \
>> + __cleanup(dma_fence_unwrap_cleanup) \
>> + = dma_fence_unwrap_first(head, &(fence)); fence; \
>> + dma_fence_unwrap_next(&cursor, &(fence)))
>> /**
>> * dma_fence_unwrap_for_each - iterate over all fences in containers
>> * @fence: current fence
>> - * @cursor: current position inside the containers
>> * @head: starting point for the iterator
>> *
>> * Unwrap dma_fence_chain and dma_fence_array containers and deep dive
>> into all
>> * potential fences in them. If @head is just a normal fence only that one
>> is
>> * returned.
>> */
>
> So far kerneldoc had no mention of the problem with the reference. Assuming
> some people have learnt about it by now, and may skip that the problem is now
> gone, it should be worth documenting that the cleanup is automatic.
I will add a sentence about holding a reference which is cleaned up
automatically.
>> -#define dma_fence_unwrap_for_each(fence, cursor, head) \
>> - for (fence = dma_fence_unwrap_first(head, cursor); fence; \
>> - fence = dma_fence_unwrap_next(cursor))
>> +#define dma_fence_unwrap_for_each(fence, head) \
>> + __dma_fence_unwrap_for_each(fence, __UNIQUE_ID(cursor), head)
>> struct dma_fence *__dma_fence_unwrap_merge(size_t num_fences,
>> - struct dma_fence **fences,
>> - struct dma_fence_unwrap *cursors);
>> + struct dma_fence **fences);
>> size_t dma_fence_dedup_array(struct dma_fence **array, size_t
>> num_fences);
>> @@ -68,12 +74,11 @@ size_t dma_fence_dedup_array(struct dma_fence **array,
>> size_t num_fences);
>> * Returns NULL on memory allocation failure, a dma_fence object
>> representing
>> * all the given fences otherwise.
>> */
>> -#define dma_fence_unwrap_merge(...) \
>> - ({ \
>> - struct dma_fence *__f[] = { __VA_ARGS__ }; \
>> - struct dma_fence_unwrap __c[ARRAY_SIZE(__f)]; \
>> - \
>> - __dma_fence_unwrap_merge(ARRAY_SIZE(__f), __f, __c); \
>> +#define dma_fence_unwrap_merge(...) \
>> + ({ \
>> + struct dma_fence *__f[] = { __VA_ARGS__ }; \
>> + \
>> + __dma_fence_unwrap_merge(ARRAY_SIZE(__f), __f); \
>> })
>> #endif
>
> Looks mostly okay to me. Just those few small questions to address.
Thanks, going to fix those up.
Regards,
Christian.
>
> Regards,
>
> Tvrtko
>