From: Alexander Shiyan <eagle.alexander923@gmail.com>
To: barebox@lists.infradead.org
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>
Subject: [PATCH] serial: ns16550: fix memory leak of linux_earlycon_name on probe failure
Date: Mon, 31 Aug 2026 15:04:17 +0300 [thread overview]
Message-ID: <20260831120417.220684-1-eagle.alexander923@gmail.com> (raw)
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
reply other threads:[~2026-08-31 12:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260831120417.220684-1-eagle.alexander923@gmail.com \
--to=eagle.alexander923@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox