serial: ns16550: fix memory leak of linux_earlycon_name on probe failure
PATCH 1/1 serial: ns16550: fix memory leak of linux_earlycon_name on probe failure
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.
--- drivers/serial/serial_ns16550.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/serial/serial_ns16550.c +3 -4
@@ -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:
Signature · 1 line
2.52.0
Sascha Hauer
AppliedQuoted 8 lines · Alexander Shiyan
When
console_register()fails, the dynamically allocatedlinux_earlycon_namestring was not freed, leading to a memory leak. Add afree_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.
[...]
Applied, thanks!
[1/1] serial: ns16550: fix memory leak of linux_earlycon_name on probe failure
https://git.pengutronix.de/cgit/barebox/commit/?id=5e97fb61df43 (link may not be stable)
Best regards,
Signature · 1 line
Sascha Hauer <[email protected]>