Formatting .c/.h files and fix memory leakage issues
Signed-off-by: John Chung <john.chung@arm.com>
Change-Id: Id8328f412c2724992d80c0b3f895c8f85bc4ae68
diff --git a/generator/sections/gen-section-cxl-protocol.c b/generator/sections/gen-section-cxl-protocol.c
index 71a1105..cd9d66d 100644
--- a/generator/sections/gen-section-cxl-protocol.c
+++ b/generator/sections/gen-section-cxl-protocol.c
@@ -11,54 +11,56 @@
//Generates a single pseudo-random CXL protocol error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_cxl_protocol(void** location)
+size_t generate_section_cxl_protocol(void **location)
{
- //Create a random length for the CXL DVSEC and CXL error log.
- //The logs attached here do not necessarily conform to the specification, and are simply random.
- int dvsec_len = rand() % 64;
- int error_log_len = rand() % 64;
+ //Create a random length for the CXL DVSEC and CXL error log.
+ //The logs attached here do not necessarily conform to the specification, and are simply random.
+ int dvsec_len = rand() % 64;
+ int error_log_len = rand() % 64;
- //Create random bytes.
- int size = 116 + dvsec_len + error_log_len;
- UINT8* bytes = generate_random_bytes(size);
+ //Create random bytes.
+ int size = 116 + dvsec_len + error_log_len;
+ UINT8 *bytes = generate_random_bytes(size);
- //Set CXL agent type.
- int cxl_agent_type = rand() % 2;
- *(bytes + 8) = cxl_agent_type;
-
- //Set reserved areas to zero.
- UINT64* validation = (UINT64*)bytes;
- *validation &= 0b111111; //Validation bits 6-63.
- for (int i=0; i<7; i++)
- *(bytes + 9 + i) = 0; //Reserved bytes 9-15.
+ //Set CXL agent type.
+ int cxl_agent_type = rand() % 2;
+ *(bytes + 8) = cxl_agent_type;
- //We only reserve bytes if it's a CXL 1.1 device, and not a host downstream port.
- if (cxl_agent_type == 0)
- {
- for (int i=0; i<3; i++)
- *(bytes + 21 + i) = 0; //CXL agent address bytes 5-7.
- }
-
- *(bytes + 34) &= ~0b111; //Device ID byte 10 bits 0-2.
- UINT32* reserved = (UINT32*)(bytes + 36);
- *reserved = 0; //Device ID bytes 12-15.
- reserved = (UINT32*)(bytes + 112);
- *reserved = 0; //Reserved bytes 112-115.
+ //Set reserved areas to zero.
+ UINT64 *validation = (UINT64 *)bytes;
+ *validation &= 0x3F; //Validation bits 6-63.
+ for (int i = 0; i < 7; i++) {
+ *(bytes + 9 + i) = 0; //Reserved bytes 9-15.
+ }
- //If the device is a host downstream port, serial/capability structure is invalid.
- if (cxl_agent_type != 0)
- {
- for (int i=0; i<68; i++)
- *(bytes + 40 + i) = 0; //Device serial & capability structure.
- }
+ //We only reserve bytes if it's a CXL 1.1 device, and not a host downstream port.
+ if (cxl_agent_type == 0) {
+ for (int i = 0; i < 3; i++) {
+ *(bytes + 21 + i) = 0; //CXL agent address bytes 5-7.
+ }
+ }
- //Set expected values.
- UINT16* dvsec_length_field = (UINT16*)(bytes + 108);
- UINT16* error_log_len_field = (UINT16*)(bytes + 110);
- *dvsec_length_field = dvsec_len;
- *error_log_len_field = error_log_len;
+ *(bytes + 34) &= ~0x7; //Device ID byte 10 bits 0-2.
+ UINT32 *reserved = (UINT32 *)(bytes + 36);
+ *reserved = 0; //Device ID bytes 12-15.
+ reserved = (UINT32 *)(bytes + 112);
+ *reserved = 0; //Reserved bytes 112-115.
- //Set return values, exit.
- *location = bytes;
- return size;
-}
\ No newline at end of file
+ //If the device is a host downstream port, serial/capability structure is invalid.
+ if (cxl_agent_type != 0) {
+ for (int i = 0; i < 68; i++) {
+ *(bytes + 40 + i) =
+ 0; //Device serial & capability structure.
+ }
+ }
+
+ //Set expected values.
+ UINT16 *dvsec_length_field = (UINT16 *)(bytes + 108);
+ UINT16 *error_log_len_field = (UINT16 *)(bytes + 110);
+ *dvsec_length_field = dvsec_len;
+ *error_log_len_field = error_log_len;
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
+}