summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 86c62e4)
raw | patch | inline | side by side (parent: 86c62e4)
author | Rob Herring <robh@kernel.org> | |
Wed, 14 Feb 2018 23:03:56 +0000 (17:03 -0600) | ||
committer | Rob Herring <robh@kernel.org> | |
Tue, 20 Feb 2018 20:16:16 +0000 (14:16 -0600) |
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(). In the interest of
making gralloc_handle_t opaque, return a native_handle_t ptr instead.
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Signed-off-by: Rob Herring <robh@kernel.org>
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(). In the interest of
making gralloc_handle_t opaque, return a native_handle_t ptr instead.
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Signed-off-by: Rob Herring <robh@kernel.org>
android/gralloc_handle.h | patch | blob | history |
index 43255ba539c20a72936837163c74a80ce359335d..9cb5a5d7842c5e34c7891d4f3a1404424c404565 100644 (file)
--- a/android/gralloc_handle.h
+++ b/android/gralloc_handle.h
/**
* Create a buffer handle.
*/
-static struct gralloc_handle_t gralloc_handle_create(int32_t width,
+static inline native_handle_t *gralloc_handle_create(int32_t width,
int32_t height,
- int32_t format,
+ int32_t hal_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 = hal_format;
+ handle->usage = usage;
+ handle->prime_fd = -1;
return handle;
}