Skip to contentSkip to conversation

dma-buf: add a warning when drv try to reserve 0 fence slots

PATCH In review Christian König 2 participants 2 messages May 29, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/dma-buf/dma-resv.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/dma-buf/dma-resv.c +7 -0
index e2869fb31140..5f8d010516f0 100644
@@ -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)
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Christian König

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.