Skip to content

Commit 4601c2f

Browse files
fix(nvme): zero the queue
Signed-off-by: Anhad Singh <[email protected]>
1 parent 8bd3110 commit 4601c2f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/aero_kernel/src/drivers/block/nvme/queue.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::cell::UnsafeCell;
2+
use core::ptr;
23
use core::sync::atomic::{AtomicU16, Ordering};
34

45
use crate::mem::paging::PhysAddr;
@@ -56,7 +57,7 @@ impl<'bell, T: QueueType> Queue<'bell, T> {
5657

5758
Ok(Self {
5859
doorbell,
59-
queue: unsafe { Dma::new_uninit_slice(size).assume_init() },
60+
queue: unsafe { Dma::new_zeroed_slice(size).assume_init() },
6061
index: 0,
6162
phase: true,
6263
})
@@ -139,7 +140,7 @@ impl<'a> QueuePair<'a> {
139140
unsafe {
140141
// SAFETY: The offset of the `command_id` field is the same, regardless of the command
141142
// type.
142-
command.common.command_id = self.cid;
143+
*ptr::addr_of_mut!(command).cast::<u16>().add(1) = self.cid;
143144
}
144145

145146
self.cid += 1;

src/aero_kernel/src/utils/dma.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ unsafe impl Allocator for DmaAllocator {
3232
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
3333
let size_bytes = layout.size();
3434

35-
let phys = FRAME_ALLOCATOR.alloc_zeroed(size_bytes).ok_or(AllocError)?;
35+
let phys = FRAME_ALLOCATOR.alloc(size_bytes).ok_or(AllocError)?;
3636
let virt = phys.as_hhdm_virt();
3737

3838
// SAFETY: The frame is aligned and non-null.
@@ -78,6 +78,10 @@ impl<T> Dma<T> {
7878
pub fn new_uninit_slice(len: usize) -> Dma<[MaybeUninit<T>]> {
7979
Dma(DmaBuffer::new_uninit_slice_in(len, DmaAllocator))
8080
}
81+
82+
pub fn new_zeroed_slice(len: usize) -> Dma<[MaybeUninit<T>]> {
83+
Dma(DmaBuffer::new_zeroed_slice_in(len, DmaAllocator))
84+
}
8185
}
8286

8387
impl<T> Dma<[MaybeUninit<T>]> {

0 commit comments

Comments
 (0)