-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove aliasing &mut references to DMA buffers (possible UB) #41
base: master
Are you sure you want to change the base?
Conversation
I need to look into the correct way to do this myself and see what I dig up |
Not seeing anything better. The example in stm32h7xx-hal was updated but still has this warning. |
Thanks for taking a look. "anything better" about or than what do you mean? Sorry, don't quite understand. I had a look at the stm32h7xx-hal dma example which uses MaybeUninit as well as Since I wrote this code, the new |
I tried using the MaybeUninit from the stm32h7xx-hal crate but it still gave the same warning with the assume_init() method. Raw pointers seems correct but not sure exactly how to use them yet. Maybe a combination of the two. Use Maybeuninit to handle the Init (does it even need to be initialized for DMA?) and then convert to the |
Cleans up nicely with |
Need a similar wrapper for usb_midi and we can merge it. |
Great, I'll get on it later this week! |
UsbBus::new requires a &'static mut so &raw mut cannot be used. Therefore, I wrote a warning not to reference EP_MEMORY again.
So |
Getting the "warning: creating a mutable reference to mutable static is discouraged" warning prompted me to look into the code in
audio.rs
. Changinginto
gets rid of the error, but I'm not convinced this is not undefined behaviour. The reason being that multiple
&mut
references are created to bothTX_BUFFER
andRX_BUFFER
, and used viaInput
andOutput
.This pull request gets around the issue by wrapping a raw pointer to the buffer instead of storing the references directly.
*mut
pointers are allowed to alias. References are created whenever the buffer is accessed, but these are short lived.I have verified this works in practice: https://github.com/ErikNatanael/daisy-blank/tree/example-sine-wave
The first commit is the changes in PR #40