summaryrefslogtreecommitdiff
path: root/src/lib/tpm2_tlcl.c
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2017-03-25 00:38:45 -0500
committerMartin Roth <martinroth@google.com>2017-04-24 19:07:07 +0200
commitee049fa8027745d8bd90e7abe8aa8a9646d390a8 (patch)
tree1faf2c3e2362b409e6196bbf3d90ad30f6008917 /src/lib/tpm2_tlcl.c
parent88b26b845cab11be3f925e2fb52b805f7f8f992a (diff)
drivers/i2c/tpm: use iobuf library for marshaling commands
Use the iobuf API instead of relying on own buffer management. It also provides consistency between marshaling and unmarshaling code paths for propagating return values instead of overloading the values of existing variables. BUG=b:36598499 Change-Id: Iec0bbff1312e8e6ec616d1528db8667f32e682c9 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/19063 Tested-by: build bot (Jenkins) Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'src/lib/tpm2_tlcl.c')
-rw-r--r--src/lib/tpm2_tlcl.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/lib/tpm2_tlcl.c b/src/lib/tpm2_tlcl.c
index 1118afb1df..754f835719 100644
--- a/src/lib/tpm2_tlcl.c
+++ b/src/lib/tpm2_tlcl.c
@@ -23,29 +23,34 @@
static void *tpm_process_command(TPM_CC command, void *command_body)
{
- ssize_t out_size;
+ struct obuf ob;
+ struct ibuf ib;
+ size_t out_size;
size_t in_size;
+ const uint8_t *sendb;
/* Command/response buffer. */
static uint8_t cr_buffer[TPM_BUFFER_SIZE] CAR_GLOBAL;
uint8_t *cr_buffer_ptr = car_get_var_ptr(cr_buffer);
- out_size = tpm_marshal_command(command, command_body,
- cr_buffer_ptr, sizeof(cr_buffer));
- if (out_size < 0) {
- printk(BIOS_ERR, "command %#x, cr size %zd\n",
- command, out_size);
+ obuf_init(&ob, cr_buffer_ptr, sizeof(cr_buffer));
+
+ if (tpm_marshal_command(command, command_body, &ob) < 0) {
+ printk(BIOS_ERR, "command %#x\n", command);
return NULL;
}
+ sendb = obuf_contents(&ob, &out_size);
+
in_size = sizeof(cr_buffer);
- if (tis_sendrecv(cr_buffer_ptr, out_size,
- cr_buffer_ptr, &in_size)) {
+ if (tis_sendrecv(sendb, out_size, cr_buffer_ptr, &in_size)) {
printk(BIOS_ERR, "tpm transaction failed\n");
return NULL;
}
- return tpm_unmarshal_response(command, cr_buffer_ptr, in_size);
+ ibuf_init(&ib, cr_buffer_ptr, in_size);
+
+ return tpm_unmarshal_response(command, &ib);
}