* [PATCH] serial: ns16550: fix memory leak of linux_earlycon_name on probe failure
@ 2026-08-31 12:04 Alexander Shiyan
0 siblings, 0 replies; only message in thread
From: Alexander Shiyan @ 2026-08-31 12:04 UTC (permalink / raw)
To: barebox; +Cc: Alexander Shiyan
When console_register() fails, the dynamically allocated
linux_earlycon_name string was not freed, leading to a memory leak.
Add a free_const() call on the error path to release it.
Also simplify the success path by returning 0 directly after
successful registration, making the code more readable.
Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
drivers/serial/serial_ns16550.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index 72bf8e4647..2c6ddabf85 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -554,12 +554,11 @@ static int ns16550_probe(struct device *dev)
devtype->init_port(cdev);
ret = console_register(cdev);
- if (ret)
- goto clk_disable;
+ if (!ret)
+ return 0;
- return 0;
+ free_const(cdev->linux_earlycon_name);
-clk_disable:
clk_disable(priv->clk);
clk_put(priv->clk);
release_region:
--
2.52.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-08-31 12:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-31 12:04 [PATCH] serial: ns16550: fix memory leak of linux_earlycon_name on probe failure Alexander Shiyan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox