[PATCH 2/4] serial: men_z135_uart: do not release an unrequested memory region
From: Praneeth Balasubramanian
Date: Sat Dec 05 2026 - 01:36:02 EST
men_z135_config_port() sets the port type and ignores the return value
of men_z135_request_port(). The port type is also set in probe. So the
port stays registered even when the memory request fails, for example
when mcb_request_mem() returns -EBUSY because the region is already
claimed.
serial core calls release_port for any port with a known type. After
a failed request uart->mem is still NULL, and men_z135_release_port()
passes it to mcb_release_mem(), which dereferences it. When ioremap()
fails instead, men_z135_request_port() releases the region itself but
leaves uart->mem set. A later release_port then releases the same
region a second time.
Set uart->mem only once the region is requested and mapped. In
men_z135_release_port(), release the region only if uart->mem is set,
and clear it afterwards.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 37f0679964fa ("tty: serial: men_z135_uart.c: use mcb memory region size instead of hardcoded one")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Praneeth Balasubramanian <praneethb2002@xxxxxxxxx>
---
Notes:
This was found by an LLM-based audit, part of research at UCSB SecLab.
An LLM turned a kernel comment into a rule, and three LLM votes checked
the code against it. The fix and changelog were drafted with GLM-5.3,
then checked against the source and partly rewritten with Claude Opus
5.5. I reviewed the patch and take responsibility for it.
Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
reproducer. I do not have this hardware.
drivers/tty/serial/men_z135_uart.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/men_z135_uart.c b/drivers/tty/serial/men_z135_uart.c
index 861b783cec3d..2eddac1da37e 100644
--- a/drivers/tty/serial/men_z135_uart.c
+++ b/drivers/tty/serial/men_z135_uart.c
@@ -726,7 +726,10 @@ static void men_z135_release_port(struct uart_port *port)
iounmap(port->membase);
port->membase = NULL;
- mcb_release_mem(uart->mem);
+ if (uart->mem) {
+ mcb_release_mem(uart->mem);
+ uart->mem = NULL;
+ }
}
static int men_z135_request_port(struct uart_port *port)
@@ -740,13 +743,13 @@ static int men_z135_request_port(struct uart_port *port)
return PTR_ERR(mem);
port->mapbase = mem->start;
- uart->mem = mem;
port->membase = ioremap(mem->start, resource_size(mem));
if (port->membase == NULL) {
mcb_release_mem(mem);
return -ENOMEM;
}
+ uart->mem = mem;
return 0;
}
--
2.25.1