Skip to content

Commit

Permalink
serial: sunsab: Fix error handling in sunsab_init()
Browse files Browse the repository at this point in the history
[ Upstream commit 1a6ec67 ]

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: c4d3721 ("[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>
  • Loading branch information
Yuan Can authored and gregkh committed Dec 31, 2022
1 parent 919e745 commit 07d547d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/tty/serial/sunsab.c
Expand Up @@ -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)
Expand Down

0 comments on commit 07d547d

Please sign in to comment.