Apply suggestions from @henrygab

Check if memory allocation fails
Fix memory leak
Initialize struct in declaration
Add/Fix some notes
Remove unlikely() in favor of readability
Remove a hard-coded magic number
This commit is contained in:
wh201906 2023-11-15 18:04:52 +08:00
commit 3ee13c9ba6
No known key found for this signature in database
12 changed files with 113 additions and 44 deletions

View file

@ -298,6 +298,8 @@ int BUTTON_HELD(int ms) {
return BUTTON_ERROR;
}
// This function returns false if no data is available or
// the USB connection is invalid.
bool data_available(void) {
#ifdef WITH_FPC_USART_HOST
return usb_poll_validate_length() || (usart_rxdata_available() > 0);
@ -306,6 +308,9 @@ bool data_available(void) {
#endif
}
// This function doesn't check if the USB connection is valid.
// In most of the cases, you should use data_available() unless
// the timing is critical.
bool data_available_fast(void) {
#ifdef WITH_FPC_USART_HOST
return usb_available_length() || (usart_rxdata_available() > 0);