Skip to content

Commit

Permalink
Merge pull request #439 from nrf-rs/soundness
Browse files Browse the repository at this point in the history
Panic if Channel::channel() returns an invalid value.
  • Loading branch information
qwandor authored Apr 10, 2024
2 parents 233a8aa + da831d2 commit 9e0aa2d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions nrf-hal-common/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::{
ADC,
},
};
use core::hint::unreachable_unchecked;

#[cfg(feature = "embedded-hal-02")]
pub trait Channel: embedded_hal_02::adc::Channel<Adc, ID = u8> {}
Expand Down Expand Up @@ -83,9 +82,9 @@ impl Adc {
.0
.config
.modify(|_, w| w.inpsel().supply_two_thirds_prescaling()),
// This can never happen the only analog pins have already been defined
// PAY CLOSE ATTENTION TO ANY CHANGES TO THIS IMPL OR THE `channel_mappings!` MACRO
_ => unsafe { unreachable_unchecked() },
// This can never happen with the `Channel` implementations provided, as the only analog
// pins have already been covered.
_ => panic!("Invalid channel"),
}

self.0.events_end.write(|w| unsafe { w.bits(0) });
Expand Down

0 comments on commit 9e0aa2d

Please sign in to comment.