Skip to content

Commit f59e247

Browse files
ken4647dkalowsk
authored andcommitted
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 <[email protected]>
1 parent de1e76f commit f59e247

15 files changed

+36
-42
lines changed

drivers/serial/leuart_gecko.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int leuart_gecko_fifo_fill(const struct device *dev,
101101
int len)
102102
{
103103
LEUART_TypeDef *base = DEV_BASE(dev);
104-
uint8_t num_tx = 0U;
104+
int num_tx = 0U;
105105

106106
while ((len - num_tx > 0) &&
107107
(base->STATUS & LEUART_STATUS_TXBL)) {
@@ -116,7 +116,7 @@ static int leuart_gecko_fifo_read(const struct device *dev, uint8_t *rx_data,
116116
const int len)
117117
{
118118
LEUART_TypeDef *base = DEV_BASE(dev);
119-
uint8_t num_rx = 0U;
119+
int num_rx = 0U;
120120

121121
while ((len - num_rx > 0) &&
122122
(base->STATUS & LEUART_STATUS_RXDATAV)) {

drivers/serial/uart_gecko.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static int uart_gecko_fifo_fill(const struct device *dev, const uint8_t *tx_data
222222
int len)
223223
{
224224
const struct uart_gecko_config *config = dev->config;
225-
uint8_t num_tx = 0U;
225+
int num_tx = 0U;
226226

227227
while ((len - num_tx > 0) &&
228228
(config->base->STATUS & USART_STATUS_TXBL)) {
@@ -237,7 +237,7 @@ static int uart_gecko_fifo_read(const struct device *dev, uint8_t *rx_data,
237237
const int len)
238238
{
239239
const struct uart_gecko_config *config = dev->config;
240-
uint8_t num_rx = 0U;
240+
int num_rx = 0U;
241241

242242
while ((len - num_rx > 0) &&
243243
(config->base->STATUS & USART_STATUS_RXDATAV)) {

drivers/serial/uart_mcux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static int uart_mcux_fifo_fill(const struct device *dev,
179179
int len)
180180
{
181181
const struct uart_mcux_config *config = dev->config;
182-
uint8_t num_tx = 0U;
182+
int num_tx = 0U;
183183

184184
while ((len - num_tx > 0) &&
185185
(UART_GetStatusFlags(config->base) & kUART_TxDataRegEmptyFlag)) {
@@ -194,7 +194,7 @@ static int uart_mcux_fifo_read(const struct device *dev, uint8_t *rx_data,
194194
const int len)
195195
{
196196
const struct uart_mcux_config *config = dev->config;
197-
uint8_t num_rx = 0U;
197+
int num_rx = 0U;
198198

199199
while ((len - num_rx > 0) &&
200200
(UART_GetStatusFlags(config->base) & kUART_RxDataRegFullFlag)) {

drivers/serial/uart_mcux_flexcomm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static int mcux_flexcomm_fifo_fill(const struct device *dev,
146146
int len)
147147
{
148148
const struct mcux_flexcomm_config *config = dev->config;
149-
uint8_t num_tx = 0U;
149+
int num_tx = 0U;
150150

151151
while ((len - num_tx > 0) &&
152152
(USART_GetStatusFlags(config->base)
@@ -162,7 +162,7 @@ static int mcux_flexcomm_fifo_read(const struct device *dev, uint8_t *rx_data,
162162
const int len)
163163
{
164164
const struct mcux_flexcomm_config *config = dev->config;
165-
uint8_t num_rx = 0U;
165+
int num_rx = 0U;
166166

167167
while ((len - num_rx > 0) &&
168168
(USART_GetStatusFlags(config->base)

drivers/serial/uart_mcux_iuart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static int mcux_iuart_fifo_fill(const struct device *dev,
8686
int len)
8787
{
8888
const struct mcux_iuart_config *config = dev->config;
89-
uint8_t num_tx = 0U;
89+
int num_tx = 0U;
9090

9191
while ((len - num_tx > 0) &&
9292
(UART_GetStatusFlag(config->base, kUART_TxEmptyFlag))) {
@@ -101,7 +101,7 @@ static int mcux_iuart_fifo_read(const struct device *dev, uint8_t *rx_data,
101101
const int len)
102102
{
103103
const struct mcux_iuart_config *config = dev->config;
104-
uint8_t num_rx = 0U;
104+
int num_rx = 0U;
105105

106106
while ((len - num_rx > 0) &&
107107
(UART_GetStatusFlag(config->base, kUART_RxDataReadyFlag))) {

drivers/serial/uart_mcux_lpsci.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static int mcux_lpsci_fifo_fill(const struct device *dev,
8989
int len)
9090
{
9191
const struct mcux_lpsci_config *config = dev->config;
92-
uint8_t num_tx = 0U;
92+
int num_tx = 0U;
9393

9494
while ((len - num_tx > 0) &&
9595
(LPSCI_GetStatusFlags(config->base)
@@ -105,7 +105,7 @@ static int mcux_lpsci_fifo_read(const struct device *dev, uint8_t *rx_data,
105105
const int len)
106106
{
107107
const struct mcux_lpsci_config *config = dev->config;
108-
uint8_t num_rx = 0U;
108+
int num_rx = 0U;
109109

110110
while ((len - num_rx > 0) &&
111111
(LPSCI_GetStatusFlags(config->base)

drivers/serial/uart_mcux_lpuart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static int mcux_lpuart_fifo_fill(const struct device *dev,
233233
int len)
234234
{
235235
const struct mcux_lpuart_config *config = dev->config;
236-
uint8_t num_tx = 0U;
236+
int num_tx = 0U;
237237

238238
while ((len - num_tx > 0) &&
239239
(LPUART_GetStatusFlags(config->base)
@@ -248,7 +248,7 @@ static int mcux_lpuart_fifo_read(const struct device *dev, uint8_t *rx_data,
248248
const int len)
249249
{
250250
const struct mcux_lpuart_config *config = dev->config;
251-
uint8_t num_rx = 0U;
251+
int num_rx = 0U;
252252

253253
while ((len - num_rx > 0) &&
254254
(LPUART_GetStatusFlags(config->base)

drivers/serial/uart_nrfx_uart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ static int uart_nrfx_fifo_fill(const struct device *dev,
786786
const uint8_t *tx_data,
787787
int len)
788788
{
789-
uint8_t num_tx = 0U;
789+
int num_tx = 0U;
790790

791791
while ((len - num_tx > 0) &&
792792
event_txdrdy_check()) {
@@ -806,7 +806,7 @@ static int uart_nrfx_fifo_read(const struct device *dev,
806806
uint8_t *rx_data,
807807
const int size)
808808
{
809-
uint8_t num_rx = 0U;
809+
int num_rx = 0U;
810810

811811
while ((size - num_rx > 0) &&
812812
nrf_uart_event_check(uart0_addr, NRF_UART_EVENT_RXDRDY)) {

drivers/serial/uart_pl011.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static int pl011_runtime_config_get(const struct device *dev,
317317
static int pl011_fifo_fill(const struct device *dev,
318318
const uint8_t *tx_data, int len)
319319
{
320-
uint8_t num_tx = 0U;
320+
int num_tx = 0U;
321321

322322
while (!(get_uart(dev)->fr & PL011_FR_TXFF) && (len - num_tx > 0)) {
323323
get_uart(dev)->dr = tx_data[num_tx++];
@@ -328,7 +328,7 @@ static int pl011_fifo_fill(const struct device *dev,
328328
static int pl011_fifo_read(const struct device *dev,
329329
uint8_t *rx_data, const int len)
330330
{
331-
uint8_t num_rx = 0U;
331+
int num_rx = 0U;
332332

333333
while ((len - num_rx > 0) && !(get_uart(dev)->fr & PL011_FR_RXFE)) {
334334
rx_data[num_rx++] = get_uart(dev)->dr;

drivers/serial/uart_renesas_ra8_sci_b.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static int uart_ra_sci_b_fifo_fill(const struct device *dev, const uint8_t *tx_d
256256
{
257257
struct uart_ra_sci_b_data *data = dev->data;
258258
const struct uart_ra_sci_b_config *cfg = dev->config;
259-
uint8_t num_tx = 0U;
259+
int num_tx = 0U;
260260

261261
if (IS_ENABLED(CONFIG_UART_RA_SCI_B_UART_FIFO_ENABLE) && data->sci.fifo_depth > 0) {
262262
while ((size - num_tx > 0) && cfg->regs->FTSR != 0x10U) {
@@ -281,7 +281,7 @@ static int uart_ra_sci_b_fifo_read(const struct device *dev, uint8_t *rx_data, c
281281
{
282282
struct uart_ra_sci_b_data *data = dev->data;
283283
const struct uart_ra_sci_b_config *cfg = dev->config;
284-
uint8_t num_rx = 0U;
284+
int num_rx = 0U;
285285

286286
if (IS_ENABLED(CONFIG_UART_RA_SCI_B_UART_FIFO_ENABLE) && data->sci.fifo_depth > 0) {
287287
while ((size - num_rx > 0) && cfg->regs->FRSR_b.R > 0U) {

0 commit comments

Comments
 (0)