From patchwork Sun Nov 13 09:37:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuan Can X-Patchwork-Id: 13041495 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA82BC433FE for ; Sun, 13 Nov 2022 09:39:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235259AbiKMJjH (ORCPT ); Sun, 13 Nov 2022 04:39:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229753AbiKMJjF (ORCPT ); Sun, 13 Nov 2022 04:39:05 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7270DCE1B for ; Sun, 13 Nov 2022 01:39:03 -0800 (PST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4N96kg4fRQzJnfZ; Sun, 13 Nov 2022 17:35:55 +0800 (CST) Received: from huawei.com (10.175.112.208) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sun, 13 Nov 2022 17:39:00 +0800 From: Yuan Can To: , , , , , , , CC: Subject: [PATCH 1/2] net: skge: Fix error handling in skge_init_module() Date: Sun, 13 Nov 2022 09:37:18 +0000 Message-ID: <20221113093719.23687-2-yuancan@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221113093719.23687-1-yuancan@huawei.com> References: <20221113093719.23687-1-yuancan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.208] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org A problem about modprobe skge failed is triggered with the following log given: debugfs: Directory 'skge' with parent '/' already present! ------------[ cut here ]------------ notifier callback skge_device_event [skge] already registered WARNING: CPU: 1 PID: 236 at kernel/notifier.c:29 notifier_chain_register+0x168/0x230 ... The reason is that skge_init_module() returns pci_register_driver() directly without checking its return value, if pci_register_driver() failed, it returns without removing skge debugfs and unregister skge_notifier, resulting the debugfs of skge can never be created later and triggers the WARNING of notifier registered. skge_init_module() skge_debug_init() # create debugfs and register skge_notifier pci_register_driver() driver_register() bus_add_driver() priv = kzalloc(...) # OOM happened # return without destroy debugfs and unregister skge_notifier Fix by calling skge_debug_cleanup() when pci_register_driver() returns error. Fixes: 678aa1f6ac86 ("skge: add a debug interface") Signed-off-by: Yuan Can --- drivers/net/ethernet/marvell/skge.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/skge.c b/drivers/net/ethernet/marvell/skge.c index 1b43704baceb..01d141369b3e 100644 --- a/drivers/net/ethernet/marvell/skge.c +++ b/drivers/net/ethernet/marvell/skge.c @@ -3776,7 +3776,7 @@ static __init void skge_debug_init(void) register_netdevice_notifier(&skge_notifier); } -static __exit void skge_debug_cleanup(void) +static void skge_debug_cleanup(void) { if (skge_debug) { unregister_netdevice_notifier(&skge_notifier); @@ -4179,10 +4179,16 @@ static const struct dmi_system_id skge_32bit_dma_boards[] = { static int __init skge_init_module(void) { + int ret; + if (dmi_check_system(skge_32bit_dma_boards)) only_32bit_dma = 1; skge_debug_init(); - return pci_register_driver(&skge_driver); + ret = pci_register_driver(&skge_driver); + if (ret) + skge_debug_cleanup(); + + return ret; } static void __exit skge_cleanup_module(void) From patchwork Sun Nov 13 09:37:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuan Can X-Patchwork-Id: 13041494 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C7A9C4332F for ; Sun, 13 Nov 2022 09:39:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235255AbiKMJjF (ORCPT ); Sun, 13 Nov 2022 04:39:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235233AbiKMJjE (ORCPT ); Sun, 13 Nov 2022 04:39:04 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 733ADCE1F for ; Sun, 13 Nov 2022 01:39:03 -0800 (PST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N96nv27wqzmVt8; Sun, 13 Nov 2022 17:38:43 +0800 (CST) Received: from huawei.com (10.175.112.208) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sun, 13 Nov 2022 17:39:01 +0800 From: Yuan Can To: , , , , , , , CC: Subject: [PATCH 2/2] net: sky2: Fix error handling in sky2_init_module() Date: Sun, 13 Nov 2022 09:37:19 +0000 Message-ID: <20221113093719.23687-3-yuancan@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221113093719.23687-1-yuancan@huawei.com> References: <20221113093719.23687-1-yuancan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.208] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org A problem about modprobe sky2 failed is triggered with the following log given: sky2: driver version 1.30 debugfs: Directory 'sky2' with parent '/' already present! The reason is that sky2_init_module() returns pci_register_driver() directly without checking its return value, if pci_register_driver() failed, it returns without removing sky2 debugfs and unregister sky2_notifier, resulting the debugfs of sky2 can never be created later. sky2_init_module() sky2_debug_init() # create debugfs and register sky2_notifier pci_register_driver() driver_register() bus_add_driver() priv = kzalloc(...) # OOM happened # return without destroy debugfs and unregister sky2_notifier Fix by calling sky2_debug_cleanup() when pci_register_driver() returns error. Fixes: 3cf267539f1f ("sky2: debug interface") Signed-off-by: Yuan Can --- drivers/net/ethernet/marvell/sky2.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c index ab33ba1c3023..6996169b7ddd 100644 --- a/drivers/net/ethernet/marvell/sky2.c +++ b/drivers/net/ethernet/marvell/sky2.c @@ -4536,7 +4536,7 @@ static __init void sky2_debug_init(void) register_netdevice_notifier(&sky2_notifier); } -static __exit void sky2_debug_cleanup(void) +static void sky2_debug_cleanup(void) { if (sky2_debug) { unregister_netdevice_notifier(&sky2_notifier); @@ -5144,10 +5144,16 @@ static struct pci_driver sky2_driver = { static int __init sky2_init_module(void) { + int ret; + pr_info("driver version " DRV_VERSION "\n"); sky2_debug_init(); - return pci_register_driver(&sky2_driver); + ret = pci_register_driver(&sky2_driver); + if (ret) + sky2_debug_cleanup(); + + return ret; } static void __exit sky2_cleanup_module(void)