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: c4d37215a8 ("[SERIAL] sunsab: Convert to of_driver framework.")
Signed-off-by: Yuan Can <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
This commit is contained in:
Yuan Can 2022-11-23 06:12:12 +00:00 • committed by Greg Kroah-Hartman
commit 98c01a728b

View file

@ -1140,7 +1140,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)