On Tue,  1 Dec 2026 17:55:59 +0100
"Christian König" <[email protected]> wrote:

> The macro dma_fence_unwrap_for_each() is used to deep dive into fences in
> chain and array containers.
> 
> To guarantee correct functionality it does this by keeping a reference to
> chain elements in the iterator structure. But so far there was no well
> defined cleanup procedure for the iterator when breaking out of the loop
> early.
> 
> Some code implemented dropping the reference manually, but Erhan now found
> another issue in an error path in amdgpu.
> 
> Fix this for good, provide a proper cleanup function which is
> automatically used with a guard and remove the workarounds spread around
> in the calling code.
> 
> Signed-off-by: Christian König <[email protected]>

Thanks for pushing that through, I've rebased my panthor changes on top
and will post a new version shortly.

> Reported-by: Erhan Bilgili <[email protected]>
> ---
>  drivers/dma-buf/dma-buf.c                     |  5 +-
>  drivers/dma-buf/dma-fence-unwrap.c            | 58 ++++++++++++-------
>  drivers/dma-buf/st-dma-fence-unwrap.c         | 27 +++------
>  drivers/dma-buf/sync_file.c                   |  5 +-
>  .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   |  6 +-
>  drivers/gpu/drm/imagination/pvr_sync.c        | 14 ++---
>  drivers/gpu/drm/tegra/submit.c                |  6 +-
>  drivers/gpu/drm/virtio/virtgpu_submit.c       |  7 +--
>  include/linux/dma-fence-unwrap.h              | 35 ++++++-----

The core changes are

Reviewed-by: Boris Brezillon <[email protected]>

just one comment below.


> +/**
> + * dma_fence_unwrap_cleanup - cleanup the cursor should we exit early
> + * @cursor: current position inside the containers
> + *
> + * Drop the fence reference inside the cursor should we exit the unwrap loop
> + * early.
> + */
> +void dma_fence_unwrap_cleanup(struct dma_fence_unwrap *cursor)
> +{
> +     dma_fence_put(cursor->chain);
> +}
> +EXPORT_SYMBOL_GPL(dma_fence_unwrap_cleanup);

This feels like a good candidate for a static inline declaration in
dma-fence-unwrap.h. This way, the compiler can see through it and
inline things. I guess LTO could to that too, but I tend to think it's
slightly better when this sort of inlining is done at compile time.

Reply via email to