mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-29 13:53:33 +00:00
habanalabs: fix dma-buf release handling if dma_buf_fd() fails
The dma-buf private object is freed if a call to dma_buf_fd() fails, and because a file was already associated with the dma-buf in dma_buf_export(), the release op will be called and will use this object. Mark the 'priv' field as NULL in this case, and avoid accessing it from the release op. Signed-off-by: Tomer Tayar <ttayar@habana.ai> Reviewed-by: Oded Gabbay <ogabbay@kernel.org> Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
This commit is contained in:
parent
6bdb7bc990
commit
9b3d9f917f
1 changed files with 8 additions and 2 deletions
|
@ -1782,7 +1782,12 @@ static void hl_unmap_dmabuf(struct dma_buf_attachment *attachment,
|
||||||
static void hl_release_dmabuf(struct dma_buf *dmabuf)
|
static void hl_release_dmabuf(struct dma_buf *dmabuf)
|
||||||
{
|
{
|
||||||
struct hl_dmabuf_priv *hl_dmabuf = dmabuf->priv;
|
struct hl_dmabuf_priv *hl_dmabuf = dmabuf->priv;
|
||||||
struct hl_ctx *ctx = hl_dmabuf->ctx;
|
struct hl_ctx *ctx;
|
||||||
|
|
||||||
|
if (!hl_dmabuf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ctx = hl_dmabuf->ctx;
|
||||||
|
|
||||||
if (hl_dmabuf->memhash_hnode) {
|
if (hl_dmabuf->memhash_hnode) {
|
||||||
mutex_lock(&ctx->mem_hash_lock);
|
mutex_lock(&ctx->mem_hash_lock);
|
||||||
|
@ -1822,7 +1827,7 @@ static int export_dmabuf(struct hl_ctx *ctx,
|
||||||
|
|
||||||
fd = dma_buf_fd(hl_dmabuf->dmabuf, flags);
|
fd = dma_buf_fd(hl_dmabuf->dmabuf, flags);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
dev_err(hdev->dev, "failed to get a file descriptor for a dma-buf\n");
|
dev_err(hdev->dev, "failed to get a file descriptor for a dma-buf, %d\n", fd);
|
||||||
rc = fd;
|
rc = fd;
|
||||||
goto err_dma_buf_put;
|
goto err_dma_buf_put;
|
||||||
}
|
}
|
||||||
|
@ -1835,6 +1840,7 @@ static int export_dmabuf(struct hl_ctx *ctx,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_dma_buf_put:
|
err_dma_buf_put:
|
||||||
|
hl_dmabuf->dmabuf->priv = NULL;
|
||||||
dma_buf_put(hl_dmabuf->dmabuf);
|
dma_buf_put(hl_dmabuf->dmabuf);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue