gralloc: Fix "Return an error if the buffer was not mapped"

Let graphics map the buffer in registerBuffer, except secure
buffers. Avoid map in register (and at allocation time) can be
done when retain/release is implemented in gralloc 1.0

Bug: 28526999
Bug: 30404840
Change-Id: I208316b89edffc7486fe74deb1b9e3352d230223
CRs-fixed: 1010697
diff --git a/msm8994/libgralloc/mapper.cpp b/msm8994/libgralloc/mapper.cpp
index 90fe3e9..1f6544c 100644
--- a/msm8994/libgralloc/mapper.cpp
+++ b/msm8994/libgralloc/mapper.cpp
@@ -108,7 +108,7 @@
         // metadata for secure buffers.
         // If mapping a secure buffers fails, the framework needs to get
         // an error code.
-        err = -EINVAL;
+        err = -EACCES;
     }
 
     //Allow mapping of metadata for all buffers including secure ones, but not
@@ -170,11 +170,12 @@
     ATRACE_CALL();
     if (!module || private_handle_t::validate(handle) < 0)
         return -EINVAL;
-    // The base address received via IPC is invalid in this process
-    // Reset it to 0 here since it will be mapped in lock()
-    private_handle_t* hnd = (private_handle_t*)handle;
-    hnd->base = 0;
-    return gralloc_map_metadata(handle);
+
+    int err =  gralloc_map(module, handle);
+    /* Do not fail register_buffer for secure buffers*/
+    if (err == -EACCES)
+        err = 0;
+    return err;
 }
 
 int gralloc_unregister_buffer(gralloc_module_t const* module,