tpm: save almost 8KB stack space

The largest possible PTM response is only 16 bytes. Size the output
buffer correctly.

In the socket read function, rely on the caller to provide a
sufficiently large buffer. That eliminates another large stack variable.

In total this saves almost 8KB stack space.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu
2023-01-30 22:01:42 +00:00
committed by Rob Bradford
parent 8e996ff2fe
commit 6e22f23831
2 changed files with 11 additions and 11 deletions

View File

@@ -216,7 +216,16 @@ impl Emulator {
))
})?;
let mut output = [0_u8; TPM_CRB_BUFFER_MAX];
// The largest response is 16 bytes so far.
if msg_len_out > 16 {
return Err(Error::RunControlCmd(anyhow!(
"Response size is too large for Cmd {:02X?}, max 16 wanted {}",
cmd,
msg_len_out
)));
}
let mut output = [0u8; 16];
// Every Control Cmd gets atleast a result code in response. Read it
let read_size = self.control_socket.read(&mut output).map_err(|e| {