From a62b61165990703f0607465c311c88e41e713e15 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Thu, 4 Aug 2022 10:36:52 +0000 Subject: [PATCH] arch: improve some structures in smbios code There is no need to manually implement Clone for some structures. It is better to explicitly spell out repr(C) to avoid the compiler reordering the fields. Signed-off-by: Wei Liu --- arch/src/x86_64/smbios.rs | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/arch/src/x86_64/smbios.rs b/arch/src/x86_64/smbios.rs index 15de2c7c9..0924e4522 100644 --- a/arch/src/x86_64/smbios.rs +++ b/arch/src/x86_64/smbios.rs @@ -75,8 +75,9 @@ fn compute_checksum(v: &T) -> u8 { (!checksum).wrapping_add(1) } +#[repr(C)] #[repr(packed)] -#[derive(Default, Copy)] +#[derive(Default, Copy, Clone)] pub struct Smbios30Entrypoint { pub signature: [u8; 5usize], pub checksum: u8, @@ -90,14 +91,9 @@ pub struct Smbios30Entrypoint { pub physptr: u64, } -impl Clone for Smbios30Entrypoint { - fn clone(&self) -> Self { - *self - } -} - +#[repr(C)] #[repr(packed)] -#[derive(Default, Copy)] +#[derive(Default, Copy, Clone)] pub struct SmbiosBiosInfo { pub typ: u8, pub length: u8, @@ -112,14 +108,9 @@ pub struct SmbiosBiosInfo { pub characteristics_ext2: u8, } -impl Clone for SmbiosBiosInfo { - fn clone(&self) -> Self { - *self - } -} - +#[repr(C)] #[repr(packed)] -#[derive(Default, Copy)] +#[derive(Default, Copy, Clone)] pub struct SmbiosSysInfo { pub typ: u8, pub length: u8, @@ -134,12 +125,6 @@ pub struct SmbiosSysInfo { pub family: u8, } -impl Clone for SmbiosSysInfo { - fn clone(&self) -> Self { - *self - } -} - // SAFETY: These data structures only contain a series of integers unsafe impl ByteValued for Smbios30Entrypoint {} unsafe impl ByteValued for SmbiosBiosInfo {}