Add missing check for empty buffer in asynchronous read_write()
This commit is contained in:
parent
13636556d9
commit
b52e9a60eb
2 changed files with 10 additions and 0 deletions
|
@ -415,6 +415,10 @@ fn operation_frames<'a, 'b: 'a>(
|
||||||
|
|
||||||
// Check empty read buffer before starting transaction. Otherwise, we would risk halting with an
|
// Check empty read buffer before starting transaction. Otherwise, we would risk halting with an
|
||||||
// error in the middle of the transaction.
|
// error in the middle of the transaction.
|
||||||
|
//
|
||||||
|
// In principle, we could allow empty read frames within consecutive read operations, as long as
|
||||||
|
// at least one byte remains in the final (merged) read operation, but that makes the logic more
|
||||||
|
// complicated and error-prone.
|
||||||
if operations.iter().any(|op| match op {
|
if operations.iter().any(|op| match op {
|
||||||
Operation::Read(read) => read.is_empty(),
|
Operation::Read(read) => read.is_empty(),
|
||||||
Operation::Write(_) => false,
|
Operation::Write(_) => false,
|
||||||
|
|
|
@ -669,6 +669,12 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
|
||||||
RXDMA: crate::i2c::RxDma<T>,
|
RXDMA: crate::i2c::RxDma<T>,
|
||||||
TXDMA: crate::i2c::TxDma<T>,
|
TXDMA: crate::i2c::TxDma<T>,
|
||||||
{
|
{
|
||||||
|
// Check empty read buffer before starting transaction. Otherwise, we would not generate the
|
||||||
|
// stop condition below.
|
||||||
|
if read.is_empty() {
|
||||||
|
return Err(Error::Overrun);
|
||||||
|
}
|
||||||
|
|
||||||
self.write_frame(address, write, FrameOptions::FirstFrame).await?;
|
self.write_frame(address, write, FrameOptions::FirstFrame).await?;
|
||||||
self.read_frame(address, read, FrameOptions::FirstAndLastFrame).await
|
self.read_frame(address, read, FrameOptions::FirstAndLastFrame).await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue