netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
	kernel@pengutronix.de,
	Ziyang Xuan <william.xuanziyang@huawei.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH net-next 14/23] can: raw: process optimization in raw_init()
Date: Thu, 15 Sep 2022 10:20:04 +0200	[thread overview]
Message-ID: <20220915082013.369072-15-mkl@pengutronix.de> (raw)
In-Reply-To: <20220915082013.369072-1-mkl@pengutronix.de>

From: Ziyang Xuan <william.xuanziyang@huawei.com>

Now, register notifier after register proto successfully. It can create
raw socket and set socket options once register proto successfully, so it
is possible missing notifier event before register notifier successfully
although this is a low probability scenario.

Move notifier registration to the front of proto registration like done
in j1939. In addition, register_netdevice_notifier() may fail, check its
result is necessary.

Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
Link: https://lore.kernel.org/all/7af9401f0d2d9fed36c1667b5ac9b8df8f8b87ee.1661584485.git.william.xuanziyang@huawei.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/raw.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/net/can/raw.c b/net/can/raw.c
index d1bd9cc51ebe..9ae7c4206b9a 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -942,12 +942,20 @@ static __init int raw_module_init(void)
 
 	pr_info("can: raw protocol\n");
 
+	err = register_netdevice_notifier(&canraw_notifier);
+	if (err)
+		return err;
+
 	err = can_proto_register(&raw_can_proto);
-	if (err < 0)
+	if (err < 0) {
 		pr_err("can: registration of raw protocol failed\n");
-	else
-		register_netdevice_notifier(&canraw_notifier);
+		goto register_proto_failed;
+	}
 
+	return 0;
+
+register_proto_failed:
+	unregister_netdevice_notifier(&canraw_notifier);
 	return err;
 }
 
-- 
2.35.1



  parent reply	other threads:[~2022-09-15  8:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15  8:19 [PATCH net-next 0/23] pull-request: can-next 2022-09-15 Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 01/23] can: rx-offload: can_rx_offload_init_queue(): fix typo Marc Kleine-Budde
2022-09-17 19:20   ` patchwork-bot+netdevbpf
2022-09-15  8:19 ` [PATCH net-next 02/23] can: flexcan: fix typo: FLEXCAN_QUIRK_SUPPPORT_* -> FLEXCAN_QUIRK_SUPPORT_* Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 03/23] can: rcar_canfd: Use dev_err_probe() to simplify code and better handle -EPROBE_DEFER Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 04/23] can: kvaser_usb: kvaser_usb_hydra: Use kzalloc for allocating only one element Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 05/23] dt-bindings: can: nxp,sja1000: Document RZ/N1 power-domains support Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 06/23] can: sja1000: Add support for RZ/N1 SJA1000 CAN Controller Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 07/23] can: sja1000: remove redundant variable ret Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 08/23] can: kvaser_pciefd: " Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 09/23] can: gs_usb: use common spelling of GS_USB in macros Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 10/23] can: gs_usb: add RX and TX hardware timestamp support Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 11/23] can: etas_es58x: Replace zero-length array with DECLARE_FLEX_ARRAY() helper Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 12/23] dt-bindings: net: can: nxp,sja1000: drop ref from reg-io-width Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 13/23] docs: networking: device drivers: flexcan: fix invalid email Marc Kleine-Budde
2022-09-15  8:20 ` Marc Kleine-Budde [this message]
2022-09-15  8:20 ` [PATCH net-next 15/23] can: raw: use guard clause to optimize nesting in raw_rcv() Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 16/23] can: flexcan: Switch to use dev_err_probe() helper Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 17/23] can: skb: unify skb CAN frame identification helpers Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 18/23] can: skb: add skb CAN frame data length helpers Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 19/23] can: set CANFD_FDF flag in all CAN FD frame structures Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 20/23] can: canxl: introduce CAN XL data structure Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 21/23] can: canxl: update CAN infrastructure for CAN XL frames Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 22/23] can: dev: add CAN XL support to virtual CAN Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 23/23] can: raw: add CAN XL support Marc Kleine-Budde

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=20220915082013.369072-15-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=davem@davemloft.net \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=william.xuanziyang@huawei.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).