[PATCH drm 2/6] drm: generalize drm_prime_lookup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: agoins <agoins@xxxxxxxxxx>

Replace drm_prime_lookup_buf_by_handle() and drm_prime_lookup_buf_handle()
with more generalized drm_prime_lookup_member_by_handle() and
drm_prime_lookup_buf_member(), respectively. New implementations return the
member itself rather than extracting a specific field, allowing other
fields to be queried as well.

Signed-off-by: Alex Goins <agoins@xxxxxxxxxx>
---
 drivers/gpu/drm/drm_prime.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 27aa718..e2e86de 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -87,32 +87,33 @@ static int drm_prime_add_buf_handle(struct drm_prime_file_private *prime_fpriv,
 	return 0;
 }
 
-static struct dma_buf *drm_prime_lookup_buf_by_handle(struct drm_prime_file_private *prime_fpriv,
-						      uint32_t handle)
+static struct drm_prime_member *drm_prime_lookup_member_by_handle(
+				struct drm_prime_file_private *prime_fpriv,
+				uint32_t handle)
 {
 	struct drm_prime_member *member;
 
 	list_for_each_entry(member, &prime_fpriv->head, entry) {
 		if (member->handle == handle)
-			return member->dma_buf;
+			return member;
 	}
 
 	return NULL;
 }
 
-static int drm_prime_lookup_buf_handle(struct drm_prime_file_private *prime_fpriv,
-				       struct dma_buf *dma_buf,
-				       uint32_t *handle)
+static struct drm_prime_member *drm_prime_lookup_buf_member(
+				struct drm_prime_file_private *prime_fpriv,
+				struct dma_buf *dma_buf)
 {
 	struct drm_prime_member *member;
 
 	list_for_each_entry(member, &prime_fpriv->head, entry) {
 		if (member->dma_buf == dma_buf) {
-			*handle = member->handle;
-			return 0;
+			return member;
 		}
 	}
-	return -ENOENT;
+
+	return NULL;
 }
 
 static int drm_gem_map_attach(struct dma_buf *dma_buf,
@@ -404,6 +405,7 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev,
 {
 	struct drm_gem_object *obj;
 	int ret = 0;
+	struct drm_prime_member *member;
 	struct dma_buf *dmabuf;
 
 	mutex_lock(&file_priv->prime.lock);
@@ -413,8 +415,9 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev,
 		goto out_unlock;
 	}
 
-	dmabuf = drm_prime_lookup_buf_by_handle(&file_priv->prime, handle);
-	if (dmabuf) {
+	member = drm_prime_lookup_member_by_handle(&file_priv->prime, handle);
+	if (member) {
+		dmabuf = member->dma_buf;
 		get_dma_buf(dmabuf);
 		goto out_have_handle;
 	}
@@ -564,6 +567,7 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 			       uint32_t *handle)
 {
 	struct dma_buf *dma_buf;
+	struct drm_prime_member *member;
 	struct drm_gem_object *obj;
 	int ret;
 
@@ -573,10 +577,12 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 
 	mutex_lock(&file_priv->prime.lock);
 
-	ret = drm_prime_lookup_buf_handle(&file_priv->prime,
-			dma_buf, handle);
-	if (ret == 0)
+	member = drm_prime_lookup_buf_member(&file_priv->prime, dma_buf);
+	if (member) {
+		ret = 0;
+		*handle = member->handle;
 		goto out_put;
+	}
 
 	/* never seen this one, need to import */
 	mutex_lock(&dev->object_name_lock);
-- 
1.9.1

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux