[RFC 02/12] dma-fence: Add callback initialization helper
Tvrtko Ursulin
tvrtko.ursulin at linux.intel.com
Tue Mar 7 10:48:14 UTC 2023
From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
In preparation of adding a new field to struct dma_fence_cb we will need
an initialization helper for those callers who add callbacks by open-
coding. That will ensure they initialize all the fields so common code
does not get confused by potential garbage in some fields.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
drivers/dma-buf/dma-fence.c | 10 ++++------
include/linux/dma-fence.h | 7 +++++++
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index 41da0da17eba..ea4a1f82c9bf 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -662,21 +662,19 @@ int dma_fence_add_callback(struct dma_fence *fence, struct dma_fence_cb *cb,
unsigned long flags;
int ret = 0;
+ __dma_fence_cb_init(cb, func);
+
if (WARN_ON(!fence || !func))
return -EINVAL;
- if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
- INIT_LIST_HEAD(&cb->node);
+ if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
return -ENOENT;
- }
spin_lock_irqsave(fence->lock, flags);
if (__dma_fence_enable_signaling(fence)) {
- cb->func = func;
list_add_tail(&cb->node, &fence->cb_list);
} else {
- INIT_LIST_HEAD(&cb->node);
ret = -ENOENT;
}
@@ -795,7 +793,7 @@ dma_fence_default_wait(struct dma_fence *fence, bool intr, signed long timeout)
goto out;
}
- cb.base.func = dma_fence_default_wait_cb;
+ __dma_fence_cb_init(&cb.base, dma_fence_default_wait_cb);
cb.task = current;
list_add(&cb.base.node, &fence->cb_list);
diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
index 2af328a89468..35933e0ae62c 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -629,4 +629,11 @@ static inline bool dma_fence_is_container(struct dma_fence *fence)
return dma_fence_is_array(fence) || dma_fence_is_chain(fence);
}
+static inline void __dma_fence_cb_init(struct dma_fence_cb *cb,
+ dma_fence_func_t func)
+{
+ INIT_LIST_HEAD(&cb->node);
+ cb->func = func;
+}
+
#endif /* __LINUX_DMA_FENCE_H */
--
2.37.2
More information about the dri-devel
mailing list