drivers: serial: fix potential overflow in fifo_fill and fifo_read

Change the type of num_tx/num_rx to avoid overflow.

Fixes #80599

Signed-off-by: Zheng Wu <ken4647@outlook.com>
This commit is contained in:
Zheng Wu 2024-10-30 19:34:45 +08:00 committed by Dan Kalowsky
commit f59e2477ba
15 changed files with 36 additions and 42 deletions

View file

@ -101,7 +101,7 @@ static int leuart_gecko_fifo_fill(const struct device *dev,
int len)
{
LEUART_TypeDef *base = DEV_BASE(dev);
uint8_t num_tx = 0U;
int num_tx = 0U;
while ((len - num_tx > 0) &&
(base->STATUS & LEUART_STATUS_TXBL)) {
@ -116,7 +116,7 @@ static int leuart_gecko_fifo_read(const struct device *dev, uint8_t *rx_data,
const int len)
{
LEUART_TypeDef *base = DEV_BASE(dev);
uint8_t num_rx = 0U;
int num_rx = 0U;
while ((len - num_rx > 0) &&
(base->STATUS & LEUART_STATUS_RXDATAV)) {