Remove aliasing &mut references to DMA buffers (possible UB)#41
Remove aliasing &mut references to DMA buffers (possible UB)#41mtthw-meyer merged 10 commits intomtthw-meyer:masterfrom
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 |
|
Alright. Let me see if I can get that CI cleared up. |
|
CI is fixed if you grab main. |
|
Thanks! I had to update the Rust version even higher to the one which introduced the |
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
&mutreferences are created to bothTX_BUFFERandRX_BUFFER, and used viaInputandOutput.This pull request gets around the issue by wrapping a raw pointer to the buffer instead of storing the references directly.
*mutpointers 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