diff options
author | Chia-I Wu <olv@google.com> | 2017-05-08 12:46:13 -0700 |
---|---|---|
committer | Chia-I Wu <olv@google.com> | 2017-05-24 08:57:00 -0700 |
commit | cacd04a3a2784c055f3d2847d28922e26768d72f (patch) | |
tree | 0f28fa69993e6c1650fe9396844c5fff5399f621 | |
parent | d3cc831956950591b96f93e0d4212236753803a0 (diff) | |
download | hikey-cacd04a3a2784c055f3d2847d28922e26768d72f.tar.gz |
gralloc: fix numFds for framebuffer handles
It is an error to claim one fd, while the fd is -1.
Bug: 37550237
Test: boots
Change-Id: I7ad0d7c2bbe0bff8f462666bbf5fab38e9115578
-rw-r--r-- | gralloc/alloc_device.cpp | 6 | ||||
-rw-r--r-- | gralloc/gralloc_priv.h | 18 |
2 files changed, 21 insertions, 3 deletions
diff --git a/gralloc/alloc_device.cpp b/gralloc/alloc_device.cpp index 67734050..cef58511 100644 --- a/gralloc/alloc_device.cpp +++ b/gralloc/alloc_device.cpp @@ -333,6 +333,12 @@ static int gralloc_alloc_framebuffer_locked(alloc_device_t *dev, size_t size, in #endif } + + // correct numFds/numInts when there is no dmabuf fd + if (hnd->share_fd < 0) { + hnd->numFds--; + hnd->numInts++; + } #endif *pHandle = hnd; diff --git a/gralloc/gralloc_priv.h b/gralloc/gralloc_priv.h index 547027e8..36159606 100644 --- a/gralloc/gralloc_priv.h +++ b/gralloc/gralloc_priv.h @@ -313,9 +313,21 @@ struct private_handle_t { const private_handle_t *hnd = (const private_handle_t *)h; - if (!h || h->version != sizeof(native_handle) || h->numFds != sNumFds || - h->numInts != (sizeof(private_handle_t) - sizeof(native_handle)) / sizeof(int) - sNumFds || - hnd->magic != sMagic) + if (!h || h->version != sizeof(native_handle) || hnd->magic != sMagic) + { + return -EINVAL; + } + + int numFds = sNumFds; + int numInts = (sizeof(private_handle_t) - sizeof(native_handle)) / sizeof(int) - sNumFds; +#if GRALLOC_ARM_DMA_BUF_MODULE + if (hnd->share_fd < 0) { + numFds--; + numInts++; + } +#endif + + if (h->numFds != numFds || h->numInts != numInts) { return -EINVAL; } |