From 389126493f774fbd2a0533053128ec44d6816269 Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Wed, 24 Oct 2018 15:01:40 -0700 Subject: [PATCH] qcacld-3.0: Refactor WE_SET_NSS processing Currently the HDD function with the highest cyclomatic complexity is __iw_setint_getnone(). The handing of WE_SET_NSS has a complexity greater than 1, so refactor that logic into a separate function to help reduce the complexity of __iw_setint_getnone(). As part of the refactoring relocate the mac_handle NULL check to hdd_update_nss() since that is where it is actually used. Change-Id: I6fef7680b8013547cb2b8eb649e207e3026144ff CRs-Fixed: 2338567 --- core/hdd/src/wlan_hdd_cfg.c | 5 +++++ core/hdd/src/wlan_hdd_wext.c | 33 +++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/core/hdd/src/wlan_hdd_cfg.c b/core/hdd/src/wlan_hdd_cfg.c index 33da36d2f092..062a6d4a4ddf 100644 --- a/core/hdd/src/wlan_hdd_cfg.c +++ b/core/hdd/src/wlan_hdd_cfg.c @@ -4723,6 +4723,11 @@ QDF_STATUS hdd_update_nss(struct hdd_adapter *adapter, uint8_t nss) } mac_handle = hdd_ctx->mac_handle; + if (!mac_handle) { + hdd_err("NULL MAC handle"); + return QDF_STATUS_E_INVAL; + } + if (sme_is_any_session_in_connected_state(mac_handle)) { hdd_err("Connected sessions present, Do not change NSS"); return QDF_STATUS_E_INVAL; diff --git a/core/hdd/src/wlan_hdd_wext.c b/core/hdd/src/wlan_hdd_wext.c index 897116dad2e2..22615ed9ee3e 100644 --- a/core/hdd/src/wlan_hdd_wext.c +++ b/core/hdd/src/wlan_hdd_wext.c @@ -4286,6 +4286,24 @@ static int hdd_we_set_tm_level(struct hdd_adapter *adapter, int level) return qdf_status_to_os_return(status); } +static int hdd_we_set_nss(struct hdd_adapter *adapter, int nss) +{ + QDF_STATUS status; + + hdd_debug("NSS %d", nss); + + if ((nss > 2) || (nss <= 0)) { + hdd_err("Invalid NSS: %d", nss); + return -EINVAL; + } + + status = hdd_update_nss(adapter, nss); + if (QDF_IS_STATUS_ERROR(status)) + hdd_err("cfg set failed, value %d status %d", nss, status); + + return qdf_status_to_os_return(status); +} + /** * iw_setint_getnone() - Generic "set integer" private ioctl handler * @dev: device upon which the ioctl was received @@ -4371,21 +4389,8 @@ static int __iw_setint_getnone(struct net_device *dev, break; case WE_SET_NSS: - { - if (!mac_handle) - return -EINVAL; - - hdd_debug("Set NSS = %d", set_value); - if ((set_value > 2) || (set_value <= 0)) { - hdd_err("NSS greater than 2 not supported"); - ret = -EINVAL; - } else { - if (QDF_STATUS_SUCCESS != - hdd_update_nss(adapter, set_value)) - ret = -EINVAL; - } + ret = hdd_we_set_nss(adapter, set_value); break; - } case WE_SET_GTX_HT_MCS: {