[Freedreno] [PATCH libdrm v2 2/2] freedreno: serialize drmPrimeFDToHandle under table_lock

Varad Gautam varadgautam at gmail.com
Sun Aug 23 10:49:05 PDT 2015


Prevents a race condition when importing a bo that's currently being freed.

Signed-off-by: Varad Gautam <varadgautam at gmail.com>
---
 freedreno/freedreno_bo.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/freedreno/freedreno_bo.c b/freedreno/freedreno_bo.c
index 0d2847f..aece972 100644
--- a/freedreno/freedreno_bo.c
+++ b/freedreno/freedreno_bo.c
@@ -233,6 +233,7 @@ fd_bo_from_dmabuf(struct fd_device *dev, int fd)
 	uint32_t handle;
 	struct fd_bo *bo;
 
+	pthread_mutex_lock(&table_lock);
 	ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
 
 	if (ret) {
@@ -242,7 +243,7 @@ fd_bo_from_dmabuf(struct fd_device *dev, int fd)
 
 	bo = lookup_bo(dev->handle_table, handle);
 	if (bo)
-		return bo;
+		goto out_unlock;
 
 	/* lseek() to get bo size */
 	size = lseek(fd, 0, SEEK_END);
@@ -251,6 +252,9 @@ fd_bo_from_dmabuf(struct fd_device *dev, int fd)
 	bo = bo_from_handle(dev, size, handle);
 	bo->fd = fd;
 
+out_unlock:
+	pthread_mutex_unlock(&table_lock);
+
 	return bo;
 }
 
-- 
2.4.6



More information about the Freedreno mailing list