From d17fc82fcd51303c2fc1e943cc86de284fd07f94 Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Wed, 2 Aug 2023 13:28:39 +0530 Subject: [PATCH] Unlock chip stack before returning from attribute::report() API --- .../esp_matter/esp_matter_attribute_utils.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/components/esp_matter/esp_matter_attribute_utils.cpp b/components/esp_matter/esp_matter_attribute_utils.cpp index 56fdcd12c..8eba7dfa0 100644 --- a/components/esp_matter/esp_matter_attribute_utils.cpp +++ b/components/esp_matter/esp_matter_attribute_utils.cpp @@ -1743,19 +1743,17 @@ esp_err_t get_val_raw(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attrib return ESP_FAIL; } + esp_err_t err = ESP_OK; EmberAfStatus status = emberAfReadAttribute(endpoint_id, cluster_id, attribute_id, value, attribute_size); if (status != EMBER_ZCL_STATUS_SUCCESS) { ESP_LOGE(TAG, "Error getting Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 "'s raw value from matter: 0x%x", endpoint_id, cluster_id, attribute_id, status); - if (lock_status == lock::SUCCESS) { - lock::chip_stack_unlock(); - } - return ESP_FAIL; + err = ESP_FAIL; } if (lock_status == lock::SUCCESS) { lock::chip_stack_unlock(); } - return ESP_OK; + return err; } esp_err_t update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val) @@ -1821,6 +1819,9 @@ esp_err_t report(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_i if (!attribute) { ESP_LOGE(TAG, "Could not find Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32, endpoint_id, cluster_id, attribute_id); + if (lock_status == lock::SUCCESS) { + lock::chip_stack_unlock(); + } return ESP_FAIL; } @@ -1830,6 +1831,9 @@ esp_err_t report(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_i if (val->type != raw_val.type) { ESP_LOGE(TAG, "Attribute type mismatch when trying to report Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32, endpoint_id, cluster_id, attribute_id); + if (lock_status == lock::SUCCESS) { + lock::chip_stack_unlock(); + } return ESP_FAIL; } attribute::set_val(attribute, val);