Skip to content

Commit 7a7670f

Browse files
nodiscard ChipError Batch project-chip#6: controller code (project-chip#41864)
* Batch project-chip#6 nodiscard errors: controller code * Restyle * Fix CI * Fix CI: unused var because ChipLogProgress is no-op * Update src/controller/webrtc/WebRTCTransportProviderClient.cpp Co-authored-by: Boris Zbarsky <[email protected]> * Apply review suggestions * Restyle --------- Co-authored-by: Boris Zbarsky <[email protected]>
1 parent 02fa94a commit 7a7670f

26 files changed

+138
-126
lines changed

src/controller/AutoCommissioner.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ using chip::app::DataModel::NullNullable;
3535

3636
AutoCommissioner::AutoCommissioner()
3737
{
38-
SetCommissioningParameters(CommissioningParameters());
38+
TEMPORARY_RETURN_IGNORED SetCommissioningParameters(CommissioningParameters());
3939
}
4040

4141
AutoCommissioner::~AutoCommissioner() {}
@@ -143,7 +143,7 @@ CHIP_ERROR AutoCommissioner::SetCommissioningParameters(const CommissioningParam
143143
else
144144
{
145145
ChipLogProgress(Controller, "Setting attestation nonce to random value");
146-
Crypto::DRBG_get_bytes(mAttestationNonce, sizeof(mAttestationNonce));
146+
TEMPORARY_RETURN_IGNORED Crypto::DRBG_get_bytes(mAttestationNonce, sizeof(mAttestationNonce));
147147
}
148148
mParams.SetAttestationNonce(ByteSpan(mAttestationNonce, sizeof(mAttestationNonce)));
149149

@@ -156,7 +156,7 @@ CHIP_ERROR AutoCommissioner::SetCommissioningParameters(const CommissioningParam
156156
else
157157
{
158158
ChipLogProgress(Controller, "Setting CSR nonce to random value");
159-
Crypto::DRBG_get_bytes(mCSRNonce, sizeof(mCSRNonce));
159+
TEMPORARY_RETURN_IGNORED Crypto::DRBG_get_bytes(mCSRNonce, sizeof(mCSRNonce));
160160
}
161161
mParams.SetCSRNonce(ByteSpan(mCSRNonce, sizeof(mCSRNonce)));
162162

@@ -184,7 +184,7 @@ CHIP_ERROR AutoCommissioner::SetCommissioningParameters(const CommissioningParam
184184
auto span = MutableCharSpan(mTimeZoneNames[i], kMaxTimeZoneNameLen);
185185
// The buffer backing "span" is statically allocated and is of size kMaxSupportedTimeZones, so this should never
186186
// fail.
187-
CopyCharSpanToMutableCharSpan(params.GetTimeZone().Value()[i].name.Value(), span);
187+
TEMPORARY_RETURN_IGNORED CopyCharSpanToMutableCharSpan(params.GetTimeZone().Value()[i].name.Value(), span);
188188
mTimeZoneBuf[i].name.SetValue(span);
189189
}
190190
else
@@ -203,7 +203,7 @@ CHIP_ERROR AutoCommissioner::SetCommissioningParameters(const CommissioningParam
203203
{
204204
// The buffer backing "span" is statically allocated and is of size kMaxDefaultNtpSize.
205205
auto span = MutableCharSpan(mDefaultNtp, kMaxDefaultNtpSize);
206-
CopyCharSpanToMutableCharSpan(params.GetDefaultNTP().Value().Value(), span);
206+
TEMPORARY_RETURN_IGNORED CopyCharSpanToMutableCharSpan(params.GetDefaultNTP().Value().Value(), span);
207207
auto default_ntp = MakeNullable(CharSpan(mDefaultNtp, params.GetDefaultNTP().Value().Value().size()));
208208
mParams.SetDefaultNTP(default_ntp);
209209
}

src/controller/CHIPDeviceController.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void DeviceController::Shutdown()
422422

423423
if (mDeleteFromFabricTableOnShutdown)
424424
{
425-
mSystemState->Fabrics()->Delete(mFabricIndex);
425+
TEMPORARY_RETURN_IGNORED mSystemState->Fabrics()->Delete(mFabricIndex);
426426
}
427427
else if (mRemoveFromFabricTableOnShutdown)
428428
{
@@ -577,8 +577,9 @@ void DeviceCommissioner::Shutdown()
577577
}
578578
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY
579579
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
580-
WiFiPAF::WiFiPAFLayer::GetWiFiPAFLayer().Shutdown(
581-
[](uint32_t id, WiFiPAF::WiFiPafRole role) { DeviceLayer::ConnectivityMgr().WiFiPAFShutdown(id, role); });
580+
WiFiPAF::WiFiPAFLayer::GetWiFiPAFLayer().Shutdown([](uint32_t id, WiFiPAF::WiFiPafRole role) {
581+
TEMPORARY_RETURN_IGNORED DeviceLayer::ConnectivityMgr().WiFiPAFShutdown(id, role);
582+
});
582583
#endif
583584

584585
// Release everything from the commissionee device pool here.
@@ -639,7 +640,7 @@ void DeviceCommissioner::ReleaseCommissioneeDevice(CommissioneeDeviceProxy * dev
639640
if (readerTransport)
640641
{
641642
ChipLogProgress(Controller, "Stopping discovery of all NFC tags");
642-
readerTransport->StopDiscoveringTags();
643+
TEMPORARY_RETURN_IGNORED readerTransport->StopDiscoveringTags();
643644
}
644645
#endif
645646

@@ -814,21 +815,18 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
814815
// The RendezvousParameters argument needs to be recovered if the search succeed, so save them
815816
// for later.
816817
mRendezvousParametersForDeviceDiscoveredOverBle = params;
817-
SuccessOrExit(err = mSystemState->BleLayer()->NewBleConnectionByObject(params.GetDiscoveredObject(), this,
818-
OnDiscoveredDeviceOverBleSuccess,
819-
OnDiscoveredDeviceOverBleError));
820-
ExitNow(CHIP_NO_ERROR);
818+
ExitNow(err = mSystemState->BleLayer()->NewBleConnectionByObject(
819+
params.GetDiscoveredObject(), this, OnDiscoveredDeviceOverBleSuccess, OnDiscoveredDeviceOverBleError));
821820
}
822821
else if (params.HasDiscriminator())
823822
{
824823
// The RendezvousParameters argument needs to be recovered if the search succeed, so save them
825824
// for later.
826825
mRendezvousParametersForDeviceDiscoveredOverBle = params;
827826

828-
SuccessOrExit(err = mSystemState->BleLayer()->NewBleConnectionByDiscriminator(params.GetSetupDiscriminator().value(),
829-
this, OnDiscoveredDeviceOverBleSuccess,
830-
OnDiscoveredDeviceOverBleError));
831-
ExitNow(CHIP_NO_ERROR);
827+
ExitNow(err = mSystemState->BleLayer()->NewBleConnectionByDiscriminator(params.GetSetupDiscriminator().value(), this,
828+
OnDiscoveredDeviceOverBleSuccess,
829+
OnDiscoveredDeviceOverBleError));
832830
}
833831
else
834832
{
@@ -854,9 +852,8 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
854852
.discriminator = discriminator };
855853
ReturnErrorOnFailure(
856854
DeviceLayer::ConnectivityMgr().GetWiFiPAF()->AddPafSession(WiFiPAF::PafInfoAccess::kAccNodeInfo, sessionInfo));
857-
DeviceLayer::ConnectivityMgr().WiFiPAFSubscribe(discriminator, reinterpret_cast<void *>(this),
858-
OnWiFiPAFSubscribeComplete, OnWiFiPAFSubscribeError);
859-
ExitNow(CHIP_NO_ERROR);
855+
ExitNow(err = DeviceLayer::ConnectivityMgr().WiFiPAFSubscribe(discriminator, reinterpret_cast<void *>(this),
856+
OnWiFiPAFSubscribeComplete, OnWiFiPAFSubscribeError));
860857
}
861858
}
862859
#endif
@@ -1004,7 +1001,7 @@ CHIP_ERROR DeviceCommissioner::Commission(NodeId remoteDeviceId)
10041001
if (device->IsSecureConnected())
10051002
{
10061003
MATTER_LOG_METRIC_BEGIN(kMetricDeviceCommissionerCommission);
1007-
mDefaultCommissioner->StartCommissioning(this, device);
1004+
ReturnErrorOnFailure(mDefaultCommissioner->StartCommissioning(this, device));
10081005
}
10091006
else
10101007
{
@@ -1223,7 +1220,7 @@ void DeviceCommissioner::OnSessionEstablished(const SessionHandle & session)
12231220
CHIP_ERROR err = device->SetConnected(session);
12241221
if (err != CHIP_NO_ERROR)
12251222
{
1226-
ChipLogError(Controller, "Failed in setting up secure channel: %" CHIP_ERROR_FORMAT, err.Format());
1223+
ChipLogFailure(err, Controller, "Failed in setting up secure channel");
12271224
OnSessionEstablishmentError(err);
12281225
return;
12291226
}
@@ -1244,7 +1241,7 @@ void DeviceCommissioner::OnSessionEstablished(const SessionHandle & session)
12441241
{
12451242
mRunCommissioningAfterConnection = false;
12461243
MATTER_LOG_METRIC_BEGIN(kMetricDeviceCommissionerCommission);
1247-
mDefaultCommissioner->StartCommissioning(this, device);
1244+
ReturnAndLogOnFailure(mDefaultCommissioner->StartCommissioning(this, device), Controller, "Failed to start commissioning");
12481245
}
12491246
}
12501247

@@ -1915,7 +1912,7 @@ CHIP_ERROR DeviceCommissioner::SetUdcListenPort(uint16_t listenPort)
19151912
void DeviceCommissioner::FindCommissionableNode(char * instanceName)
19161913
{
19171914
Dnssd::DiscoveryFilter filter(Dnssd::DiscoveryFilterType::kInstanceName, instanceName);
1918-
DiscoverCommissionableNodes(filter);
1915+
TEMPORARY_RETURN_IGNORED DiscoverCommissionableNodes(filter);
19191916
}
19201917

19211918
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY

src/controller/CHIPDeviceControllerFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class DeviceControllerFactory
269269
(void) fabricTable;
270270
if (mGroupDataProvider != nullptr)
271271
{
272-
mGroupDataProvider->RemoveFabric(fabricIndex);
272+
TEMPORARY_RETURN_IGNORED mGroupDataProvider->RemoveFabric(fabricIndex);
273273
}
274274
ClearCASEResumptionStateOnFabricChange(fabricIndex);
275275
};

src/controller/CommissioneeDeviceProxy.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ chip::Optional<SessionHandle> CommissioneeDeviceProxy::DetachSecureSession()
7575
return session;
7676
}
7777

78-
CHIP_ERROR CommissioneeDeviceProxy::UpdateDeviceData(const Transport::PeerAddress & addr,
79-
const ReliableMessageProtocolConfig & config)
78+
void CommissioneeDeviceProxy::UpdateDeviceData(const Transport::PeerAddress & addr, const ReliableMessageProtocolConfig & config)
8079
{
8180
mDeviceAddress = addr;
8281

@@ -90,13 +89,11 @@ CHIP_ERROR CommissioneeDeviceProxy::UpdateDeviceData(const Transport::PeerAddres
9089
// secureSession. For one thing, we could have gotten an different
9190
// UpdateAddress already and that caused connections to be torn down and
9291
// whatnot.
93-
return CHIP_NO_ERROR;
92+
return;
9493
}
9594

9695
Transport::SecureSession * secureSession = mSecureSession.Get().Value()->AsSecureSession();
9796
secureSession->SetPeerAddress(addr);
98-
99-
return CHIP_NO_ERROR;
10097
}
10198

10299
CHIP_ERROR CommissioneeDeviceProxy::SetConnected(const SessionHandle & session)

src/controller/CommissioneeDeviceProxy.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ class CommissioneeDeviceProxy : public DeviceProxy, public SessionDelegate
121121
*
122122
* @param[in] addr Address of the device to be set.
123123
* @param[in] config MRP parameters
124-
*
125-
* @return CHIP_NO_ERROR if the data has been updated, an error code otherwise.
126124
*/
127-
CHIP_ERROR UpdateDeviceData(const Transport::PeerAddress & addr, const ReliableMessageProtocolConfig & config);
125+
void UpdateDeviceData(const Transport::PeerAddress & addr, const ReliableMessageProtocolConfig & config);
128126

129127
/**
130128
* @brief

src/controller/CommissionerDiscoveryController.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ void CommissionerDiscoveryController::OnCommissionerPasscodeReady(UDCClientState
130130
ChipLogError(AppServer, "On UDC: no udc server");
131131
return;
132132
}
133-
mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(state.GetPeerAddress().GetIPAddress(), state.GetCdPort()));
133+
TEMPORARY_RETURN_IGNORED mUdcServer->SendCDCMessage(
134+
cd, Transport::PeerAddress::UDP(state.GetPeerAddress().GetIPAddress(), state.GetCdPort()));
134135
return;
135136
}
136137
else
@@ -383,7 +384,8 @@ void CommissionerDiscoveryController::HandleTargetContentAppCheck(TargetAppInfo
383384
ChipLogDetail(AppServer, "UX Ok - HandleContentAppCheck: target apps specified but none found, sending CDC");
384385
CommissionerDeclaration cd;
385386
cd.SetNoAppsFound(true);
386-
mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
387+
TEMPORARY_RETURN_IGNORED mUdcServer->SendCDCMessage(
388+
cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
387389
}
388390
ChipLogDetail(AppServer, "UX Ok - HandleContentAppCheck: advancing");
389391
// otherwise, advance to the next step for trying to obtain a passcode.
@@ -467,7 +469,7 @@ void CommissionerDiscoveryController::InternalHandleContentAppPasscodeResponse()
467469
CommissionerDeclaration cd;
468470
cd.SetErrorCode(CommissionerDeclaration::CdError::kCommissionerPasscodeDisabled);
469471
cd.SetNeedsPasscode(true);
470-
mUdcServer->SendCDCMessage(
472+
TEMPORARY_RETURN_IGNORED mUdcServer->SendCDCMessage(
471473
cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
472474
return;
473475
}
@@ -482,8 +484,8 @@ void CommissionerDiscoveryController::InternalHandleContentAppPasscodeResponse()
482484
{
483485
cd.SetQRCodeDisplayed(true);
484486
}
485-
mUdcServer->SendCDCMessage(cd,
486-
Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
487+
TEMPORARY_RETURN_IGNORED mUdcServer->SendCDCMessage(
488+
cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
487489

488490
// dialog
489491
ChipLogDetail(Controller,
@@ -511,7 +513,8 @@ void CommissionerDiscoveryController::InternalHandleContentAppPasscodeResponse()
511513
ChipLogDetail(AppServer, "UX Ok: no app passcode and NoPasscode in UDC, sending CDC");
512514
CommissionerDeclaration cd;
513515
cd.SetNeedsPasscode(true);
514-
mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
516+
TEMPORARY_RETURN_IGNORED mUdcServer->SendCDCMessage(
517+
cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
515518
return;
516519
}
517520

@@ -522,7 +525,8 @@ void CommissionerDiscoveryController::InternalHandleContentAppPasscodeResponse()
522525
CommissionerDeclaration cd;
523526
cd.SetNeedsPasscode(true); // TODO: should this be set?
524527
cd.SetPasscodeDialogDisplayed(true);
525-
mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
528+
TEMPORARY_RETURN_IGNORED mUdcServer->SendCDCMessage(
529+
cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
526530
}
527531

528532
ChipLogDetail(Controller, "------PROMPT USER: please enter passcode displayed in casting app ");
@@ -636,7 +640,8 @@ void CommissionerDiscoveryController::Cancel()
636640
ChipLogDetail(AppServer, "UX Cancel: user cancelled entering PIN code, sending CDC");
637641
CommissionerDeclaration cd;
638642
cd.SetCancelPasscode(true);
639-
mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
643+
TEMPORARY_RETURN_IGNORED mUdcServer->SendCDCMessage(
644+
cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
640645
}
641646

642647
mPendingConsent = false;

src/controller/ExampleOperationalCredentialsIssuer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ CHIP_ERROR ExampleOperationalCredentialsIssuer::Initialize(PersistentStorageDele
175175

176176
PERSISTENT_KEY_OP(mIndex, kOperationalCredentialsIssuerKeypairStorage, key,
177177
err = storage.SyncGetKeyValue(key, serializedKey.Bytes(), keySize));
178-
serializedKey.SetLength(keySize);
178+
ReturnErrorOnFailure(serializedKey.SetLength(keySize));
179179
}
180180

181181
if (err != CHIP_NO_ERROR)
@@ -202,7 +202,7 @@ CHIP_ERROR ExampleOperationalCredentialsIssuer::Initialize(PersistentStorageDele
202202

203203
PERSISTENT_KEY_OP(mIndex, kOperationalCredentialsIntermediateIssuerKeypairStorage, key,
204204
err = storage.SyncGetKeyValue(key, serializedKey.Bytes(), keySize));
205-
serializedKey.SetLength(keySize);
205+
ReturnErrorOnFailure(serializedKey.SetLength(keySize));
206206
}
207207

208208
if (err != CHIP_NO_ERROR)
@@ -370,7 +370,7 @@ CHIP_ERROR ExampleOperationalCredentialsIssuer::GenerateNOCChain(const ByteSpan
370370
ReturnErrorOnFailure(reader.Next(kTLVType_ByteString, TLV::ContextTag(1)));
371371

372372
ByteSpan csr(reader.GetReadPoint(), reader.GetLength());
373-
reader.ExitContainer(containerType);
373+
ReturnErrorOnFailure(reader.ExitContainer(containerType));
374374

375375
P256PublicKey pubkey;
376376
ReturnErrorOnFailure(VerifyCertificateSigningRequest(csr.data(), csr.size(), pubkey));

src/controller/ExamplePersistentStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ CHIP_ERROR PersistentStorage::Init(const char * name, const char * directory)
8383
ifs.open(mStorageFilePath, std::ifstream::in);
8484
if (!ifs.good())
8585
{
86-
CommitConfig();
86+
SuccessOrExit(err = CommitConfig());
8787
ifs.open(mStorageFilePath, std::ifstream::in);
8888
}
8989
VerifyOrExit(ifs.is_open(), err = CHIP_ERROR_OPEN_FAILED);

src/controller/SetUpCodePairer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ CHIP_ERROR SetUpCodePairer::StopDiscoveryOverDNSSD()
264264

265265
mWaitingForDiscovery[kIPTransport] = false;
266266

267-
mCommissioner->StopCommissionableDiscovery();
268-
return CHIP_NO_ERROR;
267+
return mCommissioner->StopCommissionableDiscovery();
269268
}
270269

271270
CHIP_ERROR SetUpCodePairer::StartDiscoveryOverWiFiPAF()
@@ -310,9 +309,10 @@ CHIP_ERROR SetUpCodePairer::StopDiscoveryOverWiFiPAF()
310309
{
311310
mWaitingForDiscovery[kWiFiPAFTransport] = false;
312311
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
313-
DeviceLayer::ConnectivityMgr().WiFiPAFCancelIncompleteSubscribe();
314-
#endif
312+
return DeviceLayer::ConnectivityMgr().WiFiPAFCancelIncompleteSubscribe();
313+
#else
315314
return CHIP_NO_ERROR;
315+
#endif
316316
}
317317

318318
CHIP_ERROR SetUpCodePairer::StartDiscoveryOverNFC()
@@ -653,7 +653,7 @@ void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::CommonRe
653653
{
654654
// If the discovery type does not want the PASE auto retry mechanism, we will just store
655655
// a single IP. So the discovery process is stopped as it won't be of any help anymore.
656-
StopDiscoveryOverDNSSD();
656+
TEMPORARY_RETURN_IGNORED StopDiscoveryOverDNSSD();
657657
mDiscoveredParameters.emplace_back(resolutionData, matchedLongDiscriminator, 0);
658658
}
659659
else

src/controller/TypedReadCallback.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class TypedReadEventCallback final : public app::ReadClient::Callback
219219
VerifyOrExit(apData != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);
220220

221221
VerifyOrExit((aEventHeader.mPath.mEventId == value.GetEventId()) && (aEventHeader.mPath.mClusterId == value.GetClusterId()),
222-
CHIP_ERROR_SCHEMA_MISMATCH);
222+
err = CHIP_ERROR_SCHEMA_MISMATCH);
223223
err = app::DataModel::Decode(*apData, value);
224224
SuccessOrExit(err);
225225

0 commit comments

Comments
 (0)