Skip to content

Commit ffe0002

Browse files
gfxstrandChristianKoenigAMD
authored andcommitted
dma-buf/sync_file: Don't leak fences on merge failure
Each add_fence() call does a dma_fence_get() on the relevant fence. In the error path, we weren't calling dma_fence_put() so all those fences got leaked. Also, in the krealloc_array failure case, we weren't freeing the fences array. Instead, ensure that i and fences are always zero-initialized and dma_fence_put() all the fences and kfree(fences) on every error path. Signed-off-by: Jason Ekstrand <[email protected]> Reviewed-by: Christian König <[email protected]> Fixes: a02b9dc ("dma-buf/sync_file: refactor fence storage in struct sync_file") Cc: Gustavo Padovan <[email protected]> Cc: Christian König <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Christian König <[email protected]>
1 parent 1988e0d commit ffe0002

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/dma-buf/sync_file.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
211211
struct sync_file *b)
212212
{
213213
struct sync_file *sync_file;
214-
struct dma_fence **fences, **nfences, **a_fences, **b_fences;
215-
int i, i_a, i_b, num_fences, a_num_fences, b_num_fences;
214+
struct dma_fence **fences = NULL, **nfences, **a_fences, **b_fences;
215+
int i = 0, i_a, i_b, num_fences, a_num_fences, b_num_fences;
216216

217217
sync_file = sync_file_alloc();
218218
if (!sync_file)
@@ -236,7 +236,7 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
236236
* If a sync_file can only be created with sync_file_merge
237237
* and sync_file_create, this is a reasonable assumption.
238238
*/
239-
for (i = i_a = i_b = 0; i_a < a_num_fences && i_b < b_num_fences; ) {
239+
for (i_a = i_b = 0; i_a < a_num_fences && i_b < b_num_fences; ) {
240240
struct dma_fence *pt_a = a_fences[i_a];
241241
struct dma_fence *pt_b = b_fences[i_b];
242242

@@ -277,15 +277,16 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
277277
fences = nfences;
278278
}
279279

280-
if (sync_file_set_fence(sync_file, fences, i) < 0) {
281-
kfree(fences);
280+
if (sync_file_set_fence(sync_file, fences, i) < 0)
282281
goto err;
283-
}
284282

285283
strlcpy(sync_file->user_name, name, sizeof(sync_file->user_name));
286284
return sync_file;
287285

288286
err:
287+
while (i)
288+
dma_fence_put(fences[--i]);
289+
kfree(fences);
289290
fput(sync_file->file);
290291
return NULL;
291292

0 commit comments

Comments
 (0)