Make platform PlatformManager::PostEvent() return status (#9573)
* Make platform PlatformManager::PostEvent() return status
#### Problem
`void PlatformManager::PostEvent()` can fail on some platforms, but does
not report this to callers.
In the #9543 case, an intermediate layer unconditionally returned
`CHIP_NO_ERROR`, and `Inet` code assumed it could actually test whether
`PostEvent()` succeeded.
Fixes #9543 _PacketBuffer leak_
#### Change overview
Made `PlatformManager::PostEvent()` return `CHIP_ERROR`.
Marked it `[[nodiscard]]` to catch all uses, and made callers
propagate or at least log any error.
#### Testing
CI.
* address review comments
* restyle
* replace PostEventLoggingErrors with PostEventOrDie
* fix P6
diff --git a/src/platform/P6/BLEManagerImpl.cpp b/src/platform/P6/BLEManagerImpl.cpp
index 6bc0365..5d28ec2 100644
--- a/src/platform/P6/BLEManagerImpl.cpp
+++ b/src/platform/P6/BLEManagerImpl.cpp
@@ -80,7 +80,10 @@
ChipDeviceEvent bleEvent;
bleEvent.Type = DeviceEventType::kP6BLEEnabledEvt;
- PlatformMgr().PostEvent(&bleEvent);
+ if (PlatformMgr().PostEvent(&bleEvent) != CHIP_NO_ERROR)
+ {
+ return WICED_BT_ERROR;
+ }
}
break;
}
@@ -238,7 +241,7 @@
{
ChipDeviceEvent _event;
_event.Type = DeviceEventType::kCHIPoBLEConnectionEstablished;
- PlatformMgr().PostEvent(&_event);
+ PlatformMgr().PostEventOrDie(&_event);
}
break;
@@ -428,7 +431,7 @@
ChipDeviceEvent advChange;
advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange;
advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Started;
- PlatformMgr().PostEvent(&advChange);
+ err = PlatformMgr().PostEvent(&advChange);
}
}
}
@@ -553,13 +556,18 @@
event.Type = DeviceEventType::kCHIPoBLEWriteReceived;
event.CHIPoBLEWriteReceived.ConId = conn_id;
event.CHIPoBLEWriteReceived.Data = buf;
- PlatformMgr().PostEvent(&event);
+ CHIP_ERROR status = PlatformMgr().PostEvent(&event);
+ if (status != CHIP_NO_ERROR)
+ {
+ result = WICED_BT_GATT_INTERNAL_ERROR;
+ }
buf = NULL;
}
}
else
{
ChipLogError(DeviceLayer, "BLEManagerImpl: Out of buffers during CHIPoBLE RX");
+ result = WICED_BT_GATT_NO_RESOURCES;
}
}
else
@@ -584,7 +592,10 @@
event.Type = (app_chip_service_char_tx_client_char_config[0] != 0) ? DeviceEventType::kCHIPoBLESubscribe
: DeviceEventType::kCHIPoBLEUnsubscribe;
event.CHIPoBLESubscribe.ConId = conn_id;
- PlatformMgr().PostEvent(&event);
+ if (PlatformMgr().PostEvent(&event) != CHIP_NO_ERROR)
+ {
+ return WICED_BT_GATT_INTERNAL_ERROR;
+ }
}
ChipLogProgress(DeviceLayer, "CHIPoBLE %s received",
@@ -617,7 +628,10 @@
ChipDeviceEvent event;
event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm;
event.CHIPoBLEIndicateConfirm.ConId = conn_id;
- PlatformMgr().PostEvent(&event);
+ if (PlatformMgr().PostEvent(&event) != CHIP_NO_ERROR)
+ {
+ return WICED_BT_GATT_INTERNAL_ERROR;
+ }
}
return WICED_BT_GATT_SUCCESS;
}
@@ -691,7 +705,10 @@
ChipLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %u)", p_conn_status->conn_id,
p_conn_status->reason);
- PlatformMgr().PostEvent(&event);
+ if (PlatformMgr().PostEvent(&event) != CHIP_NO_ERROR)
+ {
+ return WICED_BT_GATT_INTERNAL_ERROR;
+ }
// Arrange to re-enable connectable advertising in case it was disabled due to the
// maximum connection limit being reached.