[automerger skipped] gralloc: Additional buffer validation in getTransportSize am: 9a1a6e5eb6 -s ours am: 31fda111e0 -s ours am: dec1d9e0a9 -s ours

am skip reason: Change-Id Ife686b996220df8094216a7e55e66176fe6c3521 with SHA-1 9a1a6e5eb6 is in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/qcom/sdm845/display/+/11590991

Change-Id: Id0d8a101970a9728c82718d7e3aab2d284aa25be
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..d97975c
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,3 @@
+third_party {
+  license_type: NOTICE
+}
diff --git a/gpu_tonemapper/glengine.cpp b/gpu_tonemapper/glengine.cpp
index 35e1932..bf3b58a 100644
--- a/gpu_tonemapper/glengine.cpp
+++ b/gpu_tonemapper/glengine.cpp
@@ -315,36 +315,30 @@
 //-----------------------------------------------------------------------------
 {
   for (GLint error = glGetError(); error; error = glGetError()) {
-    char *pError;
+    const char *pError = "<unknown error>";
     switch (error) {
       case GL_NO_ERROR:
-        pError = (char *)"GL_NO_ERROR";
+        pError = "GL_NO_ERROR";
         break;
       case GL_INVALID_ENUM:
-        pError = (char *)"GL_INVALID_ENUM";
+        pError = "GL_INVALID_ENUM";
         break;
       case GL_INVALID_VALUE:
-        pError = (char *)"GL_INVALID_VALUE";
+        pError = "GL_INVALID_VALUE";
         break;
       case GL_INVALID_OPERATION:
-        pError = (char *)"GL_INVALID_OPERATION";
+        pError = "GL_INVALID_OPERATION";
         break;
       case GL_OUT_OF_MEMORY:
-        pError = (char *)"GL_OUT_OF_MEMORY";
+        pError = "GL_OUT_OF_MEMORY";
         break;
       case GL_INVALID_FRAMEBUFFER_OPERATION:
-        pError = (char *)"GL_INVALID_FRAMEBUFFER_OPERATION";
+        pError = "GL_INVALID_FRAMEBUFFER_OPERATION";
         break;
-
-      default:
-        ALOGE("glError (0x%x) %s:%d\n", error, file, line);
-        return;
     }
 
     ALOGE("glError (%s) %s:%d\n", pError, file, line);
-    return;
   }
-  return;
 }
 
 //-----------------------------------------------------------------------------
@@ -357,59 +351,54 @@
       break;
     }
 
-    char *pError;
+    const char *pError = "<unknown error>";
     switch (error) {
       case EGL_SUCCESS:
-        pError = (char *)"EGL_SUCCESS";
+        pError = "EGL_SUCCESS";
         break;
       case EGL_NOT_INITIALIZED:
-        pError = (char *)"EGL_NOT_INITIALIZED";
+        pError = "EGL_NOT_INITIALIZED";
         break;
       case EGL_BAD_ACCESS:
-        pError = (char *)"EGL_BAD_ACCESS";
+        pError = "EGL_BAD_ACCESS";
         break;
       case EGL_BAD_ALLOC:
-        pError = (char *)"EGL_BAD_ALLOC";
+        pError = "EGL_BAD_ALLOC";
         break;
       case EGL_BAD_ATTRIBUTE:
-        pError = (char *)"EGL_BAD_ATTRIBUTE";
+        pError = "EGL_BAD_ATTRIBUTE";
         break;
       case EGL_BAD_CONTEXT:
-        pError = (char *)"EGL_BAD_CONTEXT";
+        pError = "EGL_BAD_CONTEXT";
         break;
       case EGL_BAD_CONFIG:
-        pError = (char *)"EGL_BAD_CONFIG";
+        pError = "EGL_BAD_CONFIG";
         break;
       case EGL_BAD_CURRENT_SURFACE:
-        pError = (char *)"EGL_BAD_CURRENT_SURFACE";
+        pError = "EGL_BAD_CURRENT_SURFACE";
         break;
       case EGL_BAD_DISPLAY:
-        pError = (char *)"EGL_BAD_DISPLAY";
+        pError = "EGL_BAD_DISPLAY";
         break;
       case EGL_BAD_SURFACE:
-        pError = (char *)"EGL_BAD_SURFACE";
+        pError = "EGL_BAD_SURFACE";
         break;
       case EGL_BAD_MATCH:
-        pError = (char *)"EGL_BAD_MATCH";
+        pError = "EGL_BAD_MATCH";
         break;
       case EGL_BAD_PARAMETER:
-        pError = (char *)"EGL_BAD_PARAMETER";
+        pError = "EGL_BAD_PARAMETER";
         break;
       case EGL_BAD_NATIVE_PIXMAP:
-        pError = (char *)"EGL_BAD_NATIVE_PIXMAP";
+        pError = "EGL_BAD_NATIVE_PIXMAP";
         break;
       case EGL_BAD_NATIVE_WINDOW:
-        pError = (char *)"EGL_BAD_NATIVE_WINDOW";
+        pError = "EGL_BAD_NATIVE_WINDOW";
         break;
       case EGL_CONTEXT_LOST:
-        pError = (char *)"EGL_CONTEXT_LOST";
+        pError = "EGL_CONTEXT_LOST";
         break;
-      default:
-        ALOGE("eglError (0x%x) %s:%d\n", error, file, line);
-        return;
     }
     ALOGE("eglError (%s) %s:%d\n", pError, file, line);
-    return;
   }
-  return;
 }
diff --git a/liblight/Android.mk b/liblight/Android.mk
index d485c7e..3db3634 100644
--- a/liblight/Android.mk
+++ b/liblight/Android.mk
@@ -27,7 +27,7 @@
 endif
 LOCAL_CFLAGS += -Wno-error
 LOCAL_CLANG  := true
-LOCAL_MODULE := lights.$(TARGET_BOARD_PLATFORM)
+LOCAL_MODULE := lights.qcom
 LOCAL_MODULE_TAGS := optional
 LOCAL_VENDOR_MODULE := true
 
diff --git a/sdm/libs/hwc2/hwc_callbacks.cpp b/sdm/libs/hwc2/hwc_callbacks.cpp
index 48593f1..806214b 100644
--- a/sdm/libs/hwc2/hwc_callbacks.cpp
+++ b/sdm/libs/hwc2/hwc_callbacks.cpp
@@ -35,6 +35,7 @@
 namespace sdm {
 
 HWC2::Error HWCCallbacks::Hotplug(hwc2_display_t display, HWC2::Connection state) {
+  std::lock_guard<std::mutex> hotplug_lock(hotplug_mutex_);
   if (!hotplug_) {
     return HWC2::Error::NoResources;
   }
@@ -43,6 +44,7 @@
 }
 
 HWC2::Error HWCCallbacks::Refresh(hwc2_display_t display) {
+  std::lock_guard<std::mutex> refresh_lock(refresh_mutex_);
   if (!refresh_) {
     return HWC2::Error::NoResources;
   }
@@ -51,6 +53,7 @@
 }
 
 HWC2::Error HWCCallbacks::Vsync(hwc2_display_t display, int64_t timestamp) {
+  std::lock_guard<std::mutex> vsync_lock(vsync_mutex_);
   if (!vsync_) {
     return HWC2::Error::NoResources;
   }
@@ -62,18 +65,21 @@
 HWC2::Error HWCCallbacks::Register(HWC2::Callback descriptor, hwc2_callback_data_t callback_data,
                                    hwc2_function_pointer_t pointer) {
   switch (descriptor) {
-    case HWC2::Callback::Hotplug:
+    case HWC2::Callback::Hotplug: {
+      std::lock_guard<std::mutex> hotplug_lock(hotplug_mutex_);
       hotplug_data_ = callback_data;
       hotplug_ = reinterpret_cast<HWC2_PFN_HOTPLUG>(pointer);
-      break;
-    case HWC2::Callback::Refresh:
+    } break;
+    case HWC2::Callback::Refresh: {
+      std::lock_guard<std::mutex> refresh_lock(refresh_mutex_);
       refresh_data_ = callback_data;
       refresh_ = reinterpret_cast<HWC2_PFN_REFRESH>(pointer);
-      break;
-    case HWC2::Callback::Vsync:
+    } break;
+    case HWC2::Callback::Vsync: {
+      std::lock_guard<std::mutex> vsync_lock(vsync_mutex_);
       vsync_data_ = callback_data;
       vsync_ = reinterpret_cast<HWC2_PFN_VSYNC>(pointer);
-      break;
+    } break;
     default:
       return HWC2::Error::BadParameter;
   }
diff --git a/sdm/libs/hwc2/hwc_callbacks.h b/sdm/libs/hwc2/hwc_callbacks.h
index d3f4e52..8cb60fc 100644
--- a/sdm/libs/hwc2/hwc_callbacks.h
+++ b/sdm/libs/hwc2/hwc_callbacks.h
@@ -36,6 +36,8 @@
 #undef HWC2_INCLUDE_STRINGIFICATION
 #undef HWC2_USE_CPP11
 
+#include <mutex>
+
 namespace sdm {
 
 class HWCCallbacks {
@@ -56,6 +58,10 @@
   HWC2_PFN_HOTPLUG hotplug_ = nullptr;
   HWC2_PFN_REFRESH refresh_ = nullptr;
   HWC2_PFN_VSYNC vsync_ = nullptr;
+
+  std::mutex hotplug_mutex_;
+  std::mutex refresh_mutex_;
+  std::mutex vsync_mutex_;
 };
 
 }  // namespace sdm