Skip to content

Commit

Permalink
staging: rtl8192u: rework init and exit function
Browse files Browse the repository at this point in the history
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]

Reviewed-by: Dan Carpenter <[email protected]>
Signed-off-by: Tong Zhang <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
lzto authored and gregkh committed Feb 25, 2022
1 parent 907f6fa commit 57078a3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 33 additions & 12 deletions drivers/staging/rtl8192u/r8192U_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down

0 comments on commit 57078a3

Please sign in to comment.