staging: rtl8192u: fix rmmod warn when device is renamed
This driver creates 4 debug files under [devname] folder. The devname could be wlan0 initially, however it could be renamed later to e.g. enx00e04c00000. This will cause problem during debug file teardown since it uses netdev->name, which is no longer wlan0. To solve this problem, add a notifier to handle device renaming. Also note that we cannot simply do debugfs_lookup to find out old dentry since by the time the notifier is called, netdev->name is already changed to new name. Reported-by: Zheyu Ma <zheyuma97@gmail.com> Tested-by: Zheyu Ma <zheyuma97@gmail.com> Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Tong Zhang <ztong0001@gmail.com> Link: https://lore.kernel.org/r/20220730033335.74153-5-ztong0001@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Родитель
c5682c05b2
Коммит
7b84ab85b1
|
@ -1122,6 +1122,7 @@ void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
|
|||
|
||||
void rtl8192_debugfs_init_one(struct net_device *dev);
|
||||
void rtl8192_debugfs_exit_one(struct net_device *dev);
|
||||
void rtl8192_debugfs_rename_one(struct net_device *dev);
|
||||
void rtl8192_debugfs_init(void);
|
||||
void rtl8192_debugfs_exit(void);
|
||||
|
||||
|
|
|
@ -4606,6 +4606,30 @@ static void rtl8192_usb_disconnect(struct usb_interface *intf)
|
|||
RT_TRACE(COMP_DOWN, "wlan driver removed\n");
|
||||
}
|
||||
|
||||
static int rtl8192_usb_netdev_event(struct notifier_block *nb, unsigned long event,
|
||||
void *data)
|
||||
{
|
||||
struct net_device *netdev = netdev_notifier_info_to_dev(data);
|
||||
|
||||
if (netdev->netdev_ops != &rtl8192_netdev_ops)
|
||||
goto out;
|
||||
|
||||
switch (event) {
|
||||
case NETDEV_CHANGENAME:
|
||||
rtl8192_debugfs_rename_one(netdev);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
return NOTIFY_DONE;
|
||||
}
|
||||
|
||||
static struct notifier_block rtl8192_usb_netdev_notifier = {
|
||||
.notifier_call = rtl8192_usb_netdev_event,
|
||||
};
|
||||
|
||||
static int __init rtl8192_usb_module_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
@ -4615,6 +4639,12 @@ static int __init rtl8192_usb_module_init(void)
|
|||
RT_TRACE(COMP_INIT, "Initializing module");
|
||||
RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT);
|
||||
|
||||
ret = register_netdevice_notifier(&rtl8192_usb_netdev_notifier);
|
||||
if (ret) {
|
||||
pr_err("register_netdevice_notifier failed %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
rtl8192_debugfs_init();
|
||||
ret = ieee80211_debug_init();
|
||||
if (ret) {
|
||||
|
@ -4663,6 +4693,7 @@ debug_exit:
|
|||
ieee80211_debug_exit();
|
||||
debugfs_exit:
|
||||
rtl8192_debugfs_exit();
|
||||
unregister_netdevice_notifier(&rtl8192_usb_netdev_notifier);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -4675,6 +4706,7 @@ static void __exit rtl8192_usb_module_exit(void)
|
|||
ieee80211_crypto_deinit();
|
||||
ieee80211_debug_exit();
|
||||
rtl8192_debugfs_exit();
|
||||
unregister_netdevice_notifier(&rtl8192_usb_netdev_notifier);
|
||||
RT_TRACE(COMP_DOWN, "Exiting");
|
||||
}
|
||||
|
||||
|
|
|
@ -169,6 +169,14 @@ void rtl8192_debugfs_exit_one(struct net_device *dev)
|
|||
debugfs_remove_recursive(priv->debugfs_dir);
|
||||
}
|
||||
|
||||
void rtl8192_debugfs_rename_one(struct net_device *dev)
|
||||
{
|
||||
struct r8192_priv *priv = ieee80211_priv(dev);
|
||||
struct dentry *parent_dir = debugfs_lookup(KBUILD_MODNAME, NULL);
|
||||
|
||||
debugfs_rename(parent_dir, priv->debugfs_dir, parent_dir, dev->name);
|
||||
}
|
||||
|
||||
void rtl8192_debugfs_init(void)
|
||||
{
|
||||
debugfs_create_dir(KBUILD_MODNAME, NULL);
|
||||
|
|
Загрузка…
Ссылка в новой задаче