@@ -114,8 +114,8 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
114114 // Link descriptors together.
115115 for i in 0 ..( size - 1 ) {
116116 desc_shadow[ i as usize ] . next = i + 1 ;
117- // Safe because `desc` is properly aligned, dereferenceable, initialised, and the device
118- // won't access the descriptors for the duration of this unsafe block.
117+ // SAFETY: `desc` is properly aligned, dereferenceable, initialised,
118+ // and the device won't access the descriptors for the duration of this unsafe block.
119119 unsafe {
120120 ( * desc. as_ptr ( ) ) [ i as usize ] . next = i + 1 ;
121121 }
@@ -185,7 +185,7 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
185185 let head = self . add_direct ( inputs, outputs) ;
186186
187187 let avail_slot = self . avail_idx & ( SIZE as u16 - 1 ) ;
188- // Safe because self.avail is properly aligned, dereferenceable and initialised.
188+ // SAFETY: ` self.avail` is properly aligned, dereferenceable and initialised.
189189 unsafe {
190190 ( * self . avail . as_ptr ( ) ) . ring [ avail_slot as usize ] = head;
191191 }
@@ -196,7 +196,7 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
196196
197197 // increase head of avail ring
198198 self . avail_idx = self . avail_idx . wrapping_add ( 1 ) ;
199- // Safe because self.avail is properly aligned, dereferenceable and initialised.
199+ // SAFETY: ` self.avail` is properly aligned, dereferenceable and initialised.
200200 unsafe {
201201 ( * self . avail . as_ptr ( ) )
202202 . idx
@@ -220,7 +220,7 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
220220
221221 // Write to desc_shadow then copy.
222222 let desc = & mut self . desc_shadow [ usize:: from ( self . free_head ) ] ;
223- // Safe because our caller promises that the buffers live at least until `pop_used`
223+ // SAFETY: Our caller promises that the buffers live at least until `pop_used`
224224 // returns them.
225225 unsafe {
226226 desc. set_buf :: < H > ( buffer, direction, DescFlags :: NEXT ) ;
@@ -255,7 +255,7 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
255255 <[ Descriptor ] >:: new_box_zeroed_with_elems ( inputs. len ( ) + outputs. len ( ) ) . unwrap ( ) ;
256256 for ( i, ( buffer, direction) ) in InputOutputIter :: new ( inputs, outputs) . enumerate ( ) {
257257 let desc = & mut indirect_list[ i] ;
258- // Safe because our caller promises that the buffers live at least until `pop_used`
258+ // SAFETY: Our caller promises that the buffers live at least until `pop_used`
259259 // returns them.
260260 unsafe {
261261 desc. set_buf :: < H > ( buffer, direction, DescFlags :: NEXT ) ;
@@ -303,7 +303,7 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
303303 outputs : & ' a mut [ & ' a mut [ u8 ] ] ,
304304 transport : & mut impl Transport ,
305305 ) -> Result < u32 > {
306- // Safe because we don't return until the same token has been popped, so the buffers remain
306+ // SAFETY: We don't return until the same token has been popped, so the buffers remain
307307 // valid and are not otherwise accessed until then.
308308 let token = unsafe { self . add ( inputs, outputs) } ?;
309309
@@ -317,8 +317,7 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
317317 spin_loop ( ) ;
318318 }
319319
320- // Safe because these are the same buffers as we passed to `add` above and they are still
321- // valid.
320+ // SAFETY: These are the same buffers as we passed to `add` above and they are still valid.
322321 unsafe { self . pop_used ( token, inputs, outputs) }
323322 }
324323
@@ -328,8 +327,8 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
328327 pub fn set_dev_notify ( & mut self , enable : bool ) {
329328 let avail_ring_flags = if enable { 0x0000 } else { 0x0001 } ;
330329 if !self . event_idx {
331- // Safe because self.avail points to a valid, aligned, initialised, dereferenceable, readable
332- // instance of AvailRing.
330+ // SAFETY: ` self.avail` points to a valid, aligned, initialised, dereferenceable, readable
331+ // instance of ` AvailRing` .
333332 unsafe {
334333 ( * self . avail . as_ptr ( ) )
335334 . flags
@@ -344,13 +343,13 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
344343 /// This will be false if the device has supressed notifications.
345344 pub fn should_notify ( & self ) -> bool {
346345 if self . event_idx {
347- // Safe because self.used points to a valid, aligned, initialised, dereferenceable, readable
348- // instance of UsedRing.
346+ // SAFETY: ` self.used` points to a valid, aligned, initialised, dereferenceable, readable
347+ // instance of ` UsedRing` .
349348 let avail_event = unsafe { ( * self . used . as_ptr ( ) ) . avail_event . load ( Ordering :: Acquire ) } ;
350349 self . avail_idx >= avail_event. wrapping_add ( 1 )
351350 } else {
352- // Safe because self.used points to a valid, aligned, initialised, dereferenceable, readable
353- // instance of UsedRing.
351+ // SAFETY: ` self.used` points to a valid, aligned, initialised, dereferenceable, readable
352+ // instance of ` UsedRing` .
354353 unsafe { ( * self . used . as_ptr ( ) ) . flags . load ( Ordering :: Acquire ) & 0x0001 == 0 }
355354 }
356355 }
@@ -359,7 +358,7 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
359358 /// the device.
360359 fn write_desc ( & mut self , index : u16 ) {
361360 let index = usize:: from ( index) ;
362- // Safe because self.desc is properly aligned, dereferenceable and initialised, and nothing
361+ // SAFETY: ` self.desc` is properly aligned, dereferenceable and initialised, and nothing
363362 // else reads or writes the descriptor during this block.
364363 unsafe {
365364 ( * self . desc . as_ptr ( ) ) [ index] = self . desc_shadow [ index] . clone ( ) ;
@@ -368,8 +367,8 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
368367
369368 /// Returns whether there is a used element that can be popped.
370369 pub fn can_pop ( & self ) -> bool {
371- // Safe because self.used points to a valid, aligned, initialised, dereferenceable, readable
372- // instance of UsedRing.
370+ // SAFETY: ` self.used` points to a valid, aligned, initialised, dereferenceable, readable
371+ // instance of ` UsedRing` .
373372 self . last_used_idx != unsafe { ( * self . used . as_ptr ( ) ) . idx . load ( Ordering :: Acquire ) }
374373 }
375374
@@ -378,8 +377,8 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
378377 pub fn peek_used ( & self ) -> Option < u16 > {
379378 if self . can_pop ( ) {
380379 let last_used_slot = self . last_used_idx & ( SIZE as u16 - 1 ) ;
381- // Safe because self.used points to a valid, aligned, initialised, dereferenceable,
382- // readable instance of UsedRing.
380+ // SAFETY: ` self.used` points to a valid, aligned, initialised, dereferenceable,
381+ // readable instance of ` UsedRing` .
383382 Some ( unsafe { ( * self . used . as_ptr ( ) ) . ring [ last_used_slot as usize ] . id as u16 } )
384383 } else {
385384 None
@@ -513,8 +512,8 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
513512 let last_used_slot = self . last_used_idx & ( SIZE as u16 - 1 ) ;
514513 let index;
515514 let len;
516- // Safe because self.used points to a valid, aligned, initialised, dereferenceable, readable
517- // instance of UsedRing.
515+ // SAFETY: ` self.used` points to a valid, aligned, initialised, dereferenceable, readable
516+ // instance of ` UsedRing` .
518517 unsafe {
519518 index = ( * self . used . as_ptr ( ) ) . ring [ last_used_slot as usize ] . id as u16 ;
520519 len = ( * self . used . as_ptr ( ) ) . ring [ last_used_slot as usize ] . len ;
@@ -525,7 +524,7 @@ impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE> {
525524 return Err ( Error :: WrongToken ) ;
526525 }
527526
528- // Safe because the caller ensures the buffers are valid and match the descriptor.
527+ // SAFETY: The caller ensures the buffers are valid and match the descriptor.
529528 unsafe {
530529 self . recycle_descriptors ( index, inputs, outputs) ;
531530 }
@@ -718,7 +717,7 @@ impl Descriptor {
718717 direction : BufferDirection ,
719718 extra_flags : DescFlags ,
720719 ) {
721- // Safe because our caller promises that the buffer is valid.
720+ // SAFETY: Our caller promises that the buffer is valid.
722721 unsafe {
723722 self . addr = H :: share ( buf, direction) as u64 ;
724723 }
0 commit comments