components/esp_matter: propagate error code from attribute report on v1.4

attribute::report() was ignoring the return value from set_val() and
always returning ESP_OK. This hid errors like ESP_ERR_NOT_SUPPORTED
for internally managed attributes (e.g., BooleanState::StateValue).

This fix:
- Propagates the error from set_val() back to the caller
- Checks return value of get_val() in report()
- Adds void cast to intentionally unchecked get_data_from_attr_val()
  call in update()

Related: https://github.com/espressif/esp-matter/issues/1724
Backport of !1441 (main), !1458 (v1.5)
This commit is contained in:
Shubham Patil
2026-03-23 16:10:28 +05:30
parent c3bdde6567
commit fb80d15634
@@ -1,4 +1,4 @@
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
// Copyright 2021-2026 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -2081,7 +2081,8 @@ esp_err_t update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_i
}
return ESP_ERR_NO_MEM;
}
get_data_from_attr_val(val, &attribute_type, &attribute_size, value);
/* Ignore return value: identical call succeeded above with NULL value buffer */
(void)get_data_from_attr_val(val, &attribute_type, &attribute_size, value);
/* Update matter */
Status status = Status::Success;
@@ -2126,7 +2127,15 @@ esp_err_t report(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_i
/* Update attribute */
esp_matter_attr_val_t raw_val = esp_matter_invalid(NULL);
attribute::get_val(attribute, &raw_val);
esp_err_t err = attribute::get_val(attribute, &raw_val);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to get the attribute value for Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " err: %d",
endpoint_id, cluster_id, attribute_id, err);
if (lock_status == lock::SUCCESS) {
lock::chip_stack_unlock();
}
return err;
}
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);
@@ -2135,7 +2144,15 @@ esp_err_t report(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_i
}
return ESP_FAIL;
}
attribute::set_val(attribute, val);
err = attribute::set_val(attribute, val);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to set attribute value for Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " err: %d",
endpoint_id, cluster_id, attribute_id, err);
if (lock_status == lock::SUCCESS) {
lock::chip_stack_unlock();
}
return err;
}
/* Report attribute */
MatterReportingAttributeChangeCallback(endpoint_id, cluster_id, attribute_id);