Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp209353rwn; Wed, 14 Sep 2022 19:11:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR5toJqFBXMz3FTMEUpq25XZ/TxMTVG5i2deXWU9XxVp2+I/m9zCMohh0A/aI9F2YhYboCkg X-Received: by 2002:a05:6402:254b:b0:451:2b1d:d82c with SMTP id l11-20020a056402254b00b004512b1dd82cmr22844550edb.343.1663207878546; Wed, 14 Sep 2022 19:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663207878; cv=none; d=google.com; s=arc-20160816; b=nMOK15CbDcAcpmbxD/ceaj+29VwHjujwycPGwDWsOHCPRWpMTKMnsIutpMQr1J6asI V1NtOF9/Q8v2NBnoVRFneuxEDICqB/SkfUDPKm7b3I4veavRhMAZmSfw1nBQ6zg3jy4R VJ4DtOKrUwhGzylClr8tQ/Yc/jFlQoXtwoDVp62NB4ZkUAwTnC3c8s1x35kPTaumubkn 7bUq6mvhM/SjV9K8xlYhbazK8g3ObZbSjgdvZOIesT2Cmx6BwRyh43tnoeYtikSqP/qA aa+TPX06tD9ckmMKidpm90NjZaQsqr4+Pu+7QGEOpgV+jybAKbfgeHv6nZRCFOpae0RM KMXw== 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=aKdGvFBm8pSgXzIZDy/EHKiNFe5LCELAX2WU7iAlZ/8=; b=oOdxw3qHG25o+R8ygJLsWFukW3qrSH/Xp32DY+c2Nq+tCB0jSuS+spg3Z0QRisiORS Sm/x++uSh3zFaZk1+3Q1Mj4FRDXO42CyNB16Tmr1iwG3lz2gOLdr6dorWkC2mwTtLzLv V0ZxbnimbpM3tPPOOlIrm70QX34Syww7yHLLjw5GKO6VDHbz40D8D2wy1nxQxlwxhbdA QcKErACltP7zfDB1LRAiGujNCKJZ7RANOXOEtiWHOCvzselhRNmsNECCE40NzKVpAH+z VyZ1BoK2sy3GF7iol0UGANp7T9AixwhRyvzifS/qFKaHzLBFisO+u0Is7qU/psramErH 4eEg== 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 cw10-20020a170906c78a00b007416895306fsi11307350ejb.645.2022.09.14.19.10.51; Wed, 14 Sep 2022 19:11:18 -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 S230023AbiIOB4G (ORCPT + 99 others); Wed, 14 Sep 2022 21:56:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbiIOB4E (ORCPT ); Wed, 14 Sep 2022 21:56:04 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AF228E4F2; Wed, 14 Sep 2022 18:56:03 -0700 (PDT) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MSgDg2wbdz14QZp; Thu, 15 Sep 2022 09:52:03 +0800 (CST) Received: from localhost.localdomain (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.31; Thu, 15 Sep 2022 09:56:01 +0800 From: Ziyang Xuan To: , , , , , CC: Subject: [PATCH v2 1/2] can: bcm: registration process optimization in bcm_module_init() Date: Thu, 15 Sep 2022 09:55:55 +0800 Message-ID: <823cff0ebec33fa9389eeaf8b8ded3217c32cb38.1663206163.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: dggems704-chm.china.huawei.com (10.3.19.181) 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_netdevice_notifier() and register_pernet_subsys() are both after can_proto_register(). It can create CAN_BCM socket and process socket once can_proto_register() successfully, so it is possible missing notifier event or proc node creation because notifier or bcm proc directory is not registered or created yet. Although this is a low probability scenario, it is not impossible. Move register_pernet_subsys() and register_netdevice_notifier() to the front of can_proto_register(). In addition, register_pernet_subsys() and register_netdevice_notifier() may fail, check their results are necessary. Signed-off-by: Ziyang Xuan --- net/can/bcm.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/net/can/bcm.c b/net/can/bcm.c index e60161bec850..e2783156bfd1 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c @@ -1744,15 +1744,27 @@ static int __init bcm_module_init(void) pr_info("can: broadcast manager protocol\n"); + err = register_pernet_subsys(&canbcm_pernet_ops); + if (err) + return err; + + err = register_netdevice_notifier(&canbcm_notifier); + if (err) + goto register_notifier_failed; + err = can_proto_register(&bcm_can_proto); if (err < 0) { printk(KERN_ERR "can: registration of bcm protocol failed\n"); - return err; + goto register_proto_failed; } - register_pernet_subsys(&canbcm_pernet_ops); - register_netdevice_notifier(&canbcm_notifier); return 0; + +register_proto_failed: + unregister_netdevice_notifier(&canbcm_notifier); +register_notifier_failed: + unregister_pernet_subsys(&canbcm_pernet_ops); + return err; } static void __exit bcm_module_exit(void) -- 2.25.1