summaryrefslogtreecommitdiff
path: root/drivers/dma-buf
diff options
context:
space:
mode:
authorChristian König <ckoenig.leichtzumerken@gmail.com>2024-05-29 10:43:22 +0200
committerChristian König <christian.koenig@amd.com>2024-05-31 10:12:52 +0200
commitc9402efe492bb46ccbf94fedc4783eb8f8747567 (patch)
tree9e13353300e31e6340b00c6a11cdae66ab57f762 /drivers/dma-buf
parentc4e3267868e1debb3d87d21a36efc8a2255298e2 (diff)
downloadlwn-c9402efe492bb46ccbf94fedc4783eb8f8747567.tar.gz
lwn-c9402efe492bb46ccbf94fedc4783eb8f8747567.zip
dma-buf: add a warning when drv try to reserve 0 fence slots
When dma_resv_reserve_fences() is called with num_fences=0 it usually means that a driver or other component messed up its calculation how many fences are needed. Warn in that situation. When no fence are needed the function shouldn't be called in the first place. Signed-off-by: Christian König <christian.koenig@amd.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240529084322.2284-1-christian.koenig@amd.com Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Diffstat (limited to 'drivers/dma-buf')
-rw-r--r--drivers/dma-buf/dma-resv.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
index e2869fb31140..5f8d010516f0 100644
--- a/drivers/dma-buf/dma-resv.c
+++ b/drivers/dma-buf/dma-resv.c
@@ -186,6 +186,13 @@ int dma_resv_reserve_fences(struct dma_resv *obj, unsigned int num_fences)
dma_resv_assert_held(obj);
+ /* Driver and component code should never call this function with
+ * num_fences=0. If they do it usually points to bugs when calculating
+ * the number of needed fences dynamically.
+ */
+ if (WARN_ON(!num_fences))
+ return -EINVAL;
+
old = dma_resv_fences_list(obj);
if (old && old->max_fences) {
if ((old->num_fences + num_fences) <= old->max_fences)