Merge tag 'LA.QSSI.14.0.r1-13400-qssi.0' into staging/lineage-21.0_merge-LA.QSSI.14.0.r1-13400-qssi.0

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

# By Vinoth Jayaram
# Via Linux Build Service Account (1) and Vinoth Jayaram (1)
* tag 'LA.QSSI.14.0.r1-13400-qssi.0':
  commonsys: services: Delete device_obj_ to release the memory

Change-Id: Ie48cd2f76bb6835012917c40afffceb87e79c183
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 2361ab0..b0da5a8 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,6 +82,7 @@
       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) {
@@ -89,7 +90,6 @@
       device_obj_ = nullptr;
       return -1;
     }
-    device_obj_->intf_ = intf;
   }
 
   return 0;
@@ -147,6 +147,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;
@@ -233,6 +234,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);
@@ -246,6 +251,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);
@@ -256,6 +266,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);
@@ -273,6 +288,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);
@@ -287,6 +306,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);
@@ -299,6 +322,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,
@@ -313,6 +340,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,
@@ -327,6 +358,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);
@@ -352,6 +387,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,
@@ -370,6 +409,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);
@@ -382,6 +425,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);
@@ -393,6 +440,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);
@@ -408,6 +459,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);
@@ -437,6 +492,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);
 
@@ -449,6 +508,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);
@@ -459,6 +522,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);
 
@@ -482,6 +549,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,
@@ -494,6 +565,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);
@@ -515,6 +590,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);
 
@@ -540,6 +619,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,
@@ -550,6 +633,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;
@@ -563,6 +650,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;
@@ -576,6 +667,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;
@@ -591,6 +686,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);
@@ -603,6 +702,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);
@@ -630,6 +733,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,
@@ -645,6 +752,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);
@@ -660,6 +771,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];
@@ -682,6 +797,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);
@@ -705,6 +824,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);
@@ -718,6 +841,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);
@@ -728,6 +855,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);
@@ -740,6 +871,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,
@@ -764,6 +899,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);
 
@@ -779,6 +918,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,
@@ -794,6 +937,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);
 
@@ -807,6 +954,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);
 
@@ -820,6 +971,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, {}, {});
@@ -851,6 +1006,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);
@@ -864,6 +1023,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);
@@ -885,6 +1048,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);
@@ -902,6 +1070,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;
@@ -915,6 +1088,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;
@@ -932,6 +1109,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};
@@ -948,6 +1129,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);
@@ -963,6 +1148,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);
@@ -978,6 +1167,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);
@@ -990,16 +1183,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_;
 };