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

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 <tomer.tayar@intel.com>
Reviewed-by: Koby Elbaz <koby.elbaz@intel.com>
Signed-off-by: Koby Elbaz <koby.elbaz@intel.com>

authored by

Tomer Tayar and committed by
Koby Elbaz
d0dd796b b5cddeb0

+6 -1
+6 -1
drivers/accel/habanalabs/common/memory.c
··· 1837 1837 atomic_dec(&ctx->hdev->dmabuf_export_cnt); 1838 1838 hl_ctx_put(ctx); 1839 1839 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 + */ 1841 1846 fput(ctx->hpriv->file_priv->filp); 1842 1847 1843 1848 kfree(hl_dmabuf);