From 8793e54e6095789017e55a1605126f7f89955444 Mon Sep 17 00:00:00 2001 From: Stas Gurtovoy Date: Tue, 21 Jun 2011 13:41:41 +0300 Subject: [PATCH] emulator gralloc: Make the cb_handle_t::validate static This is nicer, since it checks the handle itself, not counting on the caller to check it Change-Id: I7eba6292dee8e0832a8c0074f508c07c3bc43ff2 --- .../system/OpenglSystemCommon/gralloc_cb.h | 9 +++++---- .../emulator/opengl/system/gralloc/gralloc.cpp | 17 +++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/tools/emulator/opengl/system/OpenglSystemCommon/gralloc_cb.h b/tools/emulator/opengl/system/OpenglSystemCommon/gralloc_cb.h index 117378d60..530e004dd 100644 --- a/tools/emulator/opengl/system/OpenglSystemCommon/gralloc_cb.h +++ b/tools/emulator/opengl/system/OpenglSystemCommon/gralloc_cb.h @@ -53,10 +53,11 @@ struct cb_handle_t : public native_handle { numInts = CB_HANDLE_NUM_INTS(numFds); } - bool validate() const { - return (version == sizeof(native_handle) && - magic == BUFFER_HANDLE_MAGIC && - numInts == CB_HANDLE_NUM_INTS(numFds)); + static bool validate(cb_handle_t * hnd) { + return (hnd && + hnd->version == sizeof(native_handle) && + hnd->magic == BUFFER_HANDLE_MAGIC && + hnd->numInts == CB_HANDLE_NUM_INTS(hnd->numFds)); } bool canBePosted() { diff --git a/tools/emulator/opengl/system/gralloc/gralloc.cpp b/tools/emulator/opengl/system/gralloc/gralloc.cpp index 5c11ee367..e03fa9609 100644 --- a/tools/emulator/opengl/system/gralloc/gralloc.cpp +++ b/tools/emulator/opengl/system/gralloc/gralloc.cpp @@ -245,7 +245,8 @@ static int gralloc_free(alloc_device_t* dev, buffer_handle_t handle) { const cb_handle_t *cb = (const cb_handle_t *)handle; - if (!cb || !cb->validate()) { + if (!cb_handle_t::validate((cb_handle_t*)cb)) { + ERR("gralloc_free: invalid handle"); return -EINVAL; } @@ -322,7 +323,7 @@ static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer) fb_device_t *fbdev = (fb_device_t *)dev; cb_handle_t *cb = (cb_handle_t *)buffer; - if (!fbdev || !cb || !cb->validate() || !cb->canBePosted()) { + if (!fbdev || !cb_handle_t::validate(cb) || !cb->canBePosted()) { return -EINVAL; } @@ -402,7 +403,8 @@ static int gralloc_register_buffer(gralloc_module_t const* module, { private_module_t *gr = (private_module_t *)module; cb_handle_t *cb = (cb_handle_t *)handle; - if (!gr || !cb || !cb->validate()) { + if (!gr || !cb_handle_t::validate(cb)) { + ERR("gralloc_register_buffer: invalid buffer"); return -EINVAL; } @@ -414,6 +416,7 @@ static int gralloc_register_buffer(gralloc_module_t const* module, void *vaddr; int err = map_buffer(cb, &vaddr); if (err) { + ERR("gralloc_register_buffer: map failed"); return -err; } cb->mappedPid = getpid(); @@ -427,7 +430,8 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module, { private_module_t *gr = (private_module_t *)module; cb_handle_t *cb = (cb_handle_t *)handle; - if (!gr || !cb || !cb->validate()) { + if (!gr || !cb_handle_t::validate(cb)) { + ERR("gralloc_unregister_buffer: invalid buffer"); return -EINVAL; } @@ -439,6 +443,7 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module, void *vaddr; int err = munmap((void *)cb->ashmemBase, cb->ashmemSize); if (err) { + ERR("gralloc_unregister_buffer: unmap failed"); return -EINVAL; } cb->ashmemBase = NULL; @@ -455,7 +460,7 @@ static int gralloc_lock(gralloc_module_t const* module, { private_module_t *gr = (private_module_t *)module; cb_handle_t *cb = (cb_handle_t *)handle; - if (!gr || !cb || !cb->validate()) { + if (!gr || !cb_handle_t::validate(cb)) { LOGE("gralloc_lock bad handle\n"); return -EINVAL; } @@ -543,7 +548,7 @@ static int gralloc_unlock(gralloc_module_t const* module, { private_module_t *gr = (private_module_t *)module; cb_handle_t *cb = (cb_handle_t *)handle; - if (!gr || !cb || !cb->validate()) { + if (!gr || !cb_handle_t::validate(cb)) { return -EINVAL; }