Skip to content

Commit

Permalink
Fix logical dead code (gatzka#422)
Browse files Browse the repository at this point in the history
* Avoid logical dead code.

* Cast CSIZE correctly to an unsigned integer.

* Use enum in switch/case.

* Use default for switch/case.
  • Loading branch information
gatzka authored Oct 12, 2022
1 parent bc4b6f8 commit b44b761
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/src/platform/linux/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,20 @@ enum cio_error cio_uart_get_num_data_bits(const struct cio_uart *port, enum cio_
return err;
}

if ((tty.c_cflag & (tcflag_t)CS5) == (tcflag_t)CS5) {
switch (tty.c_cflag & (tcflag_t)CSIZE) {
case CS5:
*num_data_bits = CIO_UART_5_DATA_BITS;
} else if ((tty.c_cflag & (tcflag_t)CS6) == (tcflag_t)CS6) {
break;
case CS6:
*num_data_bits = CIO_UART_6_DATA_BITS;
} else if ((tty.c_cflag & (tcflag_t)CS7) == (tcflag_t)CS7) {
break;
case CS7:
*num_data_bits = CIO_UART_7_DATA_BITS;
} else {
break;
case CS8:
default:
*num_data_bits = CIO_UART_8_DATA_BITS;
break;
}

return CIO_SUCCESS;
Expand Down

0 comments on commit b44b761

Please sign in to comment.