All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v2] hsr: Handle failures in module init
@ 2024-03-15 12:04 Felix Maurer
  2024-03-18  5:23 ` Shigeru Yoshida
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Felix Maurer @ 2024-03-15 12:04 UTC (permalink / raw)
  To: netdev; +Cc: davem, edumazet, kuba, pabeni, leitao, dkirjanov

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: f421436a591d ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)")
Signed-off-by: Felix Maurer <fmaurer@redhat.com>
---
 net/hsr/hsr_main.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/net/hsr/hsr_main.c b/net/hsr/hsr_main.c
index cb83c8feb746..9756e657bab9 100644
--- a/net/hsr/hsr_main.c
+++ b/net/hsr/hsr_main.c
@@ -148,14 +148,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;
+
+	err = hsr_netlink_init();
+	if (err) {
+		unregister_netdevice_notifier(&hsr_nb);
+		return err;
+	}
 
-	return res;
+	return 0;
 }
 
 static void __exit hsr_exit(void)
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net v2] hsr: Handle failures in module init
  2024-03-15 12:04 [PATCH net v2] hsr: Handle failures in module init Felix Maurer
@ 2024-03-18  5:23 ` Shigeru Yoshida
  2024-03-18  9:36 ` Breno Leitao
  2024-03-19 12:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Shigeru Yoshida @ 2024-03-18  5:23 UTC (permalink / raw)
  To: fmaurer; +Cc: netdev, davem, edumazet, kuba, pabeni, leitao, dkirjanov

On Fri, 15 Mar 2024 13:04:52 +0100, Felix Maurer wrote:
> 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: f421436a591d ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)")
> Signed-off-by: Felix Maurer <fmaurer@redhat.com>

The patch LGTM. Module initialization errors are handled
correctly. Netdev notifier is correctly unregistered when netlink
initialization fails.

Reviewed-by: Shigeru Yoshida <syoshida@redhat.com>

> ---
>  net/hsr/hsr_main.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/net/hsr/hsr_main.c b/net/hsr/hsr_main.c
> index cb83c8feb746..9756e657bab9 100644
> --- a/net/hsr/hsr_main.c
> +++ b/net/hsr/hsr_main.c
> @@ -148,14 +148,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;
> +
> +	err = hsr_netlink_init();
> +	if (err) {
> +		unregister_netdevice_notifier(&hsr_nb);
> +		return err;
> +	}
>  
> -	return res;
> +	return 0;
>  }
>  
>  static void __exit hsr_exit(void)
> -- 
> 2.44.0
> 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net v2] hsr: Handle failures in module init
  2024-03-15 12:04 [PATCH net v2] hsr: Handle failures in module init Felix Maurer
  2024-03-18  5:23 ` Shigeru Yoshida
@ 2024-03-18  9:36 ` Breno Leitao
  2024-03-19 12:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Breno Leitao @ 2024-03-18  9:36 UTC (permalink / raw)
  To: Felix Maurer; +Cc: netdev, davem, edumazet, kuba, pabeni, dkirjanov

On Fri, Mar 15, 2024 at 01:04:52PM +0100, Felix Maurer wrote:
> 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: f421436a591d ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)")
> Signed-off-by: Felix Maurer <fmaurer@redhat.com>

Reviewed-by: Breno Leitao <leitao@debian.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net v2] hsr: Handle failures in module init
  2024-03-15 12:04 [PATCH net v2] hsr: Handle failures in module init Felix Maurer
  2024-03-18  5:23 ` Shigeru Yoshida
  2024-03-18  9:36 ` Breno Leitao
@ 2024-03-19 12:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-03-19 12:50 UTC (permalink / raw)
  To: Felix Maurer; +Cc: netdev, davem, edumazet, kuba, pabeni, leitao, dkirjanov

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Fri, 15 Mar 2024 13:04:52 +0100 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [net,v2] hsr: Handle failures in module init
    https://git.kernel.org/netdev/net/c/3cf28cd49230

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-19 12:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-15 12:04 [PATCH net v2] hsr: Handle failures in module init Felix Maurer
2024-03-18  5:23 ` Shigeru Yoshida
2024-03-18  9:36 ` Breno Leitao
2024-03-19 12:50 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.