Skip to content

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

Merged
merged 3 commits into from
May 11, 2023

Conversation

pillo79
Copy link
Contributor

@pillo79 pillo79 commented May 10, 2023

If the user supplied a wrong UART number, the begin() method would return without releasing the lock. Add missing UNLOCK() call.

No other unbalanced locks exist in this file.

If the user supplied a wrong UART number, the begin() method would
return without releasing the lock. Add missing unlock call.
@CLAassistant
Copy link

CLAassistant commented May 10, 2023

CLA assistant check
All committers have signed the CLA.

@@ -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();
Copy link
Member

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

Copy link
Collaborator

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.

@SuGlider SuGlider self-assigned this May 11, 2023
@SuGlider SuGlider added this to the 2.0.9 milestone May 11, 2023
@SuGlider
Copy link
Collaborator

@pillo79 - Thanks for noticing it and for the PR.
As wrote in the review, such default case will never happen because the _uart_nr is tested at the beginning of the function code.
I have removed such case from the switch in order to make the code clearer.

@me-no-dev - It can be merged to the 2.x and 3.0.0 branches.

@SuGlider SuGlider requested a review from me-no-dev May 11, 2023 13:06
@me-no-dev me-no-dev merged commit 3ec5f4e into espressif:master May 11, 2023
@pillo79
Copy link
Contributor Author

pillo79 commented May 16, 2023

@pillo79 - Thanks for noticing it and for the PR. As wrote in the review, such default case will never happen because the _uart_nr is tested at the beginning of the function code.

Sorry for missing that! 😒 Removing the default case is even better, thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

5 participants