Skip to content

drivers/serial/uart_rpmsg: fix the error path, flush tx on bind, copy the names - #22021

Open
CV-Bowen wants to merge 3 commits into
apache:masterfrom
CV-Bowen:up/P106-uart-rpmsg
Open

CV-Bowen wants to merge 3 commits into
apache:masterfrom
CV-Bowen:up/P106-uart-rpmsg

Conversation

@CV-Bowen

Copy link
Copy Markdown
Contributor

Summary

Three fixes to the rpmsg tty (drivers/serial/uart_rpmsg.c):

  • handle the uart_register() failures: uart_rpmsg_init() ignored the
    result of uart_register(). With a name that is already taken it
    returned 0 and left its rpmsg callback registered, so the device
    created a second endpoint with no tty behind it. Return the error and
    undo the registration; unregister the tty when only the console
    registration fails.
  • flush the tx buffer once the endpoint is bound: data written before
    the endpoint is bound (for example the nsh prompt) stayed in the tx
    buffer until the next write, so cu showed no prompt on connect.
  • keep a copy of the device and cpu names: the driver stored the
    caller's string pointers.

Impact

uart_rpmsg_init() can now return an error where it returned 0 before.
No other change.

Testing

Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205

sim:rpserver + sim:rpproxy: the proxy's nsh console is a uart_rpmsg tty,
reached from the server with cu /dev/ttyproxy; every proxy command of
the baseline below goes through it.

Error path: a test-only patch (not in this PR) makes the server register
the same rpmsg tty twice in rpmsg_serialinit():

  uart_rpmsg_init("proxy", "proxy", 4096, false);
  syslog(LOG_EMERG, "DUPTEST second uart_rpmsg_init ret=%d\n",
         uart_rpmsg_init("proxy", "proxy", 4096, false));
master this PR
second uart_rpmsg_init() returns 0 returns -17 (-EEXIST)
rpmsg dump all, endpoints named rpmsg-ttyproxy 2: the bound one and an unbound one (dest=4294967295) 1

Prompt on connect: boot both, run cu /dev/ttyproxy on the server and
wait 5 s without pressing Enter (test-only script driving the two sim
processes):

master this PR
proxy nsh prompt shown after cu /dev/ttyproxy (3 runs) no, no, no yes, yes, yes
master
[server] DUPTEST second uart_rpmsg_init ret=0
[server]     ept rpmsg-ttyproxy 0xe882de80: addr=1025 dest=1026 refcnt=1 priority=127 priv=0xe882ddb0
[server]     ept rpmsg-ttyproxy 0xe8830020: addr=1026 dest=4294967295 refcnt=1 priority=127 priv=0xe882ff50
this PR
[server] DUPTEST second uart_rpmsg_init ret=-17
[server]     ept rpmsg-ttyproxy 0xe4f17e80: addr=1025 dest=1026 refcnt=1 priority=127 priv=0xe4f17db0

No regression in rpmsg: sim:rpserver/rpproxy and qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping, rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC disabled, which current master needs for nxinit to start nsh there; unrelated to this change.

yintao and others added 3 commits November 19, 2026 00:46
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 <yintao@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
…ound

Data written to the tty before the endpoint is bound to the remote
side stays in the tx buffer until the next write. The nsh prompt is
written that way, so it does not show up when cu connects. Start a tx
transfer from the ns_bound callback.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
uart_rpmsg_init() stored the caller's devname and cpuname pointers,
so a caller passing a temporary buffer left them dangling. Copy both
into the private data.

Signed-off-by: wangshaoxin <wangshaoxin@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
@github-actions github-actions Bot added Area: Drivers Drivers issues Size: S The size of the change in this PR is small labels Nov 18, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant