diff --git a/src/app/clusters/groups-server/groups-server.cpp b/src/app/clusters/groups-server/groups-server.cpp index fe5002da1306a1..2e2ed175df34e2 100644 --- a/src/app/clusters/groups-server/groups-server.cpp +++ b/src/app/clusters/groups-server/groups-server.cpp @@ -90,17 +90,16 @@ static bool KeyExists(FabricIndex fabricIndex, GroupId groupId) auto it = provider->IterateGroupKeys(fabricIndex); bool found = false; - while (it->Next(entry) && !found) + while (!found && it->Next(entry)) { - found = (entry.group_id == groupId); + if (entry.group_id == groupId) + { + GroupDataProvider::KeySet keys; + found = (CHIP_NO_ERROR == provider->GetKeySet(fabricIndex, entry.keyset_id, keys)); + } } it->Release(); - if (found) - { - GroupDataProvider::KeySet keys; - found = (CHIP_NO_ERROR == provider->GetKeySet(fabricIndex, entry.keyset_id, keys)); - } return found; }