Fix PeripheralRef soundness issue allowing &T.
Fix soundness issue introduced in a previous soundness fix https://github.com/embassy-rs/embassy/pull/2602 . PeripheralRef must not implement DerefMut itself, but the blanket impl must still require DerefMut. Otherwise you can create two instances of a driver on the same uart by using `&my_uart`.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use core::marker::PhantomData;
|
||||
use core::ops::Deref;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
|
||||
/// An exclusive reference to a peripheral.
|
||||
///
|
||||
@@ -155,7 +155,7 @@ pub trait Peripheral: Sized {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, T: Deref> Peripheral for T
|
||||
impl<'b, T: DerefMut> Peripheral for T
|
||||
where
|
||||
T::Target: Peripheral,
|
||||
{
|
||||
@@ -163,6 +163,15 @@ where
|
||||
|
||||
#[inline]
|
||||
unsafe fn clone_unchecked(&self) -> Self::P {
|
||||
self.deref().clone_unchecked()
|
||||
T::Target::clone_unchecked(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, T: Peripheral> Peripheral for PeripheralRef<'_, T> {
|
||||
type P = T::P;
|
||||
|
||||
#[inline]
|
||||
unsafe fn clone_unchecked(&self) -> Self::P {
|
||||
T::clone_unchecked(self)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user