Skip to content

Commit 19525fc

Browse files
committed
Use a maximum number of retries to exit the loop more reliably
1 parent 9cfcce3 commit 19525fc

File tree

1 file changed

+9
-6
lines changed
  • examples/fabric-bridge-app/linux

1 file changed

+9
-6
lines changed

examples/fabric-bridge-app/linux/main.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,17 @@ Device * gDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT + 1];
8282
int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const EmberAfDeviceType> & deviceTypeList,
8383
const Span<DataVersion> & dataVersionStorage, chip::EndpointId parentEndpointId = chip::kInvalidEndpointId)
8484
{
85-
uint8_t index = 0;
85+
uint8_t index = 0;
86+
const int maxRetries = 10; // Set the maximum number of retries
8687
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
8788
{
8889
if (nullptr == gDevices[index])
8990
{
9091
gDevices[index] = dev;
9192
CHIP_ERROR err;
92-
while (true)
93+
int retryCount = 0;
94+
while (retryCount < maxRetries)
9395
{
94-
// Todo: Update this to schedule the work rather than use this lock
9596
DeviceLayer::StackLock lock;
9697
dev->SetEndpointId(gCurrentEndpointId);
9798
dev->SetParentEndpointId(parentEndpointId);
@@ -105,14 +106,17 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
105106
}
106107
if (err != CHIP_ERROR_ENDPOINT_EXISTS)
107108
{
108-
return -1;
109+
return -1; // Return error as endpoint addition failed due to an error other than endpoint already exists
109110
}
110-
// Handle wrap condition
111+
// Increment the endpoint ID and handle wrap condition
111112
if (++gCurrentEndpointId < gFirstDynamicEndpointId)
112113
{
113114
gCurrentEndpointId = gFirstDynamicEndpointId;
114115
}
116+
retryCount++;
115117
}
118+
ChipLogError(DeviceLayer, "Failed to add dynamic endpoint after %d retries", maxRetries);
119+
return -1; // Return error as all retries are exhausted
116120
}
117121
index++;
118122
}
@@ -127,7 +131,6 @@ int RemoveDeviceEndpoint(Device * dev)
127131
{
128132
if (gDevices[index] == dev)
129133
{
130-
// Todo: Update this to schedule the work rather than use this lock
131134
DeviceLayer::StackLock lock;
132135
// Silence complaints about unused ep when progress logging
133136
// disabled.

0 commit comments

Comments
 (0)