mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
tpm: refactor startup response check
Extract the TPM2_Startup(CLEAR) response-code check so the accepted swtpm reset results can be covered directly. Assisted-by: Copilot:GPT-5.5 Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
@@ -27,6 +27,10 @@ const TPM2_STARTUP_CLEAR: [u8; 12] = [
|
||||
0x00, 0x00, // TPM_SU_CLEAR
|
||||
];
|
||||
|
||||
fn startup_response_is_ok(response_code: u32) -> bool {
|
||||
response_code == TPM_SUCCESS || response_code == TPM_RC_INITIALIZE
|
||||
}
|
||||
|
||||
/* capability flags returned by PTM_GET_CAPABILITY */
|
||||
const PTM_CAP_INIT: u64 = 1;
|
||||
const PTM_CAP_SHUTDOWN: u64 = 1 << 1;
|
||||
@@ -520,7 +524,7 @@ impl Emulator {
|
||||
self.deliver_request(&mut cmd)?;
|
||||
|
||||
let response_code = u32::from_be_bytes(buffer[6..10].try_into().unwrap());
|
||||
if response_code != TPM_SUCCESS && response_code != TPM_RC_INITIALIZE {
|
||||
if !startup_response_is_ok(response_code) {
|
||||
return Err(Error::DeliverRequest(anyhow!(
|
||||
"TPM2_Startup(CLEAR) returned error code: {response_code:#X}"
|
||||
)));
|
||||
|
||||
Reference in New Issue
Block a user