Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1266187pxm; Wed, 23 Feb 2022 22:53:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5E3CW3fVLhMeZxlpvRNTaaar4LEiJOKvAsy058SpAgiAKkwwG1p4qKVmtQMSHH3sdH/O0 X-Received: by 2002:a17:906:5950:b0:6b3:65b7:82d3 with SMTP id g16-20020a170906595000b006b365b782d3mr1065403ejr.636.1645685626410; Wed, 23 Feb 2022 22:53:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645685626; cv=none; d=google.com; s=arc-20160816; b=QFlHM1iW+xn8HFwB22rGzknT6eVNtS2LyKLckesjuSETa2MDRWaIjCDztGoNo4o/wE BzBNKY6JLyp/Q4SuB0b+1RYhDpqWh930wohpHA/iUF2VsK8J0ebeJ3n9qc1f8Sk2CaSx 4xoCz9ScX0otXLfDMUdVKNgnAjdHmWT4iDGXwdXRaa4J9quT/6yvJkqvpe8zNqXrUZY6 Znd3Xw25tEw6q+7lJaOH8qMM3m9KtowFv+gq6dzxgiwpZkSQwnyNYc04s0HAflurf2vf UG69/X6+OCQ8NGLFrOrvJelTvbp7xXHqq0MeuKnbwXv1QQIIpPTNGrafdvJ80ID+nT9O jJDg== 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 :dkim-signature; bh=R2Yu6vn105/cZrtKT/D7SUb7oHxyN3TZXt+q1NqTNrw=; b=HxVAhRZjddwwQNjbPTDj53LYnbL9OjSX4bHIub70jSKCb4tPJL0gsDRYd3t3URFvME IO12AyLtkHEqOBEFuWWVfHdSglMXxM4IhhZL5B6QmTShhWC+v9zetIvxiQ9LfKwQHzQ1 GcC9+vSPL1tNpYt4sVjFcsee5ZN4tCQrLiD/acSxIztANYvVuHHgvc6iRCCPWMyQRCo5 aWAbPKwFfpg1nOBPIM+vUUCDhptSrbiHJNoDw/w1wRg02YWLh3iFqcaaFPzZo+pm9eZt BJbt/UcQNhBv5X7BA8iHBfKmlgpZ9RZAuxVUjyv06pCaXxOSPYDNuc0QIpBoOLwTVuBZ VCWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=j5NxbfQv; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p12si1170765ejy.339.2022.02.23.22.53.21; Wed, 23 Feb 2022 22:53:46 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=j5NxbfQv; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231357AbiBXGlm (ORCPT + 99 others); Thu, 24 Feb 2022 01:41:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbiBXGll (ORCPT ); Thu, 24 Feb 2022 01:41:41 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72A4B17E36A for ; Wed, 23 Feb 2022 22:41:12 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id cp23-20020a17090afb9700b001bbfe0fbe94so1203652pjb.3 for ; Wed, 23 Feb 2022 22:41:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R2Yu6vn105/cZrtKT/D7SUb7oHxyN3TZXt+q1NqTNrw=; b=j5NxbfQvGYwJDYwnalaQOZdLuBJtbHYcL+EBMUujpQonlDIizgTV+6WTrh+3VEDKdP m+gjFxZYKHy+6f+mbcJ8b0rULw9JLPGDJMBUmnjUfhSPAz9zzG6F2z/cVx1o3r1EZ713 Z97V9eJS7LG28GvUVvyuTEcIXN6UVhQTGcF3gMYJYlvLzuTbWpf7cN9dB3COw9AoImJU Bz9B6UbfS6C1OVMaUxjz205vOYH23bDUFXA9JLCQLe0B5dtFVoms2ELDlxGA2Xf7oNiv ma4M1PInIbOYH+1ZXRumCBLdyEmAi/wbFEl5H9d8SSlrdUlV38xKlc5GSyb0gJzoMxCX umMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R2Yu6vn105/cZrtKT/D7SUb7oHxyN3TZXt+q1NqTNrw=; b=huKcTWjAFkUGmbYEvmwTsTO331mSFtDEXglJ07hql1YshGxpuPlUk0OeubpyQ7y32Q G9cUkRgijP4r6PX/92RLlBppo3bfYk0VntzJUABjMxjdPsuo3V+2siZXE3ERHhMQ0U33 16nTi90zGfr/hPXuf9EG1FXnk7/e9Tqn75ffC+yhwtqthUsG+19PtQTpaFieS43U8CiZ 2caML9sXKQ98TpK4AH8cPRzXLHE/UOiwY/g8J5Vr++g0lVgoK/Mrh17KOHTtKCuLliXV cpn6iA6hxpII1LVnHQbRKS/oOznYj7Sa+8Xt3ABnmDRIa1enfxTn+W0c7r9rAxLhk6vO WrzQ== X-Gm-Message-State: AOAM533d1VSVAHn3xrO8eM+hZdkCSbfz+pA64sZmt5NsCF8qNdVj1mEd PbMg4U4BWUFTs6fHhCX9vOU= X-Received: by 2002:a17:90a:4042:b0:1bc:c408:e7b4 with SMTP id k2-20020a17090a404200b001bcc408e7b4mr1326828pjg.169.1645684871868; Wed, 23 Feb 2022 22:41:11 -0800 (PST) Received: from tong-desktop.local ([2600:1700:3ec7:421f:47fe:f358:be6:4577]) by smtp.googlemail.com with ESMTPSA id j12sm1729109pfu.79.2022.02.23.22.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 22:41:11 -0800 (PST) From: Tong Zhang To: Greg Kroah-Hartman , Tong Zhang , Kees Cook , Jakub Kicinski , Colin Ian King , Lee Jones , Saurav Girepunje , Jiapeng Chong , Johan Hovold , linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Cc: dan.carpenter@oracle.com Subject: [PATCH v2 3/3] staging: rtl8192u: rework init and exit function Date: Wed, 23 Feb 2022 22:40:31 -0800 Message-Id: <20220224064033.1530924-3-ztong0001@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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 The init and exit functions are not releasing resource properly. An error can be observed when we load/unload/load r8192u_usb module due to this issue. This patch rework init and exit functions to do proper resource release on init error and module unload. The __exit attribute is stripped from some functions since they are now being used by module init functions. [ 493.068012] proc_dir_entry 'net/ieee80211' already registered [ 493.271973] proc_mkdir+0x18/0x20 [ 493.272136] ieee80211_debug_init+0x28/0xde8 [r8192u_usb] [ 493.272404] rtl8192_usb_module_init+0x10/0x161 [r8192u_usb] [ 13.910616] proc_dir_entry 'net/rtl819xU' already registered [ 13.918931] proc_mkdir+0x18/0x20 [ 13.919098] rtl8192_usb_module_init+0x142/0x16d [r8192u_usb] Signed-off-by: Tong Zhang --- .../rtl8192u/ieee80211/ieee80211_crypt.c | 2 +- .../rtl8192u/ieee80211/ieee80211_crypt_ccmp.c | 2 +- .../rtl8192u/ieee80211/ieee80211_crypt_tkip.c | 2 +- .../rtl8192u/ieee80211/ieee80211_crypt_wep.c | 2 +- .../rtl8192u/ieee80211/ieee80211_module.c | 2 +- drivers/staging/rtl8192u/r8192U_core.c | 45 ++++++++++++++----- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c index 01012dddcd73..840db6250b87 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c @@ -214,7 +214,7 @@ int __init ieee80211_crypto_init(void) return ret; } -void __exit ieee80211_crypto_deinit(void) +void ieee80211_crypto_deinit(void) { struct list_head *ptr, *n; diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c index ccff385cf1f8..101c28265e91 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c @@ -415,7 +415,7 @@ int __init ieee80211_crypto_ccmp_init(void) return ieee80211_register_crypto_ops(&ieee80211_crypt_ccmp); } -void __exit ieee80211_crypto_ccmp_exit(void) +void ieee80211_crypto_ccmp_exit(void) { ieee80211_unregister_crypto_ops(&ieee80211_crypt_ccmp); } diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c index e8fa1d385f24..689d8843f538 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c @@ -712,7 +712,7 @@ int __init ieee80211_crypto_tkip_init(void) return ieee80211_register_crypto_ops(&ieee80211_crypt_tkip); } -void __exit ieee80211_crypto_tkip_exit(void) +void ieee80211_crypto_tkip_exit(void) { ieee80211_unregister_crypto_ops(&ieee80211_crypt_tkip); } diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c index a41b6510481b..8a51ea1dd6e5 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c @@ -240,7 +240,7 @@ int __init ieee80211_crypto_wep_init(void) return ieee80211_register_crypto_ops(&ieee80211_crypt_wep); } -void __exit ieee80211_crypto_wep_exit(void) +void ieee80211_crypto_wep_exit(void) { ieee80211_unregister_crypto_ops(&ieee80211_crypt_wep); } diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c index c52540b734fd..b94fe9b449b6 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c @@ -276,7 +276,7 @@ int __init ieee80211_debug_init(void) return 0; } -void __exit ieee80211_debug_exit(void) +void ieee80211_debug_exit(void) { if (ieee80211_proc) { remove_proc_entry("debug_level", ieee80211_proc); diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index 364e1ca94f70..ce807c9d4219 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -4783,49 +4783,70 @@ static int __init rtl8192_usb_module_init(void) { int ret; -#ifdef CONFIG_IEEE80211_DEBUG + pr_info("\nLinux kernel driver for RTL8192 based WLAN cards\n"); + pr_info("Copyright (c) 2007-2008, Realsil Wlan\n"); + RT_TRACE(COMP_INIT, "Initializing module"); + RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT); + ret = ieee80211_debug_init(); if (ret) { pr_err("ieee80211_debug_init() failed %d\n", ret); return ret; } -#endif + ret = ieee80211_crypto_init(); if (ret) { pr_err("ieee80211_crypto_init() failed %d\n", ret); - return ret; + goto debug_exit; } ret = ieee80211_crypto_tkip_init(); if (ret) { pr_err("ieee80211_crypto_tkip_init() failed %d\n", ret); - return ret; + goto crypto_exit; } ret = ieee80211_crypto_ccmp_init(); if (ret) { pr_err("ieee80211_crypto_ccmp_init() failed %d\n", ret); - return ret; + goto crypto_tkip_exit; } ret = ieee80211_crypto_wep_init(); if (ret) { pr_err("ieee80211_crypto_wep_init() failed %d\n", ret); - return ret; + goto crypto_ccmp_exit; } - pr_info("\nLinux kernel driver for RTL8192 based WLAN cards\n"); - pr_info("Copyright (c) 2007-2008, Realsil Wlan\n"); - RT_TRACE(COMP_INIT, "Initializing module"); - RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT); rtl8192_proc_module_init(); - return usb_register(&rtl8192_usb_driver); + ret = usb_register(&rtl8192_usb_driver); + if (ret) + goto rtl8192_proc_module_exit; + return ret; + +rtl8192_proc_module_exit: + remove_proc_entry(RTL819XU_MODULE_NAME, init_net.proc_net); + ieee80211_crypto_wep_exit(); +crypto_ccmp_exit: + ieee80211_crypto_ccmp_exit(); +crypto_tkip_exit: + ieee80211_crypto_tkip_exit(); +crypto_exit: + ieee80211_crypto_deinit(); +debug_exit: + ieee80211_debug_exit(); + return ret; } static void __exit rtl8192_usb_module_exit(void) { usb_deregister(&rtl8192_usb_driver); - + remove_proc_entry(RTL819XU_MODULE_NAME, init_net.proc_net); + ieee80211_crypto_wep_exit(); + ieee80211_crypto_ccmp_exit(); + ieee80211_crypto_tkip_exit(); + ieee80211_crypto_deinit(); + ieee80211_debug_exit(); RT_TRACE(COMP_DOWN, "Exiting"); } -- 2.25.1