-
Notifications
You must be signed in to change notification settings - Fork 7.6k
HardwareSerial: fix begin() lock issue on error path #8182
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
Conversation
If the user supplied a wrong UART number, the begin() method would return without releasing the lock. Add missing unlock call.
cores/esp32/HardwareSerial.cpp
Outdated
@@ -367,6 +367,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in | |||
#endif | |||
default: | |||
log_e("Bad UART Number"); | |||
HSERIAL_MUTEX_UNLOCK(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This default case is here just to make the compiler happy. In fact, you will never get here with wrong port number, because this check has already been made on line 330
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tested the compilation and it doesn't complain about the lack of default:
case.
I'll just remove this case from the code to make it clearer.
@pillo79 - Thanks for noticing it and for the PR. @me-no-dev - It can be merged to the 2.x and 3.0.0 branches. |
Sorry for missing that! 😒 Removing the default case is even better, thanks 👍 |
If the user supplied a wrong UART number, the
begin()
method would return without releasing the lock. Add missingUNLOCK()
call.No other unbalanced locks exist in this file.