hsr: Handle failures in module init

BugLink: https://bugs.launchpad.net/bugs/2064561

[ Upstream commit 3cf28cd492308e5f63ed00b29ea03ca016264376 ]

A failure during registration of the netdev notifier was not handled at
all. A failure during netlink initialization did not unregister the netdev
notifier.

Handle failures of netdev notifier registration and netlink initialization.
Both functions should only return negative values on failure and thereby
lead to the hsr module not being loaded.

Fixes: f421436a59 ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)")
Signed-off-by: Felix Maurer <fmaurer@redhat.com>
Reviewed-by: Shigeru Yoshida <syoshida@redhat.com>
Reviewed-by: Breno Leitao <leitao@debian.org>
Link: https://lore.kernel.org/r/3ce097c15e3f7ace98fc7fd9bcbf299f092e63d1.1710504184.git.fmaurer@redhat.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Portia Stephens <portia.stephens@canonical.com>
Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
This commit is contained in:
Felix Maurer 2024-03-15 13:04:52 +01:00 committed by Stefan Bader
parent 4d038efb7f
commit 96716d6603
1 changed files with 11 additions and 4 deletions
net/hsr

View File

@ -113,14 +113,21 @@ static struct notifier_block hsr_nb = {
static int __init hsr_init(void)
{
int res;
int err;
BUILD_BUG_ON(sizeof(struct hsr_tag) != HSR_HLEN);
register_netdevice_notifier(&hsr_nb);
res = hsr_netlink_init();
err = register_netdevice_notifier(&hsr_nb);
if (err)
return err;
return res;
err = hsr_netlink_init();
if (err) {
unregister_netdevice_notifier(&hsr_nb);
return err;
}
return 0;
}
static void __exit hsr_exit(void)