aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2023-11-21 20:12:36 +0700
committerVadim Yanitskiy <vyanitskiy@sysmocom.de>2023-11-21 20:17:11 +0700
commit459cb06912c4d7954f0f54b793bf6d232a3c43e8 (patch)
tree92fe763cee265f68a9a7a7e5146d20f2d410f0fb
parentffdd99779df9c83ebd4b8460dff1c8da8da6dcba (diff)
soft_uart: check n_bits against 0 in osmo_soft_uart_tx_ubits()
Currently calling this function with n_ubits == 0 would result in requesting one character from the application (via the .tx_cb()), but not actually transmitting anything. Make it return early. Change-Id: Icbf99a9f2f6fa64dd71a5f37922f9001577c6c97 Related: OS#4396
-rw-r--r--src/core/soft_uart.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/core/soft_uart.c b/src/core/soft_uart.c
index e0f07802..4fffaeee 100644
--- a/src/core/soft_uart.c
+++ b/src/core/soft_uart.c
@@ -24,6 +24,7 @@
#include <stdint.h>
#include <errno.h>
+#include <osmocom/core/utils.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/soft_uart.h>
@@ -286,6 +287,9 @@ int osmo_soft_uart_tx_ubits(struct osmo_soft_uart *suart, ubit_t *ubits, size_t
size_t n_frame_bits, n_chars;
struct msgb *msg = NULL;
+ if (OSMO_UNLIKELY(n_ubits == 0))
+ return -EINVAL;
+
/* calculate UART frame size for the effective config */
n_frame_bits = 1 + cfg->num_data_bits + cfg->num_stop_bits;
if (cfg->parity_mode != OSMO_SUART_PARITY_NONE)