Skip to content
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

[Backport v2.7-branch] drivers: i2c: i2c_dw: Fixed integer overflow in i2c_dw_data_ask(). #67345

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

zephyrbot
Copy link
Collaborator

@zephyrbot zephyrbot commented Jan 9, 2024

Backport 4824e40 from #66685.

Fixes #67692

The 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.

Storing the rx_empty empty on a signed 32-bit variable instead of a 8-bit
one solves the issue and is compliant with the controller hardware
specifications of a maximum FIFO depth of 256 bytes.

It has been agreed with upstream maintainers to change the type of the
variables tx_empty, rx_empty, cnt, rx_buffer_depth and tx_buffer_depth to
plain int because it is most effectively handled by the CPUs. Using 8-bit
or 16-bit variables had no meaning here.

Signed-off-by: Adrien Ricciardi <[email protected]>
(cherry picked from commit 4824e40)
@zephyrbot zephyrbot requested a review from dcpleung as a code owner January 9, 2024 02:57
@zephyrbot zephyrbot added the Backport Backport PR and backport failure issues label Jan 9, 2024
@cfriedt
Copy link
Member

cfriedt commented Jan 9, 2024

@dkalowsk - this one needs a bug report. Would you be up for writing one?

@dkalowsk
Copy link
Contributor

Issue: #67688

@cfriedt
Copy link
Member

cfriedt commented Jan 16, 2024

Issue: #67688

Woops - we have 2 now

#67692

@cfriedt cfriedt merged commit 1008691 into v2.7-branch Jan 16, 2024
21 of 22 checks passed
@nashif nashif deleted the backport-66685-to-v2.7-branch branch February 13, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: I2C Backport Backport PR and backport failure issues
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants