Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dma-buf: Split out dma fence array create into alloc and arm functions

Useful to preallocate dma fence array and then arm in path of reclaim or
a dma fence.

v2:
- s/arm/init (Christian)
- Drop !array warn (Christian)
v3:
- Fix kernel doc typos (dim)

Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Christian König <christian.koenig@amd.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240826170144.2492062-2-matthew.brost@intel.com

+63 -21
+57 -21
drivers/dma-buf/dma-fence-array.c
··· 144 144 EXPORT_SYMBOL(dma_fence_array_ops); 145 145 146 146 /** 147 - * dma_fence_array_create - Create a custom fence array 147 + * dma_fence_array_alloc - Allocate a custom fence array 148 + * @num_fences: [in] number of fences to add in the array 149 + * 150 + * Return dma fence array on success, NULL on failure 151 + */ 152 + struct dma_fence_array *dma_fence_array_alloc(int num_fences) 153 + { 154 + struct dma_fence_array *array; 155 + 156 + return kzalloc(struct_size(array, callbacks, num_fences), GFP_KERNEL); 157 + } 158 + EXPORT_SYMBOL(dma_fence_array_alloc); 159 + 160 + /** 161 + * dma_fence_array_init - Init a custom fence array 162 + * @array: [in] dma fence array to arm 148 163 * @num_fences: [in] number of fences to add in the array 149 164 * @fences: [in] array containing the fences 150 165 * @context: [in] fence context to use 151 166 * @seqno: [in] sequence number to use 152 167 * @signal_on_any: [in] signal on any fence in the array 153 168 * 154 - * Allocate a dma_fence_array object and initialize the base fence with 155 - * dma_fence_init(). 156 - * In case of error it returns NULL. 157 - * 158 - * The caller should allocate the fences array with num_fences size 159 - * and fill it with the fences it wants to add to the object. Ownership of this 160 - * array is taken and dma_fence_put() is used on each fence on release. 161 - * 162 - * If @signal_on_any is true the fence array signals if any fence in the array 163 - * signals, otherwise it signals when all fences in the array signal. 169 + * Implementation of @dma_fence_array_create without allocation. Useful to init 170 + * a preallocated dma fence array in the path of reclaim or dma fence signaling. 164 171 */ 165 - struct dma_fence_array *dma_fence_array_create(int num_fences, 166 - struct dma_fence **fences, 167 - u64 context, unsigned seqno, 168 - bool signal_on_any) 172 + void dma_fence_array_init(struct dma_fence_array *array, 173 + int num_fences, struct dma_fence **fences, 174 + u64 context, unsigned seqno, 175 + bool signal_on_any) 169 176 { 170 - struct dma_fence_array *array; 171 - 172 177 WARN_ON(!num_fences || !fences); 173 - 174 - array = kzalloc(struct_size(array, callbacks, num_fences), GFP_KERNEL); 175 - if (!array) 176 - return NULL; 177 178 178 179 array->num_fences = num_fences; 179 180 ··· 201 200 */ 202 201 while (num_fences--) 203 202 WARN_ON(dma_fence_is_container(fences[num_fences])); 203 + } 204 + EXPORT_SYMBOL(dma_fence_array_init); 205 + 206 + /** 207 + * dma_fence_array_create - Create a custom fence array 208 + * @num_fences: [in] number of fences to add in the array 209 + * @fences: [in] array containing the fences 210 + * @context: [in] fence context to use 211 + * @seqno: [in] sequence number to use 212 + * @signal_on_any: [in] signal on any fence in the array 213 + * 214 + * Allocate a dma_fence_array object and initialize the base fence with 215 + * dma_fence_init(). 216 + * In case of error it returns NULL. 217 + * 218 + * The caller should allocate the fences array with num_fences size 219 + * and fill it with the fences it wants to add to the object. Ownership of this 220 + * array is taken and dma_fence_put() is used on each fence on release. 221 + * 222 + * If @signal_on_any is true the fence array signals if any fence in the array 223 + * signals, otherwise it signals when all fences in the array signal. 224 + */ 225 + struct dma_fence_array *dma_fence_array_create(int num_fences, 226 + struct dma_fence **fences, 227 + u64 context, unsigned seqno, 228 + bool signal_on_any) 229 + { 230 + struct dma_fence_array *array; 231 + 232 + array = dma_fence_array_alloc(num_fences); 233 + if (!array) 234 + return NULL; 235 + 236 + dma_fence_array_init(array, num_fences, fences, 237 + context, seqno, signal_on_any); 204 238 205 239 return array; 206 240 }
+6
include/linux/dma-fence-array.h
··· 79 79 for (index = 0, fence = dma_fence_array_first(head); fence; \ 80 80 ++(index), fence = dma_fence_array_next(head, index)) 81 81 82 + struct dma_fence_array *dma_fence_array_alloc(int num_fences); 83 + void dma_fence_array_init(struct dma_fence_array *array, 84 + int num_fences, struct dma_fence **fences, 85 + u64 context, unsigned seqno, 86 + bool signal_on_any); 87 + 82 88 struct dma_fence_array *dma_fence_array_create(int num_fences, 83 89 struct dma_fence **fences, 84 90 u64 context, unsigned seqno,