Skip to content

Integer overflow in DW I2C driver i2c_dw_data_ask() function. #67692

@RICCIARDI-Adrien

Description

@RICCIARDI-Adrien

Describe the bug
The DW I2C controller can implement a reception FIFO as deep as 256 bytes.
However, the computation made by the driver code to determine how many bytes can be asked is stored in a signed 8-bit variable called rx_empty.

If the reception FIFO depth is greater or equal to 128 bytes and the FIFO is currently empty, the rx_empty value will be 128 (or more), which stands for a negative value as the variable is signed.

Thus, the later code checking if the FIFO is full will run while it should not and exit from the i2c_dw_data_ask() function too early.

This hangs the controller in an infinite loop of interrupt storm because the interrupt flags are never cleared.

To Reproduce
Steps to reproduce the behavior:

Expected behavior
The I2C controller should correctly receive the data.

Impact
This is a showstopper because it triggers an i2C interrupt storm because I2C interrupts are never handled.

Logs and console output
None available.

Environment (please complete the following information):

  • OS: Linux
  • Toolchain: Zephyr SDK
  • Commit SHA or Version used: v3.5.0 (commit a6eef0b)

Additional context
This bug has already been fixed on mainline (see #66685).
I was asked by the Zephyr maintainers to file a bug for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThe issue is a bug, or the PR is fixing a bug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions