Skip to contentSkip to conversation

dma-buf/dma_fence_array: Annotate fences with __counted_by_ptr

PATCH New Bill Wendling 1 participant 1 message Sep 28 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-buf/dma_fence_array: Annotate fences with __counted_by_ptr

The 'struct dma_fence_array' holds a pointer field 'fences' that points to an array of 'dma_fence' pointers, and its element count is stored in the 'num_fences' field within the same structure.

Annotate 'fences' with the '__counted_by_ptr' attribute to allow compilers supporting this attribute to perform runtime bounds checking via KASAN and '__builtin_dynamic_object_size'.

The structure is allocated in 'dma_fence_array_alloc()' which initializes all fields, including 'fences' and 'num_fences', to zero. The structure is initialized in 'dma_fence_array_init()'.

---
 include/linux/dma-fence-array.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/dma-fence-array.h +1 -1
index 0c49d7ccefb6..85e5879e8a1e 100644
@@ -39,7 +39,7 @@ struct dma_fence_array {
 
 	unsigned num_fences;
 	atomic_t num_pending;
-	struct dma_fence **fences;
+	struct dma_fence **fences __counted_by_ptr(num_fences);
 
 	struct irq_work work;
 
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog