[coreboot-gerrit] New patch to review for coreboot: tpm2: clean up tpm_marshal_command()

Martin Roth (martinroth@google.com) gerrit at coreboot.org
Tue Jul 12 00:46:09 CEST 2016


Martin Roth (martinroth at google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/15611

-gerrit

commit c9f6a9376ef84c2b890f51c642f33432615909b3
Author: Vadim Bendebury <vbendeb at chromium.org>
Date:   Thu Jul 7 14:27:41 2016 -0700

    tpm2: clean up tpm_marshal_command()
    
    The function is reusing some variables which confuses the reader as
    the variable names do not match their second function.
    
    This patch edits the code for readability without changing
    functionality.
    
    BRANCH=None
    BUG=chrome-os-partner:50465
    TEST=with the rest of the patches applied Kevin still boots into
         chrome OS.
    
    Change-Id: I396206a64403229ba3921a47b5a08748d8a4b0a3
    Signed-off-by: Martin Roth <martinroth at chromium.org>
    Original-Commit-Id: 3cf02c365d098c9d2ca57def7cf349ef2291d140
    Original-Change-Id: I95a07945d9d2b00a69d514014f848802b82dd90f
    Original-Signed-off-by: Vadim Bendebury <vbendeb at chromium.org>
    Original-Reviewed-on: https://chromium-review.googlesource.com/358915
    Original-Reviewed-by: Aaron Durbin <adurbin at chromium.org>
---
 src/lib/tpm2_marshaling.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/lib/tpm2_marshaling.c b/src/lib/tpm2_marshaling.c
index 0a90df0..63f0e4c 100644
--- a/src/lib/tpm2_marshaling.c
+++ b/src/lib/tpm2_marshaling.c
@@ -357,18 +357,22 @@ int tpm_marshal_command(TPM_CC command, void *tpm_command_body,
 	}
 
 	if (body_size > 0) {
+		size_t marshaled_size;
+		size_t header_room = sizeof(struct tpm_header);
 
 		/* See how much room was taken by marshaling. */
-		body_size = max_body_size - body_size;
+		marshaled_size = max_body_size - body_size;
 
-		body_size += sizeof(struct tpm_header);
+		/* Total size includes the header size. */
+		marshaled_size += sizeof(struct tpm_header);
 
-		marshal_u16(&buffer, tpm_tag, &max_body_size);
-		marshal_u32(&buffer, body_size, &max_body_size);
-		marshal_u32(&buffer, command, &max_body_size);
+		marshal_u16(&buffer, tpm_tag, &header_room);
+		marshal_u32(&buffer, marshaled_size, &header_room);
+		marshal_u32(&buffer, command, &header_room);
+		return marshaled_size;
 	}
 
-	return body_size;
+	return -1;
 }
 
 static void unmarshal_get_capability(void **buffer, int *size,



More information about the coreboot-gerrit mailing list