@@ -82,16 +82,17 @@ Device * gDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT + 1];
82
82
int AddDeviceEndpoint (Device * dev, EmberAfEndpointType * ep, const Span<const EmberAfDeviceType> & deviceTypeList,
83
83
const Span<DataVersion> & dataVersionStorage, chip::EndpointId parentEndpointId = chip::kInvalidEndpointId )
84
84
{
85
- uint8_t index = 0 ;
85
+ uint8_t index = 0 ;
86
+ const int maxRetries = 10 ; // Set the maximum number of retries
86
87
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
87
88
{
88
89
if (nullptr == gDevices [index ])
89
90
{
90
91
gDevices [index ] = dev;
91
92
CHIP_ERROR err;
92
- while (true )
93
+ int retryCount = 0 ;
94
+ while (retryCount < maxRetries)
93
95
{
94
- // Todo: Update this to schedule the work rather than use this lock
95
96
DeviceLayer::StackLock lock;
96
97
dev->SetEndpointId (gCurrentEndpointId );
97
98
dev->SetParentEndpointId (parentEndpointId);
@@ -105,14 +106,17 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
105
106
}
106
107
if (err != CHIP_ERROR_ENDPOINT_EXISTS)
107
108
{
108
- return -1 ;
109
+ return -1 ; // Return error as endpoint addition failed due to an error other than endpoint already exists
109
110
}
110
- // Handle wrap condition
111
+ // Increment the endpoint ID and handle wrap condition
111
112
if (++gCurrentEndpointId < gFirstDynamicEndpointId )
112
113
{
113
114
gCurrentEndpointId = gFirstDynamicEndpointId ;
114
115
}
116
+ retryCount++;
115
117
}
118
+ ChipLogError (DeviceLayer, " Failed to add dynamic endpoint after %d retries" , maxRetries);
119
+ return -1 ; // Return error as all retries are exhausted
116
120
}
117
121
index ++;
118
122
}
@@ -127,7 +131,6 @@ int RemoveDeviceEndpoint(Device * dev)
127
131
{
128
132
if (gDevices [index ] == dev)
129
133
{
130
- // Todo: Update this to schedule the work rather than use this lock
131
134
DeviceLayer::StackLock lock;
132
135
// Silence complaints about unused ep when progress logging
133
136
// disabled.
0 commit comments