@@ -338,9 +338,12 @@ impl EventChannel::ver {
338338 /// Polls for new Event messages on this ring.
339339 pub ( crate ) fn poll ( & mut self ) {
340340 while let Some ( msg) = self . ch . get ( 0 ) {
341+ // SAFETY: The raw view is always valid for all bit patterns.
341342 let tag = unsafe { msg. raw . 0 } ;
342343 match tag {
343344 0 ..=EVENT_MAX => {
345+ // SAFETY: Since we have checked the tag to be in range,
346+ // accessing the enum view is valid.
344347 let msg = unsafe { msg. msg } ;
345348
346349 cls_dev_dbg ! ( EventCh , self . dev, "Event: {:?}\n " , msg) ;
@@ -426,6 +429,7 @@ impl EventChannel::ver {
426429 }
427430 }
428431 _ => {
432+ // SAFETY: The raw view is always valid for all bit patterns.
429433 dev_warn ! ( self . dev. as_ref( ) , "Unknown event message: {:?}\n " , unsafe {
430434 msg. raw
431435 } ) ;
@@ -593,13 +597,17 @@ impl StatsChannel::ver {
593597 /// Polls for new statistics messages on this ring.
594598 pub ( crate ) fn poll ( & mut self ) {
595599 while let Some ( msg) = self . ch . get ( 0 ) {
600+ // SAFETY: The raw view is always valid for all bit patterns.
596601 let tag = unsafe { msg. raw . 0 } ;
597602 match tag {
598603 0 ..=STATS_MAX :: ver => {
604+ // SAFETY: Since we have checked the tag to be in range,
605+ // accessing the enum view is valid.
599606 let msg = unsafe { msg. msg } ;
600607 cls_dev_dbg ! ( StatsCh , self . dev, "Stats: {:?}\n " , msg) ;
601608 }
602609 _ => {
610+ // SAFETY: The raw view is always valid for all bit patterns.
603611 pr_warn ! ( "Unknown stats message: {:?}\n " , unsafe { msg. raw } ) ;
604612 }
605613 }
0 commit comments