virPCIVPDParseVPDLargeResourceFields: Merge logic conditions

Merge the pre-checks with the 'switch' statement which is operating on
the same values to simplify further refactoring.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2024-01-30 15:02:39 +01:00
parent aa5e3cc449
commit 037803a949

View File

@ -438,23 +438,27 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uint16_t resPos, uint16_t re
fieldKeyword = g_strndup((char *)buf, 2); fieldKeyword = g_strndup((char *)buf, 2);
fieldFormat = virPCIVPDResourceGetFieldValueFormat(fieldKeyword); fieldFormat = virPCIVPDResourceGetFieldValueFormat(fieldKeyword);
/* Handle special cases first */
if (!readOnly && fieldFormat == VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RESVD) {
VIR_INFO("Unexpected RV keyword in the read-write section.");
return false;
} else if (readOnly && fieldFormat == VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RDWR) {
VIR_INFO("Unexpected RW keyword in the read-only section.");
return false;
}
/* Determine how many bytes to read per field value type. */ /* Determine how many bytes to read per field value type. */
switch (fieldFormat) { switch (fieldFormat) {
case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_TEXT: case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_TEXT:
case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RDWR:
case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_BINARY: case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_BINARY:
bytesToRead = fieldDataLen; bytesToRead = fieldDataLen;
break; break;
case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RDWR:
if (readOnly) {
VIR_INFO("Unexpected RW keyword in the read-only section.");
return false;
}
bytesToRead = fieldDataLen;
break;
case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RESVD: case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RESVD:
if (!readOnly) {
VIR_INFO("Unexpected RV keyword in the read-write section.");
return false;
}
/* Only need one byte to be read and accounted towards /* Only need one byte to be read and accounted towards
* the checksum calculation. */ * the checksum calculation. */
bytesToRead = 1; bytesToRead = 1;