From 877cfed3b26f2fd5a64b482e56b180b67597542d Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Sun, 12 Nov 2023 17:21:31 +0700 Subject: [PATCH] soft_uart: add osmo_soft_uart_free() Change-Id: I2fdcf6116144d8f16cf4167c37cfa7215d16337f Related: OS#4396 --- include/osmocom/core/soft_uart.h | 1 + src/core/libosmocore.map | 1 + src/core/soft_uart.c | 14 ++++++++++++++ 3 files changed, 16 insertions(+) diff --git a/include/osmocom/core/soft_uart.h b/include/osmocom/core/soft_uart.h index 36a43fe7d..4f9c1fcfc 100644 --- a/include/osmocom/core/soft_uart.h +++ b/include/osmocom/core/soft_uart.h @@ -75,6 +75,7 @@ struct osmo_soft_uart_cfg { struct osmo_soft_uart; struct osmo_soft_uart *osmo_soft_uart_alloc(void *ctx, const char *name); +void osmo_soft_uart_free(struct osmo_soft_uart *suart); int osmo_soft_uart_configure(struct osmo_soft_uart *suart, const struct osmo_soft_uart_cfg *cfg); int osmo_soft_uart_enable(struct osmo_soft_uart *suart, bool rx, bool tx); diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map index c08d3ff87..142e4c427 100644 --- a/src/core/libosmocore.map +++ b/src/core/libosmocore.map @@ -440,6 +440,7 @@ osmo_sock_set_priority; osmo_sock_unix_init; osmo_sock_unix_init_ofd; osmo_soft_uart_alloc; +osmo_soft_uart_free; osmo_soft_uart_configure; osmo_soft_uart_enable; osmo_soft_uart_rx_ubits; diff --git a/src/core/soft_uart.c b/src/core/soft_uart.c index 22292af37..78604530d 100644 --- a/src/core/soft_uart.c +++ b/src/core/soft_uart.c @@ -220,6 +220,20 @@ struct osmo_soft_uart *osmo_soft_uart_alloc(void *ctx, const char *name) return suart; } +/*! Release memory taken by the given soft-UART. + * \param[in] suart soft-UART instance to be free()d. */ +void osmo_soft_uart_free(struct osmo_soft_uart *suart) +{ + if (suart == NULL) + return; + + osmo_timer_del(&suart->rx.timer); + msgb_free(suart->rx.msg); + + talloc_free((void *)suart->name); + talloc_free(suart); +} + /*! change soft-UART configuration to user-provided config */ int osmo_soft_uart_configure(struct osmo_soft_uart *suart, const struct osmo_soft_uart_cfg *cfg) {