Allow decoding nvidia CPERs

There are cases where satmc might not be able to buffer the full CPER
message.  In those cases, it is advantageous if the decoder continues as
far as it can.

This commit moves a range check in nvidia cpers such that if there is a
buffer error, the CPER registers are still iterated until we hit the
buffer error, then filled in with null after the buffer error.  This
makes it more clear what the issue is, and decodes more of the output.

Change-Id: Idf202860d4994e719c1b73b811e767ad94ee0cae
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/sections/cper-section-nvidia.c b/sections/cper-section-nvidia.c
index ae14330..7cb2e87 100644
--- a/sections/cper-section-nvidia.c
+++ b/sections/cper-section-nvidia.c
@@ -20,11 +20,6 @@
 	}
 
 	EFI_NVIDIA_ERROR_DATA *nvidia_error = (EFI_NVIDIA_ERROR_DATA *)section;
-	if (size < sizeof(EFI_NVIDIA_ERROR_DATA) +
-			   nvidia_error->NumberRegs *
-				   sizeof(EFI_NVIDIA_REGISTER_DATA)) {
-		return NULL;
-	}
 
 	json_object *section_ir = json_object_new_object();
 
@@ -56,11 +51,21 @@
 	json_object *regarr = json_object_new_array();
 	EFI_NVIDIA_REGISTER_DATA *regPtr = nvidia_error->Register;
 	for (int i = 0; i < nvidia_error->NumberRegs; i++, regPtr++) {
-		json_object *reg = json_object_new_object();
-		json_object_object_add(reg, "address",
-				       json_object_new_uint64(regPtr->Address));
-		json_object_object_add(reg, "value",
-				       json_object_new_uint64(regPtr->Value));
+		json_object *reg = NULL;
+		if (sizeof(EFI_NVIDIA_ERROR_DATA) +
+			    i * sizeof(EFI_NVIDIA_REGISTER_DATA) <
+		    size) {
+			reg = json_object_new_object();
+			json_object_object_add(
+				reg, "address",
+				json_object_new_uint64(regPtr->Address));
+			json_object_object_add(
+				reg, "value",
+				json_object_new_uint64(regPtr->Value));
+		} else {
+			reg = json_object_new_null();
+		}
+
 		json_object_array_add(regarr, reg);
 	}
 	json_object_object_add(section_ir, "registers", regarr);