Re: [PATCH 2/6] dma-resv: Define guards for context-less dma_resv locks

From: Chia-I Wu

Date: Thu May 14 2026 - 14:24:15 EST


On Wed, May 13, 2026 at 10:09 AM Boris Brezillon
<boris.brezillon@xxxxxxxxxxxxx> wrote:
>
> When used without a context, dma_resv are no different from regular
> locks. Define guards so we can use the guard-syntactic sugars for
> explicit/implicit scoped locks.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxx>
Reviewed-by: Chia-I Wu <olvaffe@xxxxxxxxx>
> ---
> include/linux/dma-resv.h | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h
> index c5ab6fd9ebe8..e559b1811ca3 100644
> --- a/include/linux/dma-resv.h
> +++ b/include/linux/dma-resv.h
> @@ -40,6 +40,7 @@
> #define _LINUX_RESERVATION_H
>
> #include <linux/ww_mutex.h>
> +#include <linux/cleanup.h>
> #include <linux/dma-fence.h>
> #include <linux/slab.h>
> #include <linux/seqlock.h>
> @@ -484,4 +485,8 @@ void dma_resv_set_deadline(struct dma_resv *obj, enum dma_resv_usage usage,
> bool dma_resv_test_signaled(struct dma_resv *obj, enum dma_resv_usage usage);
> void dma_resv_describe(struct dma_resv *obj, struct seq_file *seq);
>
> +DEFINE_GUARD(dma_resv, struct dma_resv *, dma_resv_lock(_T, NULL), dma_resv_unlock(_T));
> +DEFINE_GUARD_COND(dma_resv, _intr, dma_resv_lock_interruptible(_T, NULL), !_RET);
> +DEFINE_GUARD_COND(dma_resv, _try, dma_resv_trylock(_T));
> +
> #endif /* _LINUX_RESERVATION_H */
>
> --
> 2.54.0
>