[PATCH 2/2] dma-buf: add dma_fence_chain_(alloc|free)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Wrap kmalloc/kfree to allow switching to a slab allocator later on.

Signed-off-by: Christian König <christian.koenig@xxxxxxx>
---
 drivers/dma-buf/dma-fence-chain.c      |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c |  6 +++---
 drivers/gpu/drm/drm_syncobj.c          |  2 +-
 include/linux/dma-fence-chain.h        | 24 ++++++++++++++++++++++++
 4 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c
index 6c3a615731b4..56183dc9f787 100644
--- a/drivers/dma-buf/dma-fence-chain.c
+++ b/drivers/dma-buf/dma-fence-chain.c
@@ -186,7 +186,7 @@ static void dma_fence_chain_release(struct dma_fence *fence)
 
 	dma_fence_put(rcu_dereference_protected(chain->prev, true));
 	dma_fence_put(chain->fence);
-	dma_fence_free(fence);
+	dma_fence_chain_free(chain);
 }
 
 const struct dma_fence_ops dma_fence_chain_ops = {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index def029ab5657..4b1e4b321999 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -758,7 +758,7 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
 
 	for (i = 0; i < parser->num_post_deps; i++) {
 		drm_syncobj_put(parser->post_deps[i].syncobj);
-		kfree(parser->post_deps[i].chain);
+		dma_fence_chain_free(parser->post_deps[i].chain);
 	}
 	kfree(parser->post_deps);
 
@@ -1187,7 +1187,7 @@ static int amdgpu_cs_process_syncobj_timeline_out_dep(struct amdgpu_cs_parser *p
 
 		dep->chain = NULL;
 		if (syncobj_deps[i].point) {
-			dep->chain = kmalloc(sizeof(*dep->chain), GFP_KERNEL);
+			dep->chain = dma_fence_chain_alloc();
 			if (!dep->chain)
 				return -ENOMEM;
 		}
@@ -1195,7 +1195,7 @@ static int amdgpu_cs_process_syncobj_timeline_out_dep(struct amdgpu_cs_parser *p
 		dep->syncobj = drm_syncobj_find(p->filp,
 						syncobj_deps[i].handle);
 		if (!dep->syncobj) {
-			kfree(dep->chain);
+			dma_fence_chain_free(dep->chain);
 			return -EINVAL;
 		}
 		dep->point = syncobj_deps[i].point;
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index cecff2e447b1..fc73f398e738 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -696,7 +696,7 @@ static int drm_syncobj_transfer_to_timeline(struct drm_file *file_private,
 				     &fence);
 	if (ret)
 		goto err;
-	chain = kzalloc(sizeof(struct dma_fence_chain), GFP_KERNEL);
+	chain = dma_fence_chain_alloc();
 	if (!chain) {
 		ret = -ENOMEM;
 		goto err1;
diff --git a/include/linux/dma-fence-chain.h b/include/linux/dma-fence-chain.h
index 7466d7b8837e..b84e28661d48 100644
--- a/include/linux/dma-fence-chain.h
+++ b/include/linux/dma-fence-chain.h
@@ -18,6 +18,7 @@
 #ifndef __LINUX_DMA_FENCE_CHAIN_H
 #define __LINUX_DMA_FENCE_CHAIN_H
 
+#include <linux/slab.h>
 #include <linux/dma-fence.h>
 #include <linux/irq_work.h>
 
@@ -43,6 +44,29 @@ struct dma_fence_chain {
 
 extern const struct dma_fence_ops dma_fence_chain_ops;
 
+/**
+ * dma_fence_chain_alloc - wrapper to allocate a dma_fence_chain
+ *
+ * Wrap the kmalloc for now to easier switch to a slub allocator.
+ *
+ * Returns an allocated dma_fence_chain or NULL.
+ */
+static inline struct dma_fence_chain *dma_fence_chain_alloc(void)
+{
+	return kmalloc(sizeof(struct dma_fence_chain), GFP_KERNEL);
+}
+
+/**
+ * dma_fence_chain_free - wrapper to free a dma_fence_chain
+ * @chain: the chain we need to free.
+ *
+ * Wrap the dma_fence_free for now to easier switch to a slub allocator.
+ */
+static inline void dma_fence_chain_free(struct dma_fence_chain *chain)
+{
+	dma_fence_free(&chain->base);
+}
+
 /**
  * to_dma_fence_chain - cast a fence to a dma_fence_chain
  * @fence: fence to cast to a dma_fence_array
-- 
2.17.1

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux