libfmq: Improve error logging am: a78c0d2b53 am: 2b1b9c648a

Original change: https://googleplex-android-review.googlesource.com/c/platform/system/libfmq/+/11842976

Change-Id: I06c4e34f5020580bbe8902e5267c0f6a00a64f7e
diff --git a/include/fmq/MessageQueue.h b/include/fmq/MessageQueue.h
index 848b77f..ca031aa 100644
--- a/include/fmq/MessageQueue.h
+++ b/include/fmq/MessageQueue.h
@@ -1169,7 +1169,14 @@
 void* MessageQueue<T, flavor>::mapGrantorDescr(uint32_t grantorIdx) {
     const native_handle_t* handle = mDesc->handle();
     auto grantors = mDesc->grantors();
-    if ((handle == nullptr) || (grantorIdx >= grantors.size())) {
+    if (handle == nullptr) {
+        details::logError("mDesc->handle is null");
+        return nullptr;
+    }
+
+    if (grantorIdx >= grantors.size()) {
+        details::logError(std::string("grantorIdx must be less than ") +
+                          std::to_string(grantors.size()));
         return nullptr;
     }
 
@@ -1183,10 +1190,11 @@
 
     void* address = mmap(0, mapLength, PROT_READ | PROT_WRITE, MAP_SHARED,
                          handle->data[fdIndex], mapOffset);
-    return (address == MAP_FAILED)
-            ? nullptr
-            : reinterpret_cast<uint8_t*>(address) +
-            (grantors[grantorIdx].offset - mapOffset);
+    if (address == MAP_FAILED) {
+        details::logError(std::string("mmap failed: ") + std::to_string(errno));
+        return nullptr;
+    }
+    return reinterpret_cast<uint8_t*>(address) + (grantors[grantorIdx].offset - mapOffset);
 }
 
 template <typename T, MQFlavor flavor>