From: Yuan Can Date: Wed, 23 Nov 2022 06:12:12 +0000 (+0000) Subject: serial: sunsab: Fix error handling in sunsab_init() X-Git-Tag: v5.15.92~1003 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=07d547d74244d0283ac2c46469ce90637750eae0;p=platform%2Fkernel%2Flinux-rpi.git serial: sunsab: Fix error handling in sunsab_init() [ Upstream commit 1a6ec673fb627c26e2267ca0a03849f91dbd9b40 ] The sunsab_init() returns the platform_driver_register() directly without checking its return value, if platform_driver_register() failed, the allocated sunsab_ports is leaked. Fix by free sunsab_ports and set it to NULL when platform_driver_register() failed. Fixes: c4d37215a824 ("[SERIAL] sunsab: Convert to of_driver framework.") Signed-off-by: Yuan Can Link: https://lore.kernel.org/r/20221123061212.52593-1-yuancan@huawei.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- diff --git a/drivers/tty/serial/sunsab.c b/drivers/tty/serial/sunsab.c index 92e5726..ac7cb80 100644 --- a/drivers/tty/serial/sunsab.c +++ b/drivers/tty/serial/sunsab.c @@ -1137,7 +1137,13 @@ static int __init sunsab_init(void) } } - return platform_driver_register(&sab_driver); + err = platform_driver_register(&sab_driver); + if (err) { + kfree(sunsab_ports); + sunsab_ports = NULL; + } + + return err; } static void __exit sunsab_exit(void)