From 2b76e1d7ba252c1477f9a84dcff57c83bbf64cda Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Wed, 25 Jan 2023 17:36:33 +0000 Subject: [PATCH] devices: simplify TPM handling The error is never propagated anywhere. Drop it. Avoid unwrapping unconditionally. Signed-off-by: Wei Liu --- devices/src/tpm.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/devices/src/tpm.rs b/devices/src/tpm.rs index d522a7619..fef10eed4 100644 --- a/devices/src/tpm.rs +++ b/devices/src/tpm.rs @@ -22,8 +22,6 @@ pub enum Error { CheckCaps(#[source] anyhow::Error), #[error("Failed to initialize tpm: {0}")] Init(#[source] anyhow::Error), - #[error("Failed to deliver tpm Command: {0}")] - DeliverRequest(#[source] anyhow::Error), } type Result = anyhow::Result; @@ -483,15 +481,12 @@ impl BusDevice for Tpm { }; let mut cmd = cmd.clone(); - let output = self.emulator.deliver_request(&mut cmd).map_err(|e| { - Error::DeliverRequest(anyhow!( - "Failed to deliver tpm request. Error :{:?}", - e - )) - }); - // TODO: drop the copy here - self.data_buff.fill(0); - self.data_buff.clone_from_slice(output.unwrap().as_slice()); + + if let Ok(output) = self.emulator.deliver_request(&mut cmd) { + // TODO: drop the copy here + self.data_buff.fill(0); + self.data_buff.clone_from_slice(output.as_slice()); + } self.request_completed(TPM_SUCCESS as isize); }