From 73af65f417467fb34359bf73da11a1bff774de04 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Wed, 25 Jan 2023 22:42:44 +0000 Subject: [PATCH] tpm: drop unused fields in BackendCmd struct They are never used. Signed-off-by: Wei Liu --- devices/src/tpm.rs | 2 -- tpm/src/emulator.rs | 22 ++++++---------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/devices/src/tpm.rs b/devices/src/tpm.rs index 68090325d..8d2265328 100644 --- a/devices/src/tpm.rs +++ b/devices/src/tpm.rs @@ -472,10 +472,8 @@ impl BusDevice for Tpm { self.regs[CRB_CTRL_START as usize] |= CRB_START_INVOKE; let mut cmd = BackendCmd { - locality: locality as u8, buffer: &mut self.data_buff, input_len: cmp::min(self.data_buff_len, TPM_CRB_BUFFER_MAX), - selftest_done: false, }; let _ = self.emulator.deliver_request(&mut cmd); diff --git a/tpm/src/emulator.rs b/tpm/src/emulator.rs index 1af129445..29ffc0985 100644 --- a/tpm/src/emulator.rs +++ b/tpm/src/emulator.rs @@ -62,12 +62,10 @@ pub enum Error { type Result = anyhow::Result; pub struct BackendCmd<'a> { - pub locality: u8, // This buffer is used for both input and output. // When used for input, the length of the data is input_len. pub buffer: &'a mut [u8], pub input_len: usize, - pub selftest_done: bool, } pub struct Emulator { @@ -285,13 +283,10 @@ impl Emulator { /// Function to write to data socket and read the response from it pub fn deliver_request(&mut self, cmd: &mut BackendCmd) -> Result<()> { - let isselftest: bool; // SAFETY: type "sockaddr_storage" is valid with an all-zero byte-pattern value let mut addr: sockaddr_storage = unsafe { mem::zeroed() }; let mut len = mem::size_of::() as socklen_t; - - cmd.selftest_done = false; - isselftest = is_selftest(&cmd.buffer[0..cmd.input_len]); + let isselftest = is_selftest(&cmd.buffer[0..cmd.input_len]); debug!( "Send cmd: {:02X?} of len {:?} on data_ioc ", @@ -347,16 +342,11 @@ impl Emulator { cmd.buffer, output_len, isselftest ); - if isselftest { - if output_len < 10 { - return Err(Error::SelfTest(anyhow!( - "Self test response should have 10 bytes. Only {:?} returned", - output_len - ))); - } - let mut errcode: [u8; 4] = [0; 4]; - errcode.copy_from_slice(&cmd.buffer[6..6 + 4]); - cmd.selftest_done = u32::from_ne_bytes(errcode).to_be() == 0; + if isselftest && output_len < 10 { + return Err(Error::SelfTest(anyhow!( + "Self test response should have 10 bytes. Only {:?} returned", + output_len + ))); } Ok(())