arch: x86_64: tdx: drop one unsafe call in code

Implement Default trait for TdvfDescriptor and drop one unsafe in code.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2021-11-10 14:52:41 +00:00 committed by Sebastien Boeuf
parent 38351f0d96
commit a4d8616676

View File

@ -25,6 +25,7 @@ pub enum TdvfError {
// TDVF_DESCRIPTOR
#[repr(packed)]
#[derive(Default)]
pub struct TdvfDescriptor {
signature: [u8; 4],
length: u32,
@ -128,7 +129,7 @@ pub fn parse_tdvf_sections(file: &mut File) -> Result<Vec<TdvfSection>, TdvfErro
file.seek(SeekFrom::Start(descriptor_offset))
.map_err(TdvfError::ReadDescriptor)?;
let mut descriptor: TdvfDescriptor = unsafe { std::mem::zeroed() };
let mut descriptor: TdvfDescriptor = Default::default();
// Safe as we read exactly the size of the descriptor header
file.read_exact(unsafe {
std::slice::from_raw_parts_mut(