From 1eca4865446edf2e2eec5300f105827815088790 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Tue, 29 Nov 2022 16:41:04 +0000 Subject: [PATCH 1/2] rtl8723ds: fix locking for (un)register rtnl_is_locked() checks whether the lock is currently held by any task, not specifically by _this_ task so it is wrong to use it in the (un)register path. In both of these cases, examining the call stack shows that there is no way for rtnl_lock to be taken by the task running these functions, so remove the checks. Further, (un)register_netdev() have existed since the beginning of Git history so there's no reason for a version check here and we can always call the function that takes the lock itself and should never call the version which expects rtnl_lock to be held. --- os_dep/linux/os_intfs.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/os_dep/linux/os_intfs.c b/os_dep/linux/os_intfs.c index d513934..76510e9 100644 --- a/os_dep/linux/os_intfs.c +++ b/os_dep/linux/os_intfs.c @@ -1402,13 +1402,7 @@ int rtw_os_ndev_register(_adapter *adapter, const char *name) /* Tell the network stack we exist */ - #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)) - if (!rtnl_is_locked()) - ret = (register_netdev(ndev) == 0) ? _SUCCESS : _FAIL; - else - #endif - ret = (register_netdevice(ndev) == 0) ? _SUCCESS : _FAIL; - + ret = (register_netdev(ndev) == 0) ? _SUCCESS : _FAIL; if (ret == _SUCCESS) adapter->registered = 1; else @@ -1447,14 +1441,8 @@ void rtw_os_ndev_unregister(_adapter *adapter) rtw_cfg80211_ndev_res_unregister(adapter); #endif - if ((adapter->DriverState != DRIVER_DISAPPEAR) && netdev) { - #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)) - if (!rtnl_is_locked()) - unregister_netdev(netdev); - else - #endif - unregister_netdevice(netdev); - } + if ((adapter->DriverState != DRIVER_DISAPPEAR) && netdev) + unregister_netdev(netdev); #if defined(CONFIG_IOCTL_CFG80211) && !defined(RTW_SINGLE_WIPHY) rtw_wiphy_unregister(adapter_to_wiphy(adapter)); From dac75d70bc190657b7392739dc09911cd48adfa7 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Tue, 29 Nov 2022 16:45:59 +0000 Subject: [PATCH 2/2] rtl8723ds: simplify locking in rtw_change_ifname() As the comment says, rtnl_lock is acquired by the caller of this function. In fact this is not specific to 2.6.26 and later but has always been the case, so checking lock state is unnecessary and we can just call (un)register_netdevice() knowing that rtnl_lock is held. --- os_dep/osdep_service.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/os_dep/osdep_service.c b/os_dep/osdep_service.c index 178ce14..cb5ff69 100644 --- a/os_dep/osdep_service.c +++ b/os_dep/osdep_service.c @@ -1516,10 +1516,6 @@ RETURN: return; } -/* -* Jeff: this function should be called under ioctl (rtnl_lock is accquired) while -* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26) -*/ int rtw_change_ifname(_adapter *padapter, const char *ifname) { struct net_device *pnetdev; @@ -1539,12 +1535,7 @@ int rtw_change_ifname(_adapter *padapter, const char *ifname) rereg_priv->old_pnetdev = NULL; } -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)) - if (!rtnl_is_locked()) - unregister_netdev(cur_pnetdev); - else -#endif - unregister_netdevice(cur_pnetdev); + unregister_netdevice(cur_pnetdev); rereg_priv->old_pnetdev = cur_pnetdev; @@ -1564,12 +1555,7 @@ int rtw_change_ifname(_adapter *padapter, const char *ifname) dev_addr_set(pnetdev, adapter_mac_addr(padapter)); #endif -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)) - if (!rtnl_is_locked()) - ret = register_netdev(pnetdev); - else -#endif - ret = register_netdevice(pnetdev); + ret = register_netdevice(pnetdev); if (ret != 0) { goto error;