Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp62122rwn; Wed, 7 Sep 2022 20:07:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR4ecCA89Y83KiZg6UjFxRo8vZ92FITOMnqOSl6GPTYvdAxZnB1g6vHjH9OeMovI9rd1SQ6y X-Received: by 2002:a17:902:7b95:b0:172:9dc3:6c12 with SMTP id w21-20020a1709027b9500b001729dc36c12mr7154141pll.94.1662606463608; Wed, 07 Sep 2022 20:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662606463; cv=none; d=google.com; s=arc-20160816; b=A8JXddjZx+LlxjhfLti3kFxNO1lyAOtNaNXgP3OER8oS2HYgskGg0h9/J+XY2M+n0Z /hZfOtf8SW4uL+qGje4ovQw8xzwUspGK1QDshGeoF8PnGZDYEIQOAz+ZzHRIoZhdPoL1 5onQFeignG7yZJDTKcUfViX6SSN3Z7BMyuvyF0cZvDHQ0asFuzDeoKJswhoz0MclWj/G QRsP1ZCkpk3Oq3CnVKh/zjAaAHlRMFL3YB+nAn8XGu3vjFyPfrI85MvEkVM0drHpPKGq mXXe7ufwFKlo619jvkLhO2sSBKDSbTV6ajJX5efsJnOY/J0wFUx1p4fbfX1S+FxPIpDF pp3A== 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=kD/p5sXlCtjhiHAzutoXg/w7HbMIFYO7DvHmZCxjeNQ23Wx4RRp89h19aSJUOqGZeu 3kweTKx0S1nFQHHXT2+tWKVpODCAIM+53d7g3N16NVHUiXoWnJe7Mx0UuGJfL/R+b8NK vpla2x0KPFPEas67LKps1QCa0vRQ0HG/ODUvpANNL6JM8SQG3NQ6l4NPQwxiohgGKlqA 6l2lmX8HVPKn8dIdBHVr6aWtXRiViXa0jUmExUJXUrDAQWk7WJDd4w+CFNn16K2eM4Ml pU1WBuw8EVzA6dimzx67kapvY5CnzlTlLy8KS9/TyEtfXzJ7SHIEDcsU06OuPMNv92eZ okSA== 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 u42-20020a056a0009aa00b00528c43f44f1si15309702pfg.33.2022.09.07.20.07.31; Wed, 07 Sep 2022 20:07:43 -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 S230001AbiIHDEo (ORCPT + 99 others); Wed, 7 Sep 2022 23:04:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbiIHDEg (ORCPT ); Wed, 7 Sep 2022 23:04:36 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B6C33887; Wed, 7 Sep 2022 20:04:28 -0700 (PDT) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MNP6R70hLzgYv0; Thu, 8 Sep 2022 11:01:51 +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.24; Thu, 8 Sep 2022 11:04:26 +0800 From: Ziyang Xuan To: , , , , , CC: Subject: [PATCH 1/2] can: bcm: registration process optimization in bcm_module_init() Date: Thu, 8 Sep 2022 11:04:19 +0800 Message-ID: <823cff0ebec33fa9389eeaf8b8ded3217c32cb38.1662606045.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_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