From nobody Sat Jul 25 00:58:58 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23FF73CB566; Tue, 21 Jul 2026 09:41:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784626878; cv=none; b=bmGmuJUUXcB7zbLS8MqAwNUUTGxU3mYGEdejkp92wi31c+QRXE4O2S+zQVfB5PLubd/EhkiYU2w16QDcFUPi6K7WUJ1Hw0R+4xYeK0vBH7hvo95gquHnwAAqhXu1T0DmxAugeNvxPRXtw1z+bTQokVf0TpQGA6esp0GReaYhe7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784626878; c=relaxed/simple; bh=Z9zUjdQmnVnh6F+y5ZQ/fjEB3Fquth4/iGiJY6e5j+E=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=RqrodJ83xIOQtU3Q01pS6UHpObtBTlcdF3YDrmKhd3hVog5ojydemmLieIQ13mFQHqE0gSoNN8d/g4BMrPSfIliXEXhlzzh2kzF9L2WgD9t4anjBxhJSGtP6yo5LkgyFWTx/be/tDxHcLxfnOTghBKprpU4KrmRsbWKeXdqtPoA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 4ca1a2aa84e811f1aa26b74ffac11d73-20260721 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:06517924-c0d4-48a2-96c4-68c4294d786c,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:e7bac3a,CLOUDID:db488cc252f9d2132e041d5d66a6770a,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:102|136|850|865|898,TC:nil,Content:0|15| 50,EDM:-3,IP:nil,URL:99|1,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OS I:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULS X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 4ca1a2aa84e811f1aa26b74ffac11d73-20260721 X-User: heminhong@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1472024747; Tue, 21 Jul 2026 17:41:07 +0800 From: Minhong He 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 Subject: [PATCH net v4] phonet: check register_netdevice_notifier() error in phonet_device_init() Date: Tue, 21 Jul 2026 17:39:56 +0800 Message-Id: <20260721093956.162617-1-heminhong@kylinos.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Also, the existing phonet_netlink_register() failure path called phonet_device_exit(), which runs rtnl_unregister_all() even though rtnl_register_many() already unwound any partial registration. Calling the full exit helper on a partial init is not correct. Check each registration error, including proc_create_net(), and unwind only the steps that have succeeded so far, in reverse order. Signed-off-by: Minhong He --- v4: - Check proc_create_net() failure (-ENOMEM). - Unwind in reverse registration order with one label per step (notifier -> proc -> pernet). - Match phonet_device_exit() teardown order to the same sequence. v3: https://lore.kernel.org/netdev/20260720070031.108248-1-heminhong@kylino= s.cn/ - Use goto-based unwind; do not call phonet_device_exit() on phonet_netlink_register() failure. - Drop Fixes tag (theoretical init failure path). v2: https://lore.kernel.org/netdev/20260716101504.158387-1-heminhong@kylino= s.cn/ v1: https://lore.kernel.org/netdev/20260713075212.431455-1-heminhong@kylino= s.cn/ net/phonet/pn_dev.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c index ad44831d6745..1272d49cd038 100644 --- a/net/phonet/pn_dev.c +++ b/net/phonet/pn_dev.c @@ -350,16 +350,34 @@ static struct pernet_operations phonet_net_ops =3D { /* Initialize Phonet devices list */ int __init phonet_device_init(void) { - int err =3D register_pernet_subsys(&phonet_net_ops); + int err; + + err =3D register_pernet_subsys(&phonet_net_ops); if (err) return err; =20 - proc_create_net("pnresource", 0, init_net.proc_net, &pn_res_seq_ops, - sizeof(struct seq_net_private)); - register_netdevice_notifier(&phonet_device_notifier); + if (!proc_create_net("pnresource", 0, init_net.proc_net, + &pn_res_seq_ops, sizeof(struct seq_net_private))) { + err =3D -ENOMEM; + goto err_pernet; + } + + err =3D register_netdevice_notifier(&phonet_device_notifier); + if (err) + goto err_proc; + err =3D phonet_netlink_register(); if (err) - phonet_device_exit(); + goto err_notifier; + + return 0; + +err_notifier: + unregister_netdevice_notifier(&phonet_device_notifier); +err_proc: + remove_proc_entry("pnresource", init_net.proc_net); +err_pernet: + unregister_pernet_subsys(&phonet_net_ops); return err; } =20 @@ -367,8 +385,8 @@ void phonet_device_exit(void) { rtnl_unregister_all(PF_PHONET); unregister_netdevice_notifier(&phonet_device_notifier); - unregister_pernet_subsys(&phonet_net_ops); remove_proc_entry("pnresource", init_net.proc_net); + unregister_pernet_subsys(&phonet_net_ops); } =20 int phonet_route_add(struct net_device *dev, u8 daddr) --=20 2.25.1