netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Minhong He <heminhong@kylinos.cn>
To: courmisch@gmail.com, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	remi.denis-courmont@nokia.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Minhong He <heminhong@kylinos.cn>
Subject: [PATCH net v2] phonet: check register_netdevice_notifier() error in phonet_device_init()
Date: Thu, 16 Jul 2026 18:15:04 +0800	[thread overview]
Message-ID: <20260716101504.158387-1-heminhong@kylinos.cn> (raw)

phonet_device_init() registers a netdevice notifier before calling
phonet_netlink_register(), but does not check whether notifier
registration succeeded. On failure, netlink setup still proceeds and
init may return success without the notifier in place.

Check the notifier registration error and unwind only the resources
that were already registered (proc entry and pernet), without calling
unregister_netdevice_notifier() for a notifier that was never
registered.

Fixes: f8ff60283de2 ("Phonet: network device and address handling")
Signed-off-by: Minhong He <heminhong@kylinos.cn>
---
v2:
- On notifier registration failure, unwind only proc/pernet; do not call
  phonet_device_exit() / unregister_netdevice_notifier() for a notifier
  that was never registered.
v1: https://lore.kernel.org/netdev/20260713075212.431455-1-heminhong@kylinos.cn/

 net/phonet/pn_dev.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index ad44831d6745..e6c31cfdad9a 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -356,7 +356,12 @@ int __init phonet_device_init(void)
 
 	proc_create_net("pnresource", 0, init_net.proc_net, &pn_res_seq_ops,
 			sizeof(struct seq_net_private));
-	register_netdevice_notifier(&phonet_device_notifier);
+	err = register_netdevice_notifier(&phonet_device_notifier);
+	if (err) {
+		remove_proc_entry("pnresource", init_net.proc_net);
+		unregister_pernet_subsys(&phonet_net_ops);
+		return err;
+	}
 	err = phonet_netlink_register();
 	if (err)
 		phonet_device_exit();
-- 
2.25.1


             reply	other threads:[~2026-07-16 10:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16 10:15 Minhong He [this message]
2026-07-16 13:40 ` [PATCH net v2] phonet: check register_netdevice_notifier() error in phonet_device_init() Andrew Lunn

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=20260716101504.158387-1-heminhong@kylinos.cn \
    --to=heminhong@kylinos.cn \
    --cc=courmisch@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=remi.denis-courmont@nokia.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).