From 9453a8fc58b84e2e17da85d0091993bf1a7e20a3 Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Wed, 12 Feb 2020 14:35:04 -0800 Subject: [PATCH] qcacld-3.0: Refactor wireless_handlers NULLing logic Currently there is logic to set the net device wireless_handlers pointer to NULL in both hdd_deinit_station_mode() and hdd_deinit_ap_mode(). This is unnecessary duplication of code, and worse, this is WEXT-specific logic that exists outside the WEXT-specific source files. In order to address these issues refactor the logic into a new function that is exposed by wlan_hdd_wext.h. Change-Id: I0fab5a7f35941f282ddf2e286fb12bfb8c4c7c50 CRs-Fixed: 2620818 --- core/hdd/inc/wlan_hdd_wext.h | 20 +++++++++++++++++++- core/hdd/src/wlan_hdd_hostapd.c | 15 --------------- core/hdd/src/wlan_hdd_main.c | 12 ++---------- core/hdd/src/wlan_hdd_wext.c | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/core/hdd/inc/wlan_hdd_wext.h b/core/hdd/inc/wlan_hdd_wext.h index 708ac2424abc..af65188483bf 100644 --- a/core/hdd/inc/wlan_hdd_wext.h +++ b/core/hdd/inc/wlan_hdd_wext.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2019 The Linux Foundation. All rights reserved. + * Copyright (c) 2012-2020 The Linux Foundation. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the @@ -184,6 +184,19 @@ void hdd_unregister_wext(struct net_device *dev); */ void hdd_register_wext(struct net_device *dev); +/** + * hdd_wext_unregister() - unregister wext context with rtnl lock dependency + * @dev: net device from which wireless extensions are being unregistered + * @rtnl_held: flag which indicates if caller is holding the rtnl_lock + * + * Unregisters wext context for a given net device. This behaves the + * same as hdd_unregister_wext() except it does not take the rtnl_lock + * if the caller is already holding it. + * + * Returns: None + */ +void hdd_wext_unregister(struct net_device *dev, + bool rtnl_held); void hdd_wlan_get_stats(struct hdd_adapter *adapter, uint16_t *length, char *buffer, uint16_t buf_len); void hdd_wlan_list_fw_profile(uint16_t *length, @@ -363,6 +376,11 @@ static inline void hdd_unregister_wext(struct net_device *dev) static inline void hdd_register_wext(struct net_device *dev) { } + +static inline void hdd_wext_unregister(struct net_device *dev, + bool rtnl_locked) +{ +} #endif /* WLAN_WEXT_SUPPORT_ENABLE */ #if defined(WLAN_WEXT_SUPPORT_ENABLE) && defined(HASTINGS_BT_WAR) diff --git a/core/hdd/src/wlan_hdd_hostapd.c b/core/hdd/src/wlan_hdd_hostapd.c index 63864a2b6238..564e8493c0a5 100644 --- a/core/hdd/src/wlan_hdd_hostapd.c +++ b/core/hdd/src/wlan_hdd_hostapd.c @@ -3491,21 +3491,6 @@ void hdd_deinit_ap_mode(struct hdd_context *hdd_ctx, qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0); hdd_softap_deinit_tx_rx(adapter); - /* - * if we are being called during driver unload, - * then the dev has already been invalidated. - * if we are being called at other times, then we can - * detach the wireless device handlers - */ - if (adapter->dev) { - if (rtnl_held) { - adapter->dev->wireless_handlers = NULL; - } else { - rtnl_lock(); - adapter->dev->wireless_handlers = NULL; - rtnl_unlock(); - } - } if (hdd_hostapd_deinit_sap_session(adapter)) hdd_err("Failed:hdd_hostapd_deinit_sap_session"); diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c index 48a10c02a284..ba9ad28cf6dd 100644 --- a/core/hdd/src/wlan_hdd_main.c +++ b/core/hdd/src/wlan_hdd_main.c @@ -4978,16 +4978,6 @@ static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx, { hdd_enter_dev(adapter->dev); - if (adapter->dev) { - if (rtnl_held) - adapter->dev->wireless_handlers = NULL; - else { - rtnl_lock(); - adapter->dev->wireless_handlers = NULL; - rtnl_unlock(); - } - } - if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) { hdd_deinit_tx_rx(adapter); clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags); @@ -5008,6 +4998,8 @@ void hdd_deinit_adapter(struct hdd_context *hdd_ctx, { hdd_enter(); + hdd_wext_unregister(adapter->dev, rtnl_held); + switch (adapter->device_mode) { case QDF_STA_MODE: case QDF_P2P_CLIENT_MODE: diff --git a/core/hdd/src/wlan_hdd_wext.c b/core/hdd/src/wlan_hdd_wext.c index ee365ac23bb9..1af46e7c7dd7 100644 --- a/core/hdd/src/wlan_hdd_wext.c +++ b/core/hdd/src/wlan_hdd_wext.c @@ -11053,3 +11053,17 @@ void hdd_unregister_wext(struct net_device *dev) hdd_exit(); } + +void hdd_wext_unregister(struct net_device *dev, + bool rtnl_held) +{ + if (!dev) + return; + + if (!rtnl_held) + rtnl_lock(); + dev->wireless_handlers = NULL; + if (!rtnl_held) + rtnl_unlock(); +} +