From: Emil Velikov <emil.l.velikov@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: intel-gfx-trybot@lists.freedesktop.org
Subject: [PATCH 1/2] drm/prime: split drm_gem_prime_fd_to_handle()
Date: Thu, 25 Apr 2019 16:51:13 +0100 [thread overview]
Message-ID: <20190425155114.533-1-emil.l.velikov@gmail.com> (raw)
From: Emil Velikov <emil.velikov@collabora.com>
Currently drm_gem_prime_fd_to_handle() consists of illegible amount of
goto labels, for no obvious reason.
Split it in two (as below) making the code far simpler and obvious.
drm_gem_prime_fd_to_handle()
- prime mtx handling
- fd/dmabuf refcounting
- hash table lookup
import_buf_to_handle()
- drm_gem_object import and locking
- creating a handle for the gem object
- adding the handle/fd to the hash table
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
---
drivers/gpu/drm/drm_prime.c | 86 ++++++++++++++++++-------------------
1 file changed, 41 insertions(+), 45 deletions(-)
diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index dc079efb3b0f..0d83b9bbf793 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -777,37 +777,14 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
}
EXPORT_SYMBOL(drm_gem_prime_import);
-/**
- * drm_gem_prime_fd_to_handle - PRIME import function for GEM drivers
- * @dev: dev to export the buffer from
- * @file_priv: drm file-private structure
- * @prime_fd: fd id of the dma-buf which should be imported
- * @handle: pointer to storage for the handle of the imported buffer object
- *
- * This is the PRIME import function which must be used mandatorily by GEM
- * drivers to ensure correct lifetime management of the underlying GEM object.
- * The actual importing of GEM object from the dma-buf is done through the
- * gem_import_export driver callback.
- */
-int drm_gem_prime_fd_to_handle(struct drm_device *dev,
- struct drm_file *file_priv, int prime_fd,
- uint32_t *handle)
+static int import_buf_to_handle(struct drm_device *dev,
+ struct drm_file *file_priv,
+ struct dma_buf *dma_buf,
+ uint32_t *handle)
{
- struct dma_buf *dma_buf;
struct drm_gem_object *obj;
int ret;
- dma_buf = dma_buf_get(prime_fd);
- if (IS_ERR(dma_buf))
- return PTR_ERR(dma_buf);
-
- mutex_lock(&file_priv->prime.lock);
-
- ret = drm_prime_lookup_buf_handle(&file_priv->prime,
- dma_buf, handle);
- if (ret == 0)
- goto out_put;
-
/* never seen this one, need to import */
mutex_lock(&dev->object_name_lock);
if (dev->driver->gem_prime_import)
@@ -816,7 +793,8 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
obj = drm_gem_prime_import(dev, dma_buf);
if (IS_ERR(obj)) {
ret = PTR_ERR(obj);
- goto out_unlock;
+ mutex_unlock(&dev->object_name_lock);
+ return ret;
}
if (obj->dma_buf) {
@@ -830,29 +808,47 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
ret = drm_gem_handle_create_tail(file_priv, obj, handle);
drm_gem_object_put_unlocked(obj);
if (ret)
- goto out_put;
+ return ret;
- ret = drm_prime_add_buf_handle(&file_priv->prime,
- dma_buf, *handle);
- mutex_unlock(&file_priv->prime.lock);
+ ret = drm_prime_add_buf_handle(&file_priv->prime, dma_buf, *handle);
if (ret)
- goto fail;
+ /* hmm, if driver attached, we are relying on the free-object
+ * path to detach.. which seems ok..
+ */
+ drm_gem_handle_delete(file_priv, *handle);
- dma_buf_put(dma_buf);
+ return ret;
+}
- return 0;
+/**
+ * drm_gem_prime_fd_to_handle - PRIME import function for GEM drivers
+ * @dev: dev to export the buffer from
+ * @file_priv: drm file-private structure
+ * @prime_fd: fd id of the dma-buf which should be imported
+ * @handle: pointer to storage for the handle of the imported buffer object
+ *
+ * This is the PRIME import function which must be used mandatorily by GEM
+ * drivers to ensure correct lifetime management of the underlying GEM object.
+ * The actual importing of GEM object from the dma-buf is done through the
+ * gem_import_export driver callback.
+ */
+int drm_gem_prime_fd_to_handle(struct drm_device *dev,
+ struct drm_file *file_priv, int prime_fd,
+ uint32_t *handle)
+{
+ struct dma_buf *dma_buf;
+ int ret;
-fail:
- /* hmm, if driver attached, we are relying on the free-object path
- * to detach.. which seems ok..
- */
- drm_gem_handle_delete(file_priv, *handle);
- dma_buf_put(dma_buf);
- return ret;
+ dma_buf = dma_buf_get(prime_fd);
+ if (IS_ERR(dma_buf))
+ return PTR_ERR(dma_buf);
+
+ mutex_lock(&file_priv->prime.lock);
+
+ ret = drm_prime_lookup_buf_handle(&file_priv->prime, dma_buf, handle);
+ if (ret)
+ ret = import_buf_to_handle(dev, file_priv, dma_buf, handle);
-out_unlock:
- mutex_unlock(&dev->object_name_lock);
-out_put:
mutex_unlock(&file_priv->prime.lock);
dma_buf_put(dma_buf);
return ret;
--
2.21.0
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next reply other threads:[~2019-04-25 15:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-25 15:51 Emil Velikov [this message]
2019-04-25 15:51 ` [PATCH 2/2] drm/prime: split drm_gem_prime_handle_to_fd() Emil Velikov
2019-04-25 17:15 ` Sam Ravnborg
2019-04-25 17:07 ` [PATCH 1/2] drm/prime: split drm_gem_prime_fd_to_handle() Sam Ravnborg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190425155114.533-1-emil.l.velikov@gmail.com \
--to=emil.l.velikov@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx-trybot@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox