From a3c65d076126528d4a8241c115217fcc7becdcfb Mon Sep 17 00:00:00 2001 From: Li <2429302320@qq.com> Date: Fri, 30 Oct 2026 22:46:39 +0800 Subject: [PATCH] fix(serial_test): pass RS-485 ioctl pointer via uintptr_t on 64-bit targets (#28925) The RS-485 ioctls cast the address of the stack variable rs485 to int, truncating the pointer on 64-bit targets (aarch64 NuttX, x86_64 Linux/SITL) so the kernel reads/writes the serial_rs485 struct at whatever 32-bit address remains. Cast through uintptr_t instead. Fixes #28923 Co-authored-by: rikaken2004 <244897142+rikaken2004@users.noreply.github.com> Co-authored-by: Julian Oes --- src/systemcmds/serial_test/serial_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/systemcmds/serial_test/serial_test.c b/src/systemcmds/serial_test/serial_test.c index 1faf45ad773..5e57ec9c0b6 100644 --- a/src/systemcmds/serial_test/serial_test.c +++ b/src/systemcmds/serial_test/serial_test.c @@ -680,7 +680,7 @@ static void setup_serial_port(int baud, struct g_mod_t *g_mod, struct cli_args_t tcsetattr(g_mod->_fd, TCSANOW, &newtio); /* enable/disable rs485 direction control */ - if (ioctl(g_mod->_fd, TIOCGRS485, (int) &rs485) < 0) { + if (ioctl(g_mod->_fd, TIOCGRS485, (unsigned long)(uintptr_t) &rs485) < 0) { if (g_cl->_rs485_delay >= 0) { /* error could be because hardware is missing rs485 support so only print when actually trying to activate it */ perror("Error getting RS-485 mode"); @@ -691,7 +691,7 @@ static void setup_serial_port(int baud, struct g_mod_t *g_mod, struct cli_args_t rs485.delay_rts_after_send = g_cl->_rs485_delay; rs485.delay_rts_before_send = 0; - if (ioctl(g_mod->_fd, TIOCSRS485, (int) &rs485) < 0) { + if (ioctl(g_mod->_fd, TIOCSRS485, (unsigned long)(uintptr_t) &rs485) < 0) { perror("Error setting RS-485 mode"); } @@ -700,7 +700,7 @@ static void setup_serial_port(int baud, struct g_mod_t *g_mod, struct cli_args_t rs485.delay_rts_after_send = 0; rs485.delay_rts_before_send = 0; - if (ioctl(g_mod->_fd, TIOCSRS485, (int) &rs485) < 0) { + if (ioctl(g_mod->_fd, TIOCSRS485, (unsigned long)(uintptr_t) &rs485) < 0) { perror("Error setting RS-232 mode"); } }