Skip to content

Commit d0dd796

Browse files
Tomer TayarKobyElbaz
authored andcommitted
accel/habanalabs: clarify ctx use after hl_ctx_put() in dmabuf release
In hl_release_dmabuf(), ctx is dereferenced after calling hl_ctx_put() to obtain the compute device file. This is safe because the dma-buf object holds a file reference taken in export_dmabuf(), and the file release (which drops another ctx reference) can only happen after we drop that file reference via fput(). Thus, this hl_ctx_put() call cannot be the last one at this point. Add a comment explaining this to avoid confusion. Signed-off-by: Tomer Tayar <[email protected]> Reviewed-by: Koby Elbaz <[email protected]> Signed-off-by: Koby Elbaz <[email protected]>
1 parent b5cddeb commit d0dd796

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/accel/habanalabs/common/memory.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,12 @@ static void hl_release_dmabuf(struct dma_buf *dmabuf)
18371837
atomic_dec(&ctx->hdev->dmabuf_export_cnt);
18381838
hl_ctx_put(ctx);
18391839

1840-
/* Paired with get_file() in export_dmabuf() */
1840+
/*
1841+
* Paired with get_file() in export_dmabuf().
1842+
* 'ctx' can be still used here to get the file pointer, even after hl_ctx_put() was called,
1843+
* because releasing the compute device file involves another reference decrement, and it
1844+
* would be possible only after calling fput().
1845+
*/
18411846
fput(ctx->hpriv->file_priv->filp);
18421847

18431848
kfree(hl_dmabuf);

0 commit comments

Comments
 (0)