Skip to content

Commit 1cd0787

Browse files
committed
drm/msm: Fix hw_fence error path cleanup
In an error path where the submit is free'd without the job being run, the hw_fence pointer is simply a kzalloc'd block of memory. In this case we should just kfree() it, rather than trying to decrement it's reference count. Fortunately we can tell that this is the case by checking for a zero refcount, since if the job was run, the submit would be holding a reference to the hw_fence. Fixes: f94e6a5 ("drm/msm: Pre-allocate hw_fence") Signed-off-by: Rob Clark <[email protected]> Patchwork: https://patchwork.freedesktop.org/patch/547088/
1 parent 6e8a996 commit 1cd0787

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

drivers/gpu/drm/msm/msm_fence.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ msm_fence_init(struct dma_fence *fence, struct msm_fence_context *fctx)
191191

192192
f->fctx = fctx;
193193

194+
/*
195+
* Until this point, the fence was just some pre-allocated memory,
196+
* no-one should have taken a reference to it yet.
197+
*/
198+
WARN_ON(kref_read(&fence->refcount));
199+
194200
dma_fence_init(&f->base, &msm_fence_ops, &fctx->spinlock,
195201
fctx->context, ++fctx->last_fence);
196202
}

drivers/gpu/drm/msm/msm_gem_submit.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,19 @@ void __msm_gem_submit_destroy(struct kref *kref)
8686
}
8787

8888
dma_fence_put(submit->user_fence);
89-
dma_fence_put(submit->hw_fence);
89+
90+
/*
91+
* If the submit is freed before msm_job_run(), then hw_fence is
92+
* just some pre-allocated memory, not a reference counted fence.
93+
* Once the job runs and the hw_fence is initialized, it will
94+
* have a refcount of at least one, since the submit holds a ref
95+
* to the hw_fence.
96+
*/
97+
if (kref_read(&submit->hw_fence->refcount) == 0) {
98+
kfree(submit->hw_fence);
99+
} else {
100+
dma_fence_put(submit->hw_fence);
101+
}
90102

91103
put_pid(submit->pid);
92104
msm_submitqueue_put(submit->queue);

0 commit comments

Comments
 (0)