serial: sunsab: Fix error handling in sunsab_init()

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: c4d37215a8 ("[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>
This commit is contained in:
Yuan Can 2022-11-23 06:12:12 +00:00 коммит произвёл Greg Kroah-Hartman
Родитель 1307c5d33c
Коммит 1a6ec673fb
1 изменённых файлов: 7 добавлений и 1 удалений

Просмотреть файл

@ -1131,7 +1131,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) static void __exit sunsab_exit(void)