Merge tag 'LA.QSSI.14.0.r1-11200-qssi.0' of https://git.codelinaro.org/clo/la/platform/vendor/qcom-opensource/display-commonsys into lineage-21.0

"LA.QSSI.14.0.r1-11200-qssi.0"

* tag 'LA.QSSI.14.0.r1-11200-qssi.0' of https://git.codelinaro.org/clo/la/platform/vendor/qcom-opensource/display-commonsys:
  gralloc: Add handling for buffer dequeue duration metadata

Change-Id: I0434a47052692f1632c554808f6b8812e8988b6b
diff --git a/.gitupstream b/.gitupstream
new file mode 100644
index 0000000..dde8122
--- /dev/null
+++ b/.gitupstream
@@ -0,0 +1 @@
+https://git.codelinaro.org/clo/la/platform/vendor/qcom-opensource/display-commonsys
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..ad6d5eb
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,5 @@
+soong_namespace {
+    imports: [
+        "vendor/qcom/opensource/commonsys-intf/display"
+    ],
+}
diff --git a/services/config/src/device_impl.cpp b/services/config/src/device_impl.cpp
index 4541368..5d1fcdd 100644
--- a/services/config/src/device_impl.cpp
+++ b/services/config/src/device_impl.cpp
@@ -30,7 +30,7 @@
 /*
  * Changes from Qualcomm Innovation Center are provided under the following license:
  *
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted (subject to the limitations in the
@@ -82,13 +82,13 @@
       return -1;
     }
 
+    device_obj_->intf_ = intf;
     android::status_t status = device_obj_->IDisplayConfig::registerAsService();
     // Unable to start Display Config 2.0 service. Fail Init.
     if (status != android::OK) {
       device_obj_ = nullptr;
       return -1;
     }
-    device_obj_->intf_ = intf;
   }
 
   return 0;
@@ -146,6 +146,7 @@
 
 void DeviceImpl::serviceDied(uint64_t client_handle,
                              const android::wp<::android::hidl::base::V1_0::IBase>& callback) {
+  std::lock_guard<std::shared_mutex> exclusive_lock(shared_mutex_);
   std::lock_guard<std::recursive_mutex> lock(death_service_mutex_);
   auto itr = display_config_map_.find(client_handle);
   std::shared_ptr<DeviceClientContext> client = itr->second;
@@ -232,6 +233,10 @@
   bool connected = false;
   ByteStream output_params;
 
+  if (input_params.size() != sizeof(DisplayType)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   dpy = reinterpret_cast<const DisplayType*>(data);
   int32_t error = intf_->IsDisplayConnected(*dpy, &connected);
@@ -245,6 +250,11 @@
                                                             perform_cb _hidl_cb) {
   const struct StatusParams *display_status;
   const uint8_t *data = input_params.data();
+
+  if (input_params.size() != sizeof(StatusParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   display_status = reinterpret_cast<const StatusParams*>(data);
   int32_t error = intf_->SetDisplayStatus(display_status->dpy,
                                           display_status->status);
@@ -255,6 +265,11 @@
                                                                    perform_cb _hidl_cb) {
   const struct DynRefreshRateParams *dyn_refresh_data;
   const uint8_t *data = input_params.data();
+
+  if (input_params.size() != sizeof(DynRefreshRateParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   dyn_refresh_data = reinterpret_cast<const DynRefreshRateParams*>(data);
   int32_t error = intf_->ConfigureDynRefreshRate(dyn_refresh_data->op,
                                                  dyn_refresh_data->refresh_rate);
@@ -272,6 +287,10 @@
     return;
   }
 
+  if (input_params.size() != sizeof(DisplayType)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   dpy = reinterpret_cast<const DisplayType*>(data);
   int32_t error = intf_->GetConfigCount(*dpy, &count);
@@ -286,6 +305,10 @@
   uint32_t config = 0;
   ByteStream output_params;
 
+  if (input_params.size() != sizeof(DisplayType)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   dpy = reinterpret_cast<const DisplayType*>(data);
   int32_t error = intf_->GetActiveConfig(*dpy, &config);
@@ -298,6 +321,10 @@
                                                            perform_cb _hidl_cb) {
   const struct ConfigParams *set_active_cfg_data;
 
+  if (input_params.size() != sizeof(ConfigParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   set_active_cfg_data = reinterpret_cast<const ConfigParams*>(data);
   int32_t error = intf_->SetActiveConfig(set_active_cfg_data->dpy,
@@ -312,6 +339,10 @@
   ByteStream output_params;
   int32_t error = -EINVAL;
 
+  if (input_params.size() != sizeof(AttributesParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   get_disp_attr_data = reinterpret_cast<const AttributesParams*>(data);
   error = intf_->GetDisplayAttributes(get_disp_attr_data->config_index, get_disp_attr_data->dpy,
@@ -326,6 +357,10 @@
   const uint32_t *level;
   int32_t error = 0;
 
+  if (input_params.size() != sizeof(uint32_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   level = reinterpret_cast<const uint32_t*>(data);
   error = intf_->SetPanelBrightness(*level);
@@ -351,6 +386,10 @@
   const struct MinHdcpEncLevelChangedParams *min_hdcp_enc_level_data;
   int32_t error = 0;
 
+  if (input_params.size() != sizeof(MinHdcpEncLevelChangedParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   min_hdcp_enc_level_data = reinterpret_cast<const MinHdcpEncLevelChangedParams*>(data);
   error = intf_->MinHdcpEncryptionLevelChanged(min_hdcp_enc_level_data->dpy,
@@ -369,6 +408,10 @@
   const struct PartialUpdateParams *partial_update_data;
   int32_t error = 0;
 
+  if (input_params.size() != sizeof(PartialUpdateParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   partial_update_data = reinterpret_cast<const PartialUpdateParams*>(data);
   error = intf_->ControlPartialUpdate(partial_update_data->dpy, partial_update_data->enable);
@@ -381,6 +424,10 @@
   const bool *on;
   int32_t error = 0;
 
+  if (input_params.size() != sizeof(bool)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   on = reinterpret_cast<const bool*>(data);
   error = intf_->ToggleScreenUpdate(on);
@@ -392,6 +439,10 @@
                                                           perform_cb _hidl_cb) {
   const uint32_t *timeout_value;
 
+  if (input_params.size() != sizeof(uint32_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   timeout_value = reinterpret_cast<const uint32_t*>(data);
   int32_t error = intf_->SetIdleTimeout(*timeout_value);
@@ -407,6 +458,10 @@
   int32_t *data_output;
   int32_t error = -EINVAL;
 
+  if (input_params.size() != sizeof(DisplayType)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   dpy = reinterpret_cast<const DisplayType*>(data);
   error = intf_->GetHDRCapabilities(*dpy, &hdr_caps);
@@ -436,6 +491,10 @@
                                                                  perform_cb _hidl_cb) {
   const uint32_t *launch_status_data;
 
+  if (input_params.size() != sizeof(uint32_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   launch_status_data = reinterpret_cast<const uint32_t*>(data);
 
@@ -448,6 +507,10 @@
                                                            perform_cb _hidl_cb) {
   const CameraSmoothInfo *camera_info;
 
+  if (input_params.size() != sizeof(CameraSmoothInfo)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   camera_info = reinterpret_cast<const CameraSmoothInfo*>(data);
   int32_t error = intf_->SetCameraSmoothInfo(camera_info->op, camera_info->fps);
@@ -458,6 +521,10 @@
                                                                 perform_cb _hidl_cb) {
   const bool *enable;
 
+  if (input_params.size() != sizeof(bool)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   enable = reinterpret_cast<const bool*>(data);
 
@@ -481,6 +548,10 @@
                                                                perform_cb _hidl_cb) {
   const struct AnimationParams *display_animating_data;
 
+  if (input_params.size() != sizeof(AnimationParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   display_animating_data = reinterpret_cast<const AnimationParams*>(data);
   int32_t error = intf_->SetDisplayAnimating(display_animating_data->display_id,
@@ -493,6 +564,10 @@
                                                                     perform_cb _hidl_cb) {
   const struct IdlePcParams *idle_pc_data;
 
+  if (input_params.size() != sizeof(IdlePcParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   idle_pc_data = reinterpret_cast<const IdlePcParams*>(data);
   int32_t error = intf_->ControlIdlePowerCollapse(idle_pc_data->enable, idle_pc_data->synchronous);
@@ -514,6 +589,10 @@
                                                                perform_cb _hidl_cb) {
   const struct DppsAdRoiParams *ad_roi_data;
 
+  if (input_params.size() != sizeof(DppsAdRoiParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   ad_roi_data = reinterpret_cast<const DppsAdRoiParams*>(data);
 
@@ -539,6 +618,10 @@
                                                         perform_cb _hidl_cb) {
   const struct PowerModeParams *set_power_mode_data;
 
+  if (input_params.size() != sizeof(PowerModeParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   set_power_mode_data = reinterpret_cast<const PowerModeParams*>(data);
   int32_t error = intf_->SetPowerMode(set_power_mode_data->disp_id,
@@ -549,6 +632,10 @@
 void DeviceImpl::DeviceClientContext::ParseIsPowerModeOverrideSupported(
                                       const ByteStream &input_params,
                                       perform_cb _hidl_cb) {
+  if (input_params.size() != sizeof(uint32_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   const uint32_t *disp_id = reinterpret_cast<const uint32_t*>(data);
   bool supported = false;
@@ -562,6 +649,10 @@
 
 void DeviceImpl::DeviceClientContext::ParseIsHdrSupported(const ByteStream &input_params,
                                                           perform_cb _hidl_cb) {
+  if (input_params.size() != sizeof(uint32_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   const uint32_t *disp_id = reinterpret_cast<const uint32_t*>(data);
   bool supported = false;
@@ -575,6 +666,10 @@
 
 void DeviceImpl::DeviceClientContext::ParseIsWcgSupported(const ByteStream &input_params,
                                                           perform_cb _hidl_cb) {
+  if (input_params.size() != sizeof(int32_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   const int32_t *disp_id = reinterpret_cast<const int32_t*>(data);
   bool supported = false;
@@ -590,6 +685,10 @@
                                                           perform_cb _hidl_cb) {
   const struct LayerMaskParams *layer_mask_data;
 
+  if (input_params.size() != sizeof(LayerMaskParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   layer_mask_data = reinterpret_cast<const LayerMaskParams*>(data);
   int32_t error = intf_->SetLayerAsMask(layer_mask_data->disp_id, layer_mask_data->layer_id);
@@ -602,6 +701,10 @@
   std::string value;
   ByteStream output_params;
 
+  if (input_params.size() == 0) {
+    _hidl_cb(-ENODATA, {}, {});
+     return;
+  }
   const uint8_t *data = input_params.data();
   const char *name = reinterpret_cast<const char *>(data);
   std::string prop_name(name);
@@ -629,6 +732,10 @@
                                       perform_cb _hidl_cb) {
   const struct PanelLumAttrParams *panel_lum_attr_data;
 
+  if (input_params.size() != sizeof(PanelLumAttrParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   panel_lum_attr_data = reinterpret_cast<const PanelLumAttrParams*>(data);
   int32_t error = intf_->SetPanelLuminanceAttributes(panel_lum_attr_data->disp_id,
@@ -644,6 +751,10 @@
   bool is_builtin = false;
   ByteStream output_params;
 
+  if (input_params.size() != sizeof(uint32_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   disp_id = reinterpret_cast<const uint32_t*>(data);
   int32_t error = intf_->IsBuiltInDisplay(*disp_id, &is_builtin);
@@ -659,6 +770,10 @@
                                                               perform_cb _hidl_cb) {
   const struct CwbBufferParams *cwb_buffer_data;
 
+  if (input_params.size() != sizeof(CwbBufferParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   cwb_buffer_data = reinterpret_cast<const CwbBufferParams*>(data);
   hidl_handle buffer = input_handles[0];
@@ -681,6 +796,10 @@
   std::vector<uint64_t> bit_clks;
   uint64_t *bit_clks_data;
 
+  if (input_params.size() != sizeof(uint32_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   disp_id = reinterpret_cast<const uint32_t*>(data);
   int32_t error = intf_->GetSupportedDSIBitClks(*disp_id, &bit_clks);
@@ -704,6 +823,10 @@
   uint64_t bit_clk = 0;
   ByteStream output_params;
 
+  if (input_params.size() != sizeof(uint32_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   disp_id = reinterpret_cast<const uint32_t*>(data);
   int32_t error = intf_->GetDSIClk(*disp_id, &bit_clk);
@@ -717,6 +840,10 @@
                                                      perform_cb _hidl_cb) {
   const struct DsiClkParams *set_dsi_clk_data;
 
+  if (input_params.size() != sizeof(DsiClkParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   set_dsi_clk_data = reinterpret_cast<const DsiClkParams*>(data);
   int32_t error = intf_->SetDSIClk(set_dsi_clk_data->disp_id, set_dsi_clk_data->bit_clk);
@@ -727,6 +854,10 @@
                                                         perform_cb _hidl_cb) {
   const struct QsyncModeParams *set_qsync_mode_data;
 
+  if (input_params.size() != sizeof(QsyncModeParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   set_qsync_mode_data = reinterpret_cast<const QsyncModeParams*>(data);
   int32_t error = intf_->SetQsyncMode(set_qsync_mode_data->disp_id, set_qsync_mode_data->mode);
@@ -739,6 +870,10 @@
   bool is_smart = false;
   ByteStream output_params;
 
+  if (input_params.size() != sizeof(SmartPanelCfgParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   smart_panel_cfg_data = reinterpret_cast<const SmartPanelCfgParams*>(data);
   int32_t error = intf_->IsSmartPanelConfig(smart_panel_cfg_data->disp_id,
@@ -763,6 +898,10 @@
                                                                 perform_cb _hidl_cb) {
   const struct VdsParams *vds_input_data;
 
+  if (input_params.size() != sizeof(VdsParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   vds_input_data = reinterpret_cast<const VdsParams*>(data);
 
@@ -778,6 +917,10 @@
   bool supported = false;
   ByteStream output_params;
 
+  if (input_params.size() != sizeof(RotatorFormatParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   input_data = reinterpret_cast<const RotatorFormatParams*>(data);
   int32_t error = intf_->IsRotatorSupportedFormat(input_data->hal_format, input_data->ubwc,
@@ -793,6 +936,10 @@
                                                                 perform_cb _hidl_cb) {
   const bool *enable;
 
+  if (input_params.size() != sizeof(bool)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   enable = reinterpret_cast<const bool*>(data);
 
@@ -806,6 +953,10 @@
                                                                      perform_cb _hidl_cb) {
   const bool *enable;
 
+  if (input_params.size() != sizeof(bool)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   enable = reinterpret_cast<const bool*>(data);
 
@@ -819,6 +970,10 @@
   const struct TUIEventParams *input_data =
                reinterpret_cast<const TUIEventParams*>(input_params.data());
 
+  if (input_params.size() != sizeof(TUIEventParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   int32_t error = intf_->SendTUIEvent(input_data->dpy, input_data->tui_event_type);
 
   _hidl_cb(error, {}, {});
@@ -850,6 +1005,10 @@
   uint32_t disp_hw_id = 0;
   ByteStream output_params;
 
+  if (input_params.size() != sizeof(uint32_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   const uint32_t *disp_id = reinterpret_cast<const uint32_t*>(data);
   int32_t error = intf_->GetDisplayHwId(*disp_id, &disp_hw_id);
@@ -863,6 +1022,10 @@
   ByteStream output_params;
   std::vector<uint32_t> refresh_rates;
 
+  if (input_params.size() != sizeof(DisplayType)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   const DisplayType *dpy = reinterpret_cast<const DisplayType *>(data);
   int32_t error = intf_->GetSupportedDisplayRefreshRates(*dpy, &refresh_rates);
@@ -884,6 +1047,11 @@
 void DeviceImpl::DeviceClientContext::ParseIsRCSupported(const ByteStream &input_params,
                                                          perform_cb _hidl_cb) {
   const uint8_t *data = input_params.data();
+
+  if (input_params.size() != sizeof(uint32_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint32_t *disp_id = reinterpret_cast<const uint32_t*>(data);
   bool supported = false;
   int32_t error = intf_->IsRCSupported(*disp_id, &supported);
@@ -901,6 +1069,11 @@
   }
 
   const struct SupportedModesParams *supported_modes_data;
+
+  if (input_params.size() != sizeof(SupportedModesParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   bool supported = false;
   ByteStream output_params;
@@ -914,6 +1087,10 @@
 
 void DeviceImpl::DeviceClientContext::ParseGetDisplayType(const ByteStream &input_params,
                                                           perform_cb _hidl_cb) {
+  if (input_params.size() != sizeof(uint64_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   const uint64_t *physical_disp_id = reinterpret_cast<const uint64_t*>(data);
   DisplayType disp_type = DisplayConfig::DisplayType::kInvalid;
@@ -931,6 +1108,10 @@
 
 void DeviceImpl::DeviceClientContext::ParseGetDisplayTileCount(const ByteStream &input_params,
                                                                perform_cb _hidl_cb) {
+  if (input_params.size() != sizeof(uint64_t)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint64_t *data = reinterpret_cast<const uint64_t*>(input_params.data());
   uint64_t physical_disp_id = data ? *data : 0;
   uint32_t num_tiles[2] = {0, 0};
@@ -947,6 +1128,10 @@
                                                              perform_cb _hidl_cb) {
   struct PowerModeTiledParams set_power_mode_tiled_data = {};
 
+  if (input_params.size() != sizeof(PowerModeTiledParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   if (data) {
     set_power_mode_tiled_data = *reinterpret_cast<const PowerModeTiledParams*>(data);
@@ -962,6 +1147,10 @@
                                                                    perform_cb _hidl_cb) {
   struct PanelBrightnessTiledParams set_panel_brightness_tiled_data = {};
 
+  if (input_params.size() != sizeof(PanelBrightnessTiledParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   if (data) {
     set_panel_brightness_tiled_data = *reinterpret_cast<const PanelBrightnessTiledParams*>(data);
@@ -977,6 +1166,10 @@
                                                                   perform_cb _hidl_cb) {
   struct WiderModePrefParams set_wider_mode_pref_data = {};
 
+  if (input_params.size() != sizeof(WiderModePrefParams)) {
+    _hidl_cb(-ENODATA, {}, {});
+    return;
+  }
   const uint8_t *data = input_params.data();
   if (data) {
     set_wider_mode_pref_data = *reinterpret_cast<const WiderModePrefParams*>(data);
@@ -989,16 +1182,21 @@
 Return<void> DeviceImpl::perform(uint64_t client_handle, uint32_t op_code,
                                  const ByteStream &input_params, const HandleStream &input_handles,
                                  perform_cb _hidl_cb) {
+  std::shared_lock<std::shared_mutex> shared_lock(shared_mutex_);
   int32_t error = 0;
-  std::lock_guard<std::recursive_mutex> lock(death_service_mutex_);
-  auto itr = display_config_map_.find(client_handle);
-  if (itr == display_config_map_.end()) {
-    error = -EINVAL;
-    _hidl_cb(error, {}, {});
-    return Void();
+  std::shared_ptr<DeviceClientContext> client = nullptr;
+
+  {
+    std::lock_guard<std::recursive_mutex> lock(death_service_mutex_);
+    auto itr = display_config_map_.find(client_handle);
+    if (itr == display_config_map_.end()) {
+      error = -EINVAL;
+      _hidl_cb(error, {}, {});
+      return Void();
+    }
+    client = itr->second;
   }
 
-  std::shared_ptr<DeviceClientContext> client = itr->second;
   if (!client) {
     error = -EINVAL;
     _hidl_cb(error, {}, {});
diff --git a/services/config/src/device_impl.h b/services/config/src/device_impl.h
index cf60366..3433d05 100644
--- a/services/config/src/device_impl.h
+++ b/services/config/src/device_impl.h
@@ -74,6 +74,7 @@
 #include <utility>
 #include <string>
 #include <vector>
+#include <shared_mutex>
 
 #include "opcode_types.h"
 
@@ -187,6 +188,7 @@
   std::map<uint64_t, std::shared_ptr<DeviceClientContext>> display_config_map_;
   uint64_t client_id_ = 0;
   std::recursive_mutex death_service_mutex_;
+  std::shared_mutex shared_mutex_;
   static DeviceImpl *device_obj_;
   static std::mutex device_lock_;
 };