Snap for 6123600 from 10d9ddfe37d067757b28e6d6270d3ce0ab150f9a to qt-qpr2-release

Change-Id: Ic43d0ecd583e2fbb29bc153ba133bdceb0a6abff
diff --git a/msm8998/sdm/libs/hwc2/hwc_session.cpp b/msm8998/sdm/libs/hwc2/hwc_session.cpp
index 0a8576c..f077667 100644
--- a/msm8998/sdm/libs/hwc2/hwc_session.cpp
+++ b/msm8998/sdm/libs/hwc2/hwc_session.cpp
@@ -992,7 +992,7 @@
   int dpy = input_parcel->readInt32();
   int error = android::BAD_VALUE;
 
-  if (dpy > HWC_DISPLAY_VIRTUAL) {
+  if (dpy < HWC_DISPLAY_PRIMARY || dpy > HWC_DISPLAY_VIRTUAL) {
     return android::BAD_VALUE;
   }
 
@@ -1011,7 +1011,7 @@
   int dpy = input_parcel->readInt32();
   int error = android::BAD_VALUE;
 
-  if (dpy > HWC_DISPLAY_VIRTUAL) {
+  if (dpy < HWC_DISPLAY_PRIMARY || dpy > HWC_DISPLAY_VIRTUAL) {
     return android::BAD_VALUE;
   }
 
@@ -1031,7 +1031,7 @@
   int dpy = input_parcel->readInt32();
   int error = android::BAD_VALUE;
 
-  if (dpy > HWC_DISPLAY_VIRTUAL) {
+  if (dpy < HWC_DISPLAY_PRIMARY || dpy > HWC_DISPLAY_VIRTUAL) {
     return android::BAD_VALUE;
   }
 
@@ -1055,7 +1055,7 @@
   int error = android::BAD_VALUE;
   DisplayConfigVariableInfo display_attributes;
 
-  if (dpy > HWC_DISPLAY_VIRTUAL) {
+  if (dpy < HWC_DISPLAY_PRIMARY || dpy >= HWC_NUM_DISPLAY_TYPES || config < 0) {
     return android::BAD_VALUE;
   }
 
@@ -1251,7 +1251,7 @@
   auto mode = static_cast<android_color_mode_t>(input_parcel->readInt32());
   auto device = static_cast<hwc2_device_t *>(this);
 
-  if (display > HWC_DISPLAY_VIRTUAL) {
+  if (display >= HWC_NUM_DISPLAY_TYPES) {
     return -EINVAL;
   }
 
@@ -1266,7 +1266,7 @@
   auto mode = input_parcel->readInt32();
   auto device = static_cast<hwc2_device_t *>(this);
 
-  if (display > HWC_DISPLAY_VIRTUAL) {
+  if (display >= HWC_NUM_DISPLAY_TYPES) {
     return -EINVAL;
   }
 
@@ -1621,7 +1621,7 @@
   SCOPE_LOCK(locker_);
   int dpy = input_parcel->readInt32();
 
-  if (dpy < HWC_DISPLAY_PRIMARY || dpy > HWC_DISPLAY_VIRTUAL) {
+  if (dpy < HWC_DISPLAY_PRIMARY || dpy >= HWC_NUM_DISPLAY_TYPES) {
     return android::BAD_VALUE;
   }