Commit f59e2477 authored by Zheng Wu's avatar Zheng Wu Committed by Dan Kalowsky
Browse files

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: default avatarZheng Wu <ken4647@outlook.com>
parent de1e76fa
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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)) {
+2 −2
Original line number Diff line number Diff line
@@ -222,7 +222,7 @@ static int uart_gecko_fifo_fill(const struct device *dev, const uint8_t *tx_data
			       int len)
{
	const struct uart_gecko_config *config = dev->config;
	uint8_t num_tx = 0U;
	int num_tx = 0U;

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

	while ((len - num_rx > 0) &&
	       (config->base->STATUS & USART_STATUS_RXDATAV)) {
+2 −2
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ static int uart_mcux_fifo_fill(const struct device *dev,
			       int len)
{
	const struct uart_mcux_config *config = dev->config;
	uint8_t num_tx = 0U;
	int num_tx = 0U;

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

	while ((len - num_rx > 0) &&
	       (UART_GetStatusFlags(config->base) & kUART_RxDataRegFullFlag)) {
+2 −2
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ static int mcux_flexcomm_fifo_fill(const struct device *dev,
				   int len)
{
	const struct mcux_flexcomm_config *config = dev->config;
	uint8_t num_tx = 0U;
	int num_tx = 0U;

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

	while ((len - num_rx > 0) &&
	       (USART_GetStatusFlags(config->base)
+2 −2
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ static int mcux_iuart_fifo_fill(const struct device *dev,
				int len)
{
	const struct mcux_iuart_config *config = dev->config;
	uint8_t num_tx = 0U;
	int num_tx = 0U;

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

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