serial: sunsab: Fix error handling in sunsab_init()
authorYuan Can <yuancan@huawei.com>
Wed, 23 Nov 2022 06:12:12 +0000 (06:12 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:14:28 +0000 (13:14 +0100)
commit07d547d74244d0283ac2c46469ce90637750eae0
tree5872e28247550ee28770542fbc5ff7ad84427720
parent919e745fdd0dc54fe34b6b1100035ad6a4e79b69
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 <yuancan@huawei.com>
Link: https://lore.kernel.org/r/20221123061212.52593-1-yuancan@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/tty/serial/sunsab.c