From 94fcfa9f1f43e635c6a610e30c1b2932a2fb562f Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Wed, 17 Nov 2021 13:43:00 +0000 Subject: [PATCH] virtio-queue: add safety comments for `impl ByteValued` Signed-off-by: Wei Liu --- virtio-queue/src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/virtio-queue/src/lib.rs b/virtio-queue/src/lib.rs index d321f6f3e..353901439 100644 --- a/virtio-queue/src/lib.rs +++ b/virtio-queue/src/lib.rs @@ -94,6 +94,9 @@ pub struct Descriptor { next: u16, } +// SAFETY: Descriptor only contains a series of integers and has no implicit padding +unsafe impl ByteValued for Descriptor {} + #[allow(clippy::len_without_is_empty)] impl Descriptor { /// Creates a new descriptor @@ -149,8 +152,6 @@ impl Descriptor { } } -unsafe impl ByteValued for Descriptor {} - /// A virtio descriptor chain. #[derive(Clone, Debug)] pub struct DescriptorChain { @@ -421,6 +422,9 @@ pub struct VirtqUsedElem { len: u32, } +// SAFETY: VirtqUsedElem only contains a series of integers and has no implicit padding +unsafe impl ByteValued for VirtqUsedElem {} + impl VirtqUsedElem { /// Create a new `VirtqUsedElem` instance. pub fn new(id: u16, len: u32) -> Self { @@ -431,8 +435,6 @@ impl VirtqUsedElem { } } -unsafe impl ByteValued for VirtqUsedElem {} - /// Struct to hold an exclusive reference to the underlying `QueueState` object. pub enum QueueStateGuard<'a, M: GuestAddressSpace> { /// A reference to a `QueueState` object.