Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1114720rwe; Sat, 27 Aug 2022 00:40:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR4PocmS6QIYCCZJyUVLiZ3a+s2vS7fxByLQwv+vW5uUDTv6NEPw4bDrfPqi4J/zlvKt5AdK X-Received: by 2002:a05:6402:3227:b0:446:e48c:1251 with SMTP id g39-20020a056402322700b00446e48c1251mr9396778eda.186.1661586053604; Sat, 27 Aug 2022 00:40:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661586053; cv=none; d=google.com; s=arc-20160816; b=vfCsZzVpZoPD2t78UF9MwjQi3Ic7Luh6gyF+Cn4Uv+1drbr1yaAavM6w4MjucEZ60b +Qd5veQaBhw+17QqTI6OCRPfaLf9qLc7bDzxr8dWz741NYtuzK2xdQEf/3gkZ1zWCqZG AmIQctPonsv8dJ3026Iq6ol3NJ2Q7uIVns+nj6SjlMBXPhWdQGzq0zSwER8KDCXp3fwV A4Fl2/1HmkAQjYDOn0U1XweVsw6GUqasjzAqpDuLYklLB+TaruN6BvFwMrHRI/tCy8c/ SKK4DAyy3/l1N9TskgYlPjmPZz3chSv5qsuNovFntLBkMAnb2H2FoeAJ8/DhGBXJiQL3 u57g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=a1nDsNKiPxLtGLrLaEyizgc0qDsZfR9diwXlkOiT3qw=; b=UI1c9TBJnD5LqH0x+2G/IQ/xnsXGb5fwkZUrO6SH9q2usUaI9eD3diABROpYMYltJw Xe1T32CG3RVkOzgNY1z4zkZVdC+j1kMEYp9oqg/abi67CEYkqIwPosJR/0jPMu1LYNaR 2mrcJQnNJFv/Pl5IVHZjFXGMmmDw7XjiC6KyWiRCjpQdu8JZC7d4QtRe/3CeGrnnwz9Y DfqFvqUycgvJYYUU9791E+qP3Cr/JDPwI0kdLsryzMOuS13hP0Oik7w4Yh7HjKMv6pzH nFXWw4VtmOPSyLb8gCc/Ocz0sftIzp7C5xJBzx0YTcW4u6z5PKB7vGegTp0nbFSc5aF5 8B5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw8-20020a170906478800b0074156b2af5fsi140527ejc.829.2022.08.27.00.40.27; Sat, 27 Aug 2022 00:40:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345331AbiH0HUh (ORCPT + 99 others); Sat, 27 Aug 2022 03:20:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232922AbiH0HUX (ORCPT ); Sat, 27 Aug 2022 03:20:23 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01C807CA9A; Sat, 27 Aug 2022 00:20:21 -0700 (PDT) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MF7L5435vz1N7H4; Sat, 27 Aug 2022 15:16:45 +0800 (CST) Received: from ubuntu-82.huawei.com (10.175.104.82) by canpemm500006.china.huawei.com (7.192.105.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 27 Aug 2022 15:20:18 +0800 From: Ziyang Xuan To: , , , CC: , , , , Subject: [PATCH net-next 1/2] can: raw: process optimization in raw_init() Date: Sat, 27 Aug 2022 15:20:10 +0800 Message-ID: <7af9401f0d2d9fed36c1667b5ac9b8df8f8b87ee.1661584485.git.william.xuanziyang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500006.china.huawei.com (7.192.105.130) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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.25.1