Audit flexspi HAL for panics#535
Conversation
9f9a5dd to
945f780
Compare
bafd8aa to
8e9fcc1
Compare
2b4b40f to
62b50b6
Compare
jerrysxie
left a comment
There was a problem hiding this comment.
Can you add a testing section to the PR description to indicate which flash example was ran with this change?
Oh, and please announce the breaking change on Zulip, once it is ready to be merged. |
62b50b6 to
d5049be
Compare
d5049be to
c790c52
Compare
c790c52 to
97f46f0
Compare
Done. |
| ) -> Result<(), NorStorageBusError> { | ||
| if cmd.data_bytes.is_some() && cmd.data_bytes.unwrap() > MAX_TRANSFER_SIZE_PER_COMMAND as u32 { | ||
| // `program_lut` expects data_bytes to be available so we bail out early if that's not the case | ||
| let Some(data_bytes) = cmd.data_bytes else { |
There was a problem hiding this comment.
Maybe:
let data_bytes = cmd.data_bytes.ok_or(NorStorageBusError::StorageBusInternalError)?
There was a problem hiding this comment.
Ah yeah that is cleaner, unfortunately already merged :(
Removes unwraps and most indexing/slicing (two cases of slicing were left in but are very easy to see they can never panic) from the flexspi HAL.
I use this pattern several times for copying a remainder (which may be less than a 4 byte chunk):
since it avoids the need to use
copy_from_slice(with a calculated min length). However, this may be slightly less efficient than the equivalentcopy_from_sliceespecially since the compiler should be able to elide the panic path as remainder size can be determined statically (as_chunks::<N>guarantees statically that remainder length is less than N). Open to using the slice method with anallowlint if folks prefer.Testing
The changes in
peripheral.rsI was able to test by copying the unit tests to another project with my new implementations and verifying they pass (speaking of, I can't figure out how to getcargo testto work here).My other changes I at least tested using the
flexspi-embedded-storageandflexspi-nor-flashexamples on the 685evk. Still having issues getting the flexspi-nor-flash example working properly as I'm having trouble receiving defmt logs to verify it's functioning correctly.Resolves OpenDevicePartnership/embedded-services#643