Skip to content

Commit a629992

Browse files
committed
Re-format the read only checks a bit
1 parent 1f79a52 commit a629992

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/app/codegen-data-model/CodegenDataModel_Write.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -290,30 +290,32 @@ CHIP_ERROR CodegenDataModel::WriteAttribute(const InteractionModel::WriteAttribu
290290
}
291291

292292
const EmberAfAttributeMetadata ** attributeMetadata = std::get_if<const EmberAfAttributeMetadata *>(&metadata);
293-
if (attributeMetadata == nullptr)
294-
{
295-
// All the global attributes that we do not have metadata for are
296-
// read-only. Specifically only the following list-based attributes match the
297-
// "global attributes not in metadata" (see GlobalAttributes.h :: GlobalAttributesNotInMetadat):
298-
// - AttributeList
299-
// - EventList
300-
// - AcceptedCommands
301-
// - GeneratedCommands
302-
//
303-
// Given the above, UnsupportedWrite should be correct (attempt to write to a read-only list)
304-
return CHIP_IM_GLOBAL_STATUS(UnsupportedWrite);
305-
}
293+
294+
// All the global attributes that we do not have metadata for are
295+
// read-only. Specifically only the following list-based attributes match the
296+
// "global attributes not in metadata" (see GlobalAttributes.h :: GlobalAttributesNotInMetadat):
297+
// - AttributeList
298+
// - EventList
299+
// - AcceptedCommands
300+
// - GeneratedCommands
301+
//
302+
// Given the above, UnsupportedWrite should be correct (attempt to write to a read-only list)
303+
bool isReadOnly = (attributeMetadata == nullptr) || (*attributeMetadata)->IsReadOnly();
306304

307305
// Internal is allowed to bypass timed writes and read-only.
308306
if (!request.operationFlags.Has(InteractionModel::OperationFlags::kInternal))
309307
{
310-
VerifyOrReturnError(!(*attributeMetadata)->IsReadOnly(), CHIP_IM_GLOBAL_STATUS(UnsupportedWrite));
308+
VerifyOrReturnError(!isReadOnly, CHIP_IM_GLOBAL_STATUS(UnsupportedWrite));
311309

312310
VerifyOrReturnError(!(*attributeMetadata)->MustUseTimedWrite() ||
313311
request.writeFlags.Has(InteractionModel::WriteFlags::kTimed),
314312
CHIP_IM_GLOBAL_STATUS(NeedsTimedInteraction));
315313
}
316314

315+
// Extra check: internal requests can bypass the read only check, however global attributes
316+
// have no underlying storage, so write still cannot be done
317+
VerifyOrReturnError(attributeMetadata != nullptr, CHIP_IM_GLOBAL_STATUS(UnsupportedWrite));
318+
317319
if (request.path.mDataVersion.HasValue())
318320
{
319321
std::optional<InteractionModel::ClusterInfo> clusterInfo = GetClusterInfo(request.path);

0 commit comments

Comments
 (0)