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
diff --git a/gralloc/alloc_device.cpp b/gralloc/alloc_device.cpp
index 6773405..cef5851 100644
--- a/gralloc/alloc_device.cpp
+++ b/gralloc/alloc_device.cpp
@@ -333,6 +333,12 @@
 
 #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 547027e..3615960 100644
--- a/gralloc/gralloc_priv.h
+++ b/gralloc/gralloc_priv.h
@@ -313,9 +313,21 @@
 	{
 		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;
 		}