This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 444e38c6b5d20228623b5796635a184b72c6207c Author: yintao <[email protected]> AuthorDate: Wed Oct 23 19:32:56 2024 +0800 drivers/serial/uart_rpmsg: handle the uart_register() failures uart_rpmsg_init() ignored the result of uart_register(). When the name was already taken it still returned 0 and left the rpmsg callback registered, so the device created a second endpoint with no tty behind it. Return the error and undo the callback registration, and unregister the tty when only the console registration fails. Signed-off-by: yintao <[email protected]> Signed-off-by: Bowen Wang <[email protected]> --- drivers/serial/uart_rpmsg.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/serial/uart_rpmsg.c b/drivers/serial/uart_rpmsg.c index 2fc7d273f38..9055b9e3bc7 100644 --- a/drivers/serial/uart_rpmsg.c +++ b/drivers/serial/uart_rpmsg.c @@ -30,6 +30,7 @@ #include <stdio.h> #include <string.h> +#include <nuttx/debug.h> #include <nuttx/fs/ioctl.h> #include <nuttx/kmalloc.h> #include <nuttx/mutex.h> @@ -456,12 +457,33 @@ int uart_rpmsg_init(FAR const char *cpuname, FAR const char *devname, snprintf(name, sizeof(name), "%s%s", UART_RPMSG_DEV_PREFIX, devname); - uart_register(name, dev); + ret = uart_register(name, dev); + if (ret < 0) + { + rpmsgerr("uart register failed, ret=%d\n", ret); + goto fail_with_rpmsg; + } if (dev->isconsole) { - uart_register(UART_RPMSG_DEV_CONSOLE, dev); + ret = uart_register(UART_RPMSG_DEV_CONSOLE, dev); + if (ret < 0) + { + rpmsgerr("uart register console failed, ret=%d\n", ret); + unregister_driver(name); + goto fail_with_rpmsg; + } } - return 0; + return OK; + +fail_with_rpmsg: + rpmsg_unregister_callback(dev, + uart_rpmsg_device_created, + uart_rpmsg_device_destroy, + NULL, + NULL); + nxmutex_destroy(&priv->lock); + kmm_free(dev); + return ret; }
