From: Breno Leitao <leitao@debian.org>
To: Felix Maurer <fmaurer@redhat.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com
Subject: Re: [PATCH net] hsr: Handle failures in module init
Date: Thu, 14 Mar 2024 05:59:35 -0700 [thread overview]
Message-ID: <ZfL0t5v3szkhEhiN@gmail.com> (raw)
In-Reply-To: <0b718dd6cc28d09fd2478d8debdfc0a6755a8895.1710410183.git.fmaurer@redhat.com>
On Thu, Mar 14, 2024 at 11:10:52AM +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.
>
> Signed-off-by: Felix Maurer <fmaurer@redhat.com>
> ---
> net/hsr/hsr_main.c | 18 ++++++++++++++----
> 1 file changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/net/hsr/hsr_main.c b/net/hsr/hsr_main.c
> index cb83c8feb746..1c4a5b678688 100644
> --- a/net/hsr/hsr_main.c
> +++ b/net/hsr/hsr_main.c
> @@ -148,14 +148,24 @@ 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)
> + goto out;
Can't you just 'return err' here? And avoid the `out` label below?
> +
> + err = hsr_netlink_init();
> + if (err)
> + goto cleanup;
Same here, you can do something like the following and remove the
all the labels below, making the function a bit clearer.
if (err) {
unregister_netdevice_notifier(&hsr_nb);
return err;
}
next prev parent reply other threads:[~2024-03-14 12:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-14 10:10 [PATCH net] hsr: Handle failures in module init Felix Maurer
2024-03-14 10:50 ` Denis Kirjanov
2024-03-14 12:59 ` Breno Leitao [this message]
2024-03-14 15:56 ` Felix Maurer
2024-03-18 13:01 ` Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZfL0t5v3szkhEhiN@gmail.com \
--to=leitao@debian.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fmaurer@redhat.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).