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

Fix for #4565 (rx fifo length), protect access to rx_buffer #4568

Merged
merged 14 commits into from
Mar 28, 2018
Merged

Fix for #4565 (rx fifo length), protect access to rx_buffer #4568

merged 14 commits into from
Mar 28, 2018

Conversation

devyte
Copy link
Collaborator

@devyte devyte commented Mar 26, 2018

Fixes #4565 , and protects access to rx_buffer by disabling/enabling the uart interrupt.

@devyte devyte requested a review from d-a-v March 26, 2018 15:56
return uart_rx_buffer_available(uart) + uart_rx_fifo_available(uart);
ETS_UART_INTR_DISABLE();
int uartrxbufferavailable = uart_rx_buffer_available(uart);
ETS_UART_INTR_ENABLE();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, for more clarity, what about renaming uart_rx_buffer_available to uart_rx_buffer_available_unprotected ?

if (!uart_rx_available(uart)) {
ETS_UART_INTR_ENABLE();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uart_rx_available() also conflictly calls INTR_DISABLE+ENABLE. Maybe adding a new static uart_rx_available_unprotected() would help (L82 too)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this needs rework.

@@ -140,15 +140,17 @@ int uart_peek_char(uart_t* uart)
if(uart == NULL || !uart->rx_enabled) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment right next to uart_rx_copy_fifo_to_buffer(). For more clarity, I guess it could be renamed to uart_rx_copy_fifo_to_buffer_unprotected() too.

@devyte
Copy link
Collaborator Author

devyte commented Mar 27, 2018

Alright, did a more thorough rework of the file, including some refactoring and styling. It's gonna be a bit hard to understand some of the changes, but basically I put all the unsafe functions together, factored out some of the uart register magic to unify the relevant code, tracked all the function entrypoints to make sure there are no uart interrupt double enable/disables, and added a dab of constness.
My code changes are "I see the matrix" style, so I've done no testing whatsoever. All I know is it builds. Extra eyes and all testing welcome!

@devyte
Copy link
Collaborator Author

devyte commented Mar 27, 2018

@d-a-v looks like CI builds now. I have no idea why my local workspace built before.
Anyways, how does this look?

@devyte devyte merged commit 29580e8 into esp8266:master Mar 28, 2018
@devyte devyte deleted the uart_int branch March 28, 2018 01:28
bryceschober pushed a commit to bryceschober/Arduino that referenced this pull request Apr 5, 2018
…sp8266#4568)

* Fix for esp8266#4565 (rx fifo length), protect access to rx_buffer

* Fix typo

* reworked to separate safe from unsafe functions, factorized some code, constness

* additional rework for uart_rx_fifo_available()

* swapped unsafe function definition order

* Remove static for overrun string

* Some shorthand for perf and readability

(cherry picked from commit 29580e8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants