Skip to contentSkip to conversation

dma-buf: call kfree() w/o mutex held in dma_buf_attach()

PATCH In review Emil Velikov 2 participants 2 messages Apr 25, 2019 DMA buffer sharing framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-buf: call kfree() w/o mutex held in dma_buf_attach()

From: Emil Velikov <[email protected]>

In dma_buf_attach() we allocate memory w/o a mutex being held, thus in the error path we should kfree() it after the mutex_unlock.

The inverse function dma_buf_deattach() gets this right.

---
 drivers/dma-buf/dma-buf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-buf.c +1 -1
index 3ae6c0c2cc02..57ddeb735b8b 100644
@@ -579,8 +579,8 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
 	return attach;
 
 err_attach:
-	kfree(attach);
 	mutex_unlock(&dmabuf->lock);
+	kfree(attach);
 	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(dma_buf_attach);
Signature · 6 lines
2.21.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Emil Velikov

From: Emil Velikov <[email protected]>

In dma_buf_attach() we allocate memory w/o a mutex being held, thus in the error path we should kfree() it after the mutex_unlock.

The inverse function dma_buf_deattach() gets this right.

I don't think this matters, but +1 on ocd.

Quoted 25 lines
---
 drivers/dma-buf/dma-buf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/dma-buf.c +1 -1
index 3ae6c0c2cc02..57ddeb735b8b 100644
@@ -579,8 +579,8 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
 	return attach;
 
 err_attach:
-	kfree(attach);
 	mutex_unlock(&dmabuf->lock);
+	kfree(attach);
 	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(dma_buf_attach);
Signature · 6 lines
2.21.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel