[PATCH v15 11/23] dma-resv: Add kref_put_dma_resv()

From: Dmitry Osipenko
Date: Sun Aug 27 2023 - 14:12:29 EST


Add simple kref_put_dma_resv() helper that wraps around kref_put_ww_mutex()
for drivers that needs to lock dma-resv on kref_put().

It's not possible to easily add this helper to kref.h because of the
headers inclusion dependency, hence add it to dma-resv.h.

Signed-off-by: Dmitry Osipenko <dmitry.osipenko@xxxxxxxxxxxxx>
---
include/linux/dma-resv.h | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h
index 8d0e34dad446..c5cf302e4194 100644
--- a/include/linux/dma-resv.h
+++ b/include/linux/dma-resv.h
@@ -41,6 +41,7 @@

#include <linux/ww_mutex.h>
#include <linux/dma-fence.h>
+#include <linux/kref.h>
#include <linux/slab.h>
#include <linux/seqlock.h>
#include <linux/rcupdate.h>
@@ -464,6 +465,14 @@ static inline void dma_resv_unlock(struct dma_resv *obj)
ww_mutex_unlock(&obj->lock);
}

+static inline int kref_put_dma_resv(struct kref *kref,
+ void (*release)(struct kref *kref),
+ struct dma_resv *resv,
+ struct ww_acquire_ctx *ctx)
+{
+ return kref_put_ww_mutex(kref, release, &resv->lock, ctx);
+}
+
void dma_resv_init(struct dma_resv *obj);
void dma_resv_fini(struct dma_resv *obj);
int dma_resv_reserve_fences(struct dma_resv *obj, unsigned int num_fences);
--
2.41.0