All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rob Herring <robh@kernel.org>
To: dri-devel@lists.freedesktop.org
Cc: Robert Foss <robert.foss@collabora.com>
Subject: [PATCH libdrm 4/4] android: fix gralloc_handle_create() problems
Date: Thu, 15 Feb 2018 07:59:26 -0600	[thread overview]
Message-ID: <20180215135926.9502-5-robh@kernel.org> (raw)
In-Reply-To: <20180215135926.9502-1-robh@kernel.org>

There's a number of problems with gralloc_handle_create starting with it
doesn't even compile. More importantly, it doesn't really create (i.e.
allocate) a handle. It allocates a native_handle_t, copies it to a
struct gralloc_handle_t on the stack and returns the struct (not a ptr).
So the caller still has to allocate a struct gralloc_handle_t to hold
the returned struct.

Rework gralloc_handle_create() to allocate a new handle and return the
pointer to the allocated handle. Callers should free the handle with
native_handle_close() and native_handle_delete().

Signed-off-by: Rob Herring <robh@kernel.org>
---
 android/gralloc_handle.h | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/android/gralloc_handle.h b/android/gralloc_handle.h
index 43255ba539c2..3177f7a1fd8f 100644
--- a/android/gralloc_handle.h
+++ b/android/gralloc_handle.h
@@ -84,28 +84,26 @@ static inline struct gralloc_handle_t *gralloc_handle(buffer_handle_t handle)
 /**
  * Create a buffer handle.
  */
-static struct gralloc_handle_t gralloc_handle_create(int32_t width,
+static inline struct gralloc_handle_t *gralloc_handle_create(int32_t width,
                                                      int32_t height,
                                                      int32_t format,
                                                      int32_t usage)
 {
-	struct alloc_handle_t handle = {
-		.magic = GRALLOC_HANDLE_MAGIC,
-		.version = GRALLOC_HANDLE_VERSION };
-
+	struct gralloc_handle_t *handle;
 	native_handle_t *nhandle = native_handle_create(GRALLOC_HANDLE_NUM_FDS,
-		                                            GRALLOC_HANDLE_NUM_INTS);
-	handle.base = *nhandle;
-	native_handle_delete(nhandle);
-
-	handle.width = width;
-	handle.height = height;
-	handle.format = format;
-	handle.usage = usage;
-	handle.prime_fd = -1;
-
-	handle->data_owner = getpid();
-	handle->data = bo;
+							GRALLOC_HANDLE_NUM_INTS);
+
+	if (!nhandle)
+		return NULL;
+
+	handle = gralloc_handle(nhandle);
+	handle->magic = GRALLOC_HANDLE_MAGIC;
+	handle->version = GRALLOC_HANDLE_VERSION;
+	handle->width = width;
+	handle->height = height;
+	handle->format = format;
+	handle->usage = usage;
+	handle->prime_fd = -1;
 
 	return handle;
 }
-- 
2.14.1

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

  parent reply	other threads:[~2018-02-15 13:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-15 13:59 [PATCH libdrm 0/4] gralloc handle fixes Rob Herring
2018-02-15 13:59 ` [PATCH libdrm 1/4] android: revert making handle magic and version members const Rob Herring
2018-02-15 13:59 ` [PATCH libdrm 2/4] android: fix mis-named alloc_handle_t Rob Herring
2018-02-15 13:59 ` [PATCH libdrm 3/4] android: add helper to convert buffer_handle_t to gralloc_handle_t ptr Rob Herring
2018-02-15 13:59 ` Rob Herring [this message]
2018-02-15 15:43 ` [PATCH libdrm 0/4] gralloc handle fixes Robert Foss

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=20180215135926.9502-5-robh@kernel.org \
    --to=robh@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=robert.foss@collabora.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.