Browse Source

qcacld-3.0: wma: Remove logs for wmi_handle checks

wmi_validate_handle() function already takes care of logging the
caller function name in case of any error.
Hence there is no need to add the error log again.
Getting rid of these unnecessary logs reduces driver memory footprint.

Change-Id: I9c38d161826ae653156237a5bac17e00c7dde573
CRs-Fixed: 2840878
Srinivas Girigowda 4 years ago
parent
commit
f9cf5f9d87

+ 1 - 3
core/wma/src/wma_dev_if.c

@@ -1295,10 +1295,8 @@ QDF_STATUS wma_vdev_start_resp_handler(struct vdev_mlme_obj *vdev_mlme,
 	    (ratemask_cfg->type < WLAN_MLME_RATEMASK_TYPE_MAX)) {
 		struct wmi_unified *wmi_handle = wma->wmi_handle;
 
-		if (!wmi_handle) {
-			wma_err(FL("wmi_handle is null"));
+		if (wmi_validate_handle(wmi_handle))
 			return QDF_STATUS_E_INVAL;
-		}
 
 		rparams.vdev_id = rsp->vdev_id;
 		status = wma_get_ratemask_type(ratemask_cfg->type,

+ 176 - 130
core/wma/src/wma_features.c

@@ -441,17 +441,20 @@ QDF_STATUS wma_set_tsf_gpio_pin(WMA_HANDLE handle, uint32_t pin)
 	tp_wma_handle wma = (tp_wma_handle)handle;
 	struct pdev_params pdev_param = {0};
 	int32_t ret;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not set gpio");
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	wma_debug("set tsf gpio pin: %d", pin);
 
 	pdev_param.param_id = WMI_PDEV_PARAM_WNTS_CONFIG;
 	pdev_param.param_value = pin;
-	ret = wmi_unified_pdev_param_send(wma->wmi_handle,
+	ret = wmi_unified_pdev_param_send(wmi_handle,
 					 &pdev_param,
 					 WMA_WILDCARD_PDEV_ID);
 	if (ret) {
@@ -688,13 +691,17 @@ QDF_STATUS wma_get_link_speed(WMA_HANDLE handle,
 {
 	tp_wma_handle wma_handle = (tp_wma_handle) handle;
 	wmi_mac_addr peer_macaddr;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, can not issue get link speed cmd");
+	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
-	}
-	if (!wmi_service_enabled(wma_handle->wmi_handle,
-				    wmi_service_estimate_linkspeed)) {
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
+	if (!wmi_service_enabled(wmi_handle,
+				 wmi_service_estimate_linkspeed)) {
 		wma_err("Linkspeed feature bit not enabled Sending value 0 as link speed");
 		wma_send_link_speed(0);
 		return QDF_STATUS_E_FAILURE;
@@ -706,8 +713,7 @@ QDF_STATUS wma_get_link_speed(WMA_HANDLE handle,
 		 QDF_MAC_ADDR_REF(pLinkSpeed->peer_macaddr.bytes),
 		 peer_macaddr.mac_addr31to0,
 		 peer_macaddr.mac_addr47to32);
-	if (wmi_unified_get_link_speed_cmd(wma_handle->wmi_handle,
-					peer_macaddr)) {
+	if (wmi_unified_get_link_speed_cmd(wmi_handle, peer_macaddr)) {
 		return QDF_STATUS_E_FAILURE;
 	}
 
@@ -720,16 +726,19 @@ QDF_STATUS wma_get_isolation(tp_wma_handle wma)
 	wmi_buf_t wmi_buf;
 	uint32_t  len;
 	uint8_t *buf_ptr;
+	struct wmi_unified *wmi_handle;
 
 	wma_debug("get isolation");
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue get isolation");
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wma->wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	len  = sizeof(wmi_coex_get_antenna_isolation_cmd_fixed_param);
-	wmi_buf = wmi_buf_alloc(wma->wmi_handle, len);
+	wmi_buf = wmi_buf_alloc(wmi_handle, len);
 	if (!wmi_buf) {
 		wma_err("wmi_buf_alloc failed");
 		return QDF_STATUS_E_NOMEM;
@@ -743,7 +752,7 @@ QDF_STATUS wma_get_isolation(tp_wma_handle wma)
 	WMITLV_GET_STRUCT_TLVLEN(
 	wmi_coex_get_antenna_isolation_cmd_fixed_param));
 
-	if (wmi_unified_cmd_send(wma->wmi_handle, wmi_buf, len,
+	if (wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
 				 WMI_COEX_GET_ANTENNA_ISOLATION_CMDID)) {
 		wma_err("Failed to get isolation request from fw");
 		wmi_buf_free(wmi_buf);
@@ -770,6 +779,7 @@ QDF_STATUS wma_add_beacon_filter(WMA_HANDLE handle,
 	int ret;
 	struct wma_txrx_node *iface;
 	tp_wma_handle wma = (tp_wma_handle) handle;
+	struct wmi_unified *wmi_handle;
 
 	wmi_add_bcn_filter_cmd_fixed_param *cmd;
 	int len = sizeof(wmi_add_bcn_filter_cmd_fixed_param);
@@ -777,17 +787,19 @@ QDF_STATUS wma_add_beacon_filter(WMA_HANDLE handle,
 	len += WMI_TLV_HDR_SIZE;
 	len += BCN_FLT_MAX_ELEMS_IE_LIST*sizeof(A_UINT32);
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue set beacon filter");
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wma->wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	iface = &wma->interfaces[filter_params->vdev_id];
 	qdf_mem_copy(&iface->beacon_filter, filter_params,
 			sizeof(struct beacon_filter_param));
 	iface->beacon_filter_enabled = true;
 
-	wmi_buf = wmi_buf_alloc(wma->wmi_handle, len);
+	wmi_buf = wmi_buf_alloc(wmi_handle, len);
 	if (!wmi_buf)
 		return QDF_STATUS_E_NOMEM;
 
@@ -812,7 +824,7 @@ QDF_STATUS wma_add_beacon_filter(WMA_HANDLE handle,
 		wma_debug("beacon filter ie map = %u", ie_map[i]);
 	}
 
-	ret = wmi_unified_cmd_send(wma->wmi_handle, wmi_buf, len,
+	ret = wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
 			WMI_ADD_BCN_FILTER_CMDID);
 	if (ret) {
 		wmi_buf_free(wmi_buf);
@@ -837,13 +849,16 @@ QDF_STATUS wma_remove_beacon_filter(WMA_HANDLE handle,
 	wmi_rmv_bcn_filter_cmd_fixed_param *cmd;
 	int len = sizeof(wmi_rmv_bcn_filter_cmd_fixed_param);
 	int ret;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, cannot issue remove beacon filter");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_INVAL;
-	}
 
-	buf = wmi_buf_alloc(wma->wmi_handle, len);
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wma->wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
+	buf = wmi_buf_alloc(wmi_handle, len);
 	if (!buf)
 		return QDF_STATUS_E_NOMEM;
 
@@ -855,7 +870,7 @@ QDF_STATUS wma_remove_beacon_filter(WMA_HANDLE handle,
 			WMITLV_GET_STRUCT_TLVLEN(
 				wmi_rmv_bcn_filter_cmd_fixed_param));
 
-	ret = wmi_unified_cmd_send(wma->wmi_handle, buf, len,
+	ret = wmi_unified_cmd_send(wmi_handle, buf, len,
 			WMI_RMV_BCN_FILTER_CMDID);
 	if (ret) {
 		wmi_buf_free(buf);
@@ -1261,6 +1276,7 @@ QDF_STATUS wma_start_oem_req_cmd(tp_wma_handle wma_handle,
 				 struct oem_data_req *oem_data_req)
 {
 	QDF_STATUS ret;
+	struct wmi_unified *wmi_handle;
 
 	wma_debug("Send OEM Data Request to target");
 
@@ -1269,14 +1285,19 @@ QDF_STATUS wma_start_oem_req_cmd(tp_wma_handle wma_handle,
 		return QDF_STATUS_E_INVAL;
 	}
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA - closed, can not send Oem data request cmd");
+	if (wma_validate_handle(wma_handle)) {
+		qdf_mem_free(oem_data_req->data);
+		return QDF_STATUS_E_INVAL;
+	}
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle)) {
 		qdf_mem_free(oem_data_req->data);
 		return QDF_STATUS_E_INVAL;
 	}
 
 	/* legacy api, for oem data request case */
-	ret = wmi_unified_start_oem_data_cmd(wma_handle->wmi_handle,
+	ret = wmi_unified_start_oem_data_cmd(wmi_handle,
 					     oem_data_req->data_len,
 					     oem_data_req->data);
 
@@ -1292,6 +1313,7 @@ QDF_STATUS wma_start_oem_data_cmd(tp_wma_handle wma_handle,
 				  struct oem_data *oem_data)
 {
 	QDF_STATUS ret;
+	struct wmi_unified *wmi_handle;
 
 	wma_debug("Send OEM Data to target");
 
@@ -1300,14 +1322,15 @@ QDF_STATUS wma_start_oem_data_cmd(tp_wma_handle wma_handle,
 		return QDF_STATUS_E_INVAL;
 	}
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA - closed");
+	if (wma_validate_handle(wma_handle))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	/* common api, for oem data command case */
-	ret = wmi_unified_start_oemv2_data_cmd(wma_handle->wmi_handle,
-					       oem_data);
+	ret = wmi_unified_start_oemv2_data_cmd(wmi_handle, oem_data);
 	if (!QDF_IS_STATUS_SUCCESS(ret))
 		wma_err("call start wmi cmd failed");
 
@@ -2977,11 +3000,14 @@ QDF_STATUS wma_process_add_periodic_tx_ptrn_ind(WMA_HANDLE handle,
 	struct periodic_tx_pattern *params_ptr;
 	uint8_t vdev_id;
 	QDF_STATUS status;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, can not issue fw add pattern cmd");
+	if (wma_validate_handle(wma_handle))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	if (wma_find_vdev_id_by_addr(wma_handle,
 				     pattern->mac_address.bytes,
@@ -3004,7 +3030,7 @@ QDF_STATUS wma_process_add_periodic_tx_ptrn_ind(WMA_HANDLE handle,
 		     params_ptr->ucPtrnSize);
 
 	status = wmi_unified_process_add_periodic_tx_ptrn_cmd(
-				wma_handle->wmi_handle, params_ptr, vdev_id);
+				wmi_handle, params_ptr, vdev_id);
 
 	qdf_mem_free(params_ptr);
 	return status;
@@ -3023,11 +3049,14 @@ QDF_STATUS wma_process_del_periodic_tx_ptrn_ind(WMA_HANDLE handle,
 {
 	tp_wma_handle wma_handle = (tp_wma_handle) handle;
 	uint8_t vdev_id;
+	struct wmi_unified *wmi_handle;
+
+	if (wma_validate_handle(wma_handle))
+		return QDF_STATUS_E_INVAL;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, can not issue Del Pattern cmd");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	if (wma_find_vdev_id_by_addr(
 			wma_handle,
@@ -3039,7 +3068,7 @@ QDF_STATUS wma_process_del_periodic_tx_ptrn_ind(WMA_HANDLE handle,
 	}
 
 	return wmi_unified_process_del_periodic_tx_ptrn_cmd(
-				wma_handle->wmi_handle, vdev_id,
+				wmi_handle, vdev_id,
 				pDelPeriodicTxPtrnParams->ucPtrnId);
 }
 
@@ -3289,17 +3318,20 @@ QDF_STATUS wma_set_led_flashing(tp_wma_handle wma_handle,
 				struct flashing_req_params *flashing)
 {
 	QDF_STATUS status;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, can not issue cmd");
+	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
-	}
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
 	if (!flashing) {
 		wma_err("invalid parameter: flashing");
 		return QDF_STATUS_E_INVAL;
 	}
-	status = wmi_unified_set_led_flashing_cmd(wma_handle->wmi_handle,
-						  flashing);
+	status = wmi_unified_set_led_flashing_cmd(wmi_handle, flashing);
 	return status;
 }
 #endif /* WLAN_FEATURE_GPIO_LED_FLASHING */
@@ -3313,16 +3345,12 @@ int wma_sar_rsp_evt_handler(ol_scn_t handle, uint8_t *event, uint32_t len)
 	wma_debug("handle:%pK event:%pK len:%u", handle, event, len);
 
 	wma_handle = handle;
-	if (!wma_handle) {
-		wma_err("NULL wma_handle");
+	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	wmi_handle = wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("NULL wmi_handle");
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	status = wmi_unified_extract_sar2_result_event(wmi_handle,
 						       event, len);
@@ -3347,11 +3375,15 @@ QDF_STATUS wma_process_ch_avoid_update_req(tp_wma_handle wma_handle,
 					   ch_avoid_update_req)
 {
 	QDF_STATUS status;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle) {
-		wma_err("wma handle is NULL");
+	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_FAILURE;
-	}
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_FAILURE;
+
 	if (!ch_avoid_update_req) {
 		wma_err("ch_avoid_update_req is NULL");
 		return QDF_STATUS_E_FAILURE;
@@ -3359,8 +3391,7 @@ QDF_STATUS wma_process_ch_avoid_update_req(tp_wma_handle wma_handle,
 
 	wma_debug("WMA --> WMI_CHAN_AVOID_UPDATE");
 
-	status = wmi_unified_process_ch_avoid_update_cmd(
-					wma_handle->wmi_handle);
+	status = wmi_unified_process_ch_avoid_update_cmd(wmi_handle);
 	if (QDF_IS_STATUS_ERROR(status))
 		return status;
 
@@ -3441,9 +3472,15 @@ int wma_update_tdls_peer_state(WMA_HANDLE handle,
 	uint8_t chan_id;
 	bool restore_last_peer = false;
 	QDF_STATUS qdf_status;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, can not issue cmd");
+	if (wma_validate_handle(wma_handle)) {
+		ret = -EINVAL;
+		goto end_tdls_peer_state;
+	}
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle)) {
 		ret = -EINVAL;
 		goto end_tdls_peer_state;
 	}
@@ -3551,10 +3588,8 @@ QDF_STATUS wma_process_cfg_action_frm_tb_ppdu(tp_wma_handle wma,
 {
 	struct cfg_action_frm_tb_ppdu_param cmd = {0};
 
-	if (!wma) {
-		wma_err("WMA pointer is NULL");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_FAILURE;
-	}
 
 	cmd.frm_len = cfg_info->frm_len;
 	cmd.cfg = cfg_info->cfg;
@@ -3670,19 +3705,22 @@ QDF_STATUS wma_get_apf_capabilities(tp_wma_handle wma)
 	wmi_buf_t wmi_buf;
 	uint32_t   len;
 	u_int8_t *buf_ptr;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue get APF capab");
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
-	if (!wmi_service_enabled(wma->wmi_handle, wmi_service_apf_offload)) {
+	if (!wmi_service_enabled(wmi_handle, wmi_service_apf_offload)) {
 		wma_err("APF cababilities feature bit not enabled");
 		return QDF_STATUS_E_FAILURE;
 	}
 
 	len = sizeof(*cmd);
-	wmi_buf = wmi_buf_alloc(wma->wmi_handle, len);
+	wmi_buf = wmi_buf_alloc(wmi_handle, len);
 	if (!wmi_buf)
 		return QDF_STATUS_E_NOMEM;
 
@@ -3693,7 +3731,7 @@ QDF_STATUS wma_get_apf_capabilities(tp_wma_handle wma)
 		WMITLV_GET_STRUCT_TLVLEN(
 		wmi_bpf_get_capability_cmd_fixed_param));
 
-	if (wmi_unified_cmd_send(wma->wmi_handle, wmi_buf, len,
+	if (wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
 				 WMI_BPF_GET_CAPABILITY_CMDID)) {
 		wmi_buf_free(wmi_buf);
 		return QDF_STATUS_E_FAILURE;
@@ -3708,13 +3746,16 @@ QDF_STATUS wma_set_apf_instructions(tp_wma_handle wma,
 	wmi_buf_t wmi_buf;
 	uint32_t   len = 0, len_aligned = 0;
 	u_int8_t *buf_ptr;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue set APF capability");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_INVAL;
-	}
 
-	if (!wmi_service_enabled(wma->wmi_handle,
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
+	if (!wmi_service_enabled(wmi_handle,
 		wmi_service_apf_offload)) {
 		wma_err("APF offload feature Disabled");
 		return QDF_STATUS_E_NOSUPPORT;
@@ -3743,7 +3784,7 @@ QDF_STATUS wma_set_apf_instructions(tp_wma_handle wma,
 	}
 
 	len += sizeof(*cmd);
-	wmi_buf = wmi_buf_alloc(wma->wmi_handle, len);
+	wmi_buf = wmi_buf_alloc(wmi_handle, len);
 	if (!wmi_buf)
 		return QDF_STATUS_E_NOMEM;
 
@@ -3769,7 +3810,7 @@ QDF_STATUS wma_set_apf_instructions(tp_wma_handle wma,
 			     apf_set_offload->current_length);
 	}
 
-	if (wmi_unified_cmd_send(wma->wmi_handle, wmi_buf, len,
+	if (wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
 				 WMI_BPF_SET_VDEV_INSTRUCTIONS_CMDID)) {
 		wmi_buf_free(wmi_buf);
 		return QDF_STATUS_E_FAILURE;
@@ -3784,11 +3825,14 @@ QDF_STATUS wma_send_apf_enable_cmd(WMA_HANDLE handle, uint8_t vdev_id,
 {
 	QDF_STATUS status = QDF_STATUS_SUCCESS;
 	tp_wma_handle wma = (tp_wma_handle) handle;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue get APF capab");
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	if (!WMI_SERVICE_IS_ENABLED(wma->wmi_service_bitmap,
 		WMI_SERVICE_BPF_OFFLOAD)) {
@@ -3796,7 +3840,7 @@ QDF_STATUS wma_send_apf_enable_cmd(WMA_HANDLE handle, uint8_t vdev_id,
 		return QDF_STATUS_E_FAILURE;
 	}
 
-	status = wmi_unified_send_apf_enable_cmd(wma->wmi_handle, vdev_id,
+	status = wmi_unified_send_apf_enable_cmd(wmi_handle, vdev_id,
 						 apf_enable);
 	if (QDF_IS_STATUS_ERROR(status)) {
 		wma_err("Failed to send apf enable/disable cmd");
@@ -3818,11 +3862,14 @@ wma_send_apf_write_work_memory_cmd(WMA_HANDLE handle,
 {
 	QDF_STATUS status = QDF_STATUS_SUCCESS;
 	tp_wma_handle wma = (tp_wma_handle) handle;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue write APF mem");
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	if (!WMI_SERVICE_IS_ENABLED(wma->wmi_service_bitmap,
 		WMI_SERVICE_BPF_OFFLOAD)) {
@@ -3830,7 +3877,7 @@ wma_send_apf_write_work_memory_cmd(WMA_HANDLE handle,
 		return QDF_STATUS_E_FAILURE;
 	}
 
-	if (wmi_unified_send_apf_write_work_memory_cmd(wma->wmi_handle,
+	if (wmi_unified_send_apf_write_work_memory_cmd(wmi_handle,
 						       write_params)) {
 		wma_err("Failed to send APF write mem command");
 		return QDF_STATUS_E_FAILURE;
@@ -3852,16 +3899,12 @@ int wma_apf_read_work_memory_event_handler(void *handle, uint8_t *evt_buf,
 	wma_debug("handle:%pK event:%pK len:%u", handle, evt_buf, len);
 
 	wma_handle = handle;
-	if (!wma_handle) {
-		wma_err("NULL wma_handle");
+	if (wma_validate_handle(wma_handle))
 		return -EINVAL;
-	}
 
 	wmi_handle = wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("NULL wmi_handle");
+	if (wmi_validate_handle(wmi_handle))
 		return -EINVAL;
-	}
 
 	if (!pmac)
 		return -EINVAL;
@@ -3889,11 +3932,14 @@ QDF_STATUS wma_send_apf_read_work_memory_cmd(WMA_HANDLE handle,
 {
 	QDF_STATUS status = QDF_STATUS_SUCCESS;
 	tp_wma_handle wma = (tp_wma_handle) handle;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue read APF memory");
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	if (!WMI_SERVICE_IS_ENABLED(wma->wmi_service_bitmap,
 		WMI_SERVICE_BPF_OFFLOAD)) {
@@ -3901,7 +3947,7 @@ QDF_STATUS wma_send_apf_read_work_memory_cmd(WMA_HANDLE handle,
 		return QDF_STATUS_E_FAILURE;
 	}
 
-	if (wmi_unified_send_apf_read_work_memory_cmd(wma->wmi_handle,
+	if (wmi_unified_send_apf_read_work_memory_cmd(wmi_handle,
 						      read_params)) {
 		wma_err("Failed to send APF read memory command");
 		return QDF_STATUS_E_FAILURE;
@@ -4181,13 +4227,16 @@ QDF_STATUS wma_process_fw_test_cmd(WMA_HANDLE handle,
 				   struct set_fwtest_params *wma_fwtest)
 {
 	tp_wma_handle wma_handle = (tp_wma_handle) handle;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, can not issue fw test cmd");
-		return QDF_STATUS_E_FAILURE;
-	}
+	if (wma_validate_handle(wma_handle))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
 
-	if (wmi_unified_fw_test_cmd(wma_handle->wmi_handle,
+	if (wmi_unified_fw_test_cmd(wmi_handle,
 				    (struct set_fwtest_params *)wma_fwtest)) {
 		wma_err("Failed to issue fw test cmd");
 		return QDF_STATUS_E_FAILURE;
@@ -4209,14 +4258,17 @@ QDF_STATUS wma_enable_disable_caevent_ind(tp_wma_handle wma, uint8_t val)
 	wmi_buf_t wmi_buf;
 	uint8_t *buf_ptr;
 	uint32_t len;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue set/clear CA");
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	len = sizeof(*cmd);
-	wmi_buf = wmi_buf_alloc(wma->wmi_handle, len);
+	wmi_buf = wmi_buf_alloc(wmi_handle, len);
 	if (!wmi_buf)
 		return QDF_STATUS_E_NOMEM;
 
@@ -4227,7 +4279,7 @@ QDF_STATUS wma_enable_disable_caevent_ind(tp_wma_handle wma, uint8_t val)
 		WMITLV_GET_STRUCT_TLVLEN(
 				WMI_CHAN_AVOID_RPT_ALLOW_CMD_fixed_param));
 	cmd->rpt_allow = val;
-	if (wmi_unified_cmd_send(wma->wmi_handle, wmi_buf, len,
+	if (wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
 				WMI_CHAN_AVOID_RPT_ALLOW_CMDID)) {
 		wmi_buf_free(wmi_buf);
 		return QDF_STATUS_E_FAILURE;
@@ -4250,16 +4302,12 @@ static int wma_sar_event_handler(void *handle, uint8_t *evt_buf, uint32_t len)
 	wma_info("handle:%pK event:%pK len:%u", handle, evt_buf, len);
 
 	wma_handle = handle;
-	if (!wma_handle) {
-		wma_err("NULL wma_handle");
+	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	wmi_handle = wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("NULL wmi_handle");
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	event = qdf_mem_malloc(sizeof(*event));
 	if (!event)
@@ -4288,16 +4336,12 @@ QDF_STATUS wma_sar_register_event_handlers(WMA_HANDLE handle)
 	tp_wma_handle wma_handle = handle;
 	wmi_unified_t wmi_handle;
 
-	if (!wma_handle) {
-		wma_err("NULL wma_handle");
+	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	wmi_handle = wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("NULL wmi_handle");
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	return wmi_unified_register_event_handler(wmi_handle,
 						  wmi_sar_get_limits_event_id,
@@ -4312,16 +4356,12 @@ QDF_STATUS wma_get_sar_limit(WMA_HANDLE handle,
 	wmi_unified_t wmi_handle;
 	QDF_STATUS status;
 
-	if (!wma_handle) {
-		wma_err("NULL wma_handle");
+	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	wmi_handle = wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("NULL wmi_handle");
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	sar_callback = callback;
 	sar_context = context;
@@ -4340,18 +4380,21 @@ QDF_STATUS wma_set_sar_limit(WMA_HANDLE handle,
 {
 	int ret;
 	tp_wma_handle wma = (tp_wma_handle) handle;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue set sar limit msg");
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	if (!sar_limit_params) {
 		wma_err("set sar limit ptr NULL");
 		return QDF_STATUS_E_INVAL;
 	}
 
-	ret = wmi_unified_send_sar_limit_cmd(wma->wmi_handle,
+	ret = wmi_unified_send_sar_limit_cmd(wmi_handle,
 				sar_limit_params);
 
 	return ret;
@@ -4361,19 +4404,22 @@ QDF_STATUS wma_send_coex_config_cmd(WMA_HANDLE wma_handle,
 				    struct coex_config_params *coex_cfg_params)
 {
 	tp_wma_handle wma = (tp_wma_handle)wma_handle;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue coex config command");
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	if (!coex_cfg_params) {
 		wma_err("coex cfg params ptr NULL");
 		return QDF_STATUS_E_INVAL;
 	}
 
-	return wmi_unified_send_coex_config_cmd(wma->wmi_handle,
-					       coex_cfg_params);
+	return wmi_unified_send_coex_config_cmd(wmi_handle,
+					        coex_cfg_params);
 }
 
 /**

+ 4 - 12
core/wma/src/wma_fips_api.c

@@ -39,16 +39,12 @@ wma_fips_event_handler(void *handle, uint8_t *event, uint32_t len)
 	QDF_STATUS status;
 
 	wma_handle = handle;
-	if (!wma_handle) {
-		wma_err("NULL wma_handle");
+	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	wmi_handle = wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("NULL wmi_handle");
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	status = wmi_extract_fips_event_data(wmi_handle, event, &param);
 
@@ -76,16 +72,12 @@ QDF_STATUS wma_fips_request(WMA_HANDLE handle,
 	wmi_unified_t wmi_handle;
 	QDF_STATUS status;
 
-	if (!wma_handle) {
-		wma_err("NULL wma_handle");
+	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	wmi_handle = wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("NULL wmi_handle");
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	fips_callback = callback;
 	fips_context = context;

+ 1 - 3
core/wma/src/wma_fw_state.c

@@ -31,10 +31,8 @@ QDF_STATUS wma_get_fw_state(tp_wma_handle wma_handle)
 	wmi_buf_t wmi_buf;
 	uint32_t len = sizeof(*cmd);
 
-	if (!wma_handle) {
-		wma_err("WMA is closed, can not issue cmd");
+	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	wmi_buf = wmi_buf_alloc(wma_handle->wmi_handle, len);
 	if (!wmi_buf)

+ 109 - 81
core/wma/src/wma_main.c

@@ -668,6 +668,7 @@ QDF_STATUS wma_form_unit_test_cmd_and_send(uint32_t vdev_id,
 	tp_wma_handle wma_handle = cds_get_context(QDF_MODULE_ID_WMA);
 	uint32_t i;
 	QDF_STATUS status;
+	struct wmi_unified *wmi_handle;
 
 	wma_debug("enter");
 
@@ -680,10 +681,14 @@ QDF_STATUS wma_form_unit_test_cmd_and_send(uint32_t vdev_id,
 		wma_err("arg_count is crossed the boundary");
 		return QDF_STATUS_E_FAILURE;
 	}
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("Invalid WMA/WMI handle");
+
+	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_FAILURE;
-	}
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_FAILURE;
+
 	unit_test_args = qdf_mem_malloc(sizeof(*unit_test_args));
 	if (!unit_test_args)
 		return QDF_STATUS_E_NOMEM;
@@ -694,7 +699,7 @@ QDF_STATUS wma_form_unit_test_cmd_and_send(uint32_t vdev_id,
 	for (i = 0; i < arg_count; i++)
 		unit_test_args->args[i] = arg[i];
 
-	status = wmi_unified_unit_test_cmd(wma_handle->wmi_handle,
+	status = wmi_unified_unit_test_cmd(wmi_handle,
 					   unit_test_args);
 	qdf_mem_free(unit_test_args);
 	wma_debug("exit");
@@ -706,14 +711,20 @@ static void wma_process_send_addba_req(tp_wma_handle wma_handle,
 		struct send_add_ba_req *send_addba)
 {
 	QDF_STATUS status;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("Invalid WMA/WMI handle");
+	if (wma_validate_handle(wma_handle)) {
 		qdf_mem_free(send_addba);
 		return;
 	}
 
-	status = wmi_unified_addba_send_cmd_send(wma_handle->wmi_handle,
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle)) {
+		qdf_mem_free(send_addba);
+		return;
+	}
+
+	status = wmi_unified_addba_send_cmd_send(wmi_handle,
 					   send_addba->mac_addr,
 					   &send_addba->param);
 	if (QDF_STATUS_SUCCESS != status) {
@@ -1440,10 +1451,12 @@ uint32_t wma_critical_events_in_flight(void)
 	t_wma_handle *wma;
 
 	wma = cds_get_context(QDF_MODULE_ID_WMA);
-	if (!wma || !wma->wmi_handle) {
-		wma_err("Invalid wma or wmi handle");
+	if (!wma)
 		return 0;
-	}
+
+	if (wmi_validate_handle(wma->wmi_handle))
+		return 0;
+
 	return wmi_critical_events_in_flight(wma->wmi_handle);
 }
 
@@ -2613,11 +2626,12 @@ void wma_wmi_stop(void)
 	tp_wma_handle wma_handle;
 
 	wma_handle = cds_get_context(QDF_MODULE_ID_WMA);
-	if ((!wma_handle) || (!wma_handle->wmi_handle)) {
-		QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
-			  "wma_handle or wmi_handle is NULL\n");
+	if (!wma_handle)
 		return;
-	}
+
+	if (wmi_validate_handle(wma_handle->wmi_handle))
+		return;
+
 	wmi_stop(wma_handle->wmi_handle);
 }
 
@@ -3993,15 +4007,14 @@ QDF_STATUS wma_start(void)
 	}
 
 	wmi_handle = get_wmi_unified_hdl_from_psoc(wma_handle->psoc);
-	if (!wmi_handle) {
-		wma_err("Invalid wmi handle");
+	if (wmi_validate_handle(wmi_handle)) {
 		qdf_status = QDF_STATUS_E_INVAL;
 		goto end;
 	}
 
 	mac = cds_get_context(QDF_MODULE_ID_PE);
 	if (!mac) {
-		wma_err("Invalid mac context");
+		qdf_status = QDF_STATUS_E_INVAL;
 		goto end;
 	}
 
@@ -4303,6 +4316,7 @@ QDF_STATUS wma_wmi_service_close(void)
 	void *cds_ctx;
 	tp_wma_handle wma_handle;
 	uint8_t i;
+	struct wmi_unified *wmi_handle;
 
 	wma_debug("Enter");
 
@@ -4316,15 +4330,13 @@ QDF_STATUS wma_wmi_service_close(void)
 	if (!wma_handle)
 		return QDF_STATUS_E_INVAL;
 
-	/* validate the wmi handle */
-	if (!wma_handle->wmi_handle) {
-		wma_err("Invalid wmi handle");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
-	/* dettach the wmi serice */
+	/* detach the wmi service */
 	wma_debug("calling wmi_unified_detach");
-	wmi_unified_detach(wma_handle->wmi_handle);
+	wmi_unified_detach(wmi_handle);
 	wma_handle->wmi_handle = NULL;
 
 	for (i = 0; i < wma_handle->max_bssid; i++)
@@ -4354,6 +4366,7 @@ QDF_STATUS wma_wmi_service_close(void)
 QDF_STATUS wma_wmi_work_close(void)
 {
 	tp_wma_handle wma_handle;
+	struct wmi_unified *wmi_handle;
 
 	wma_debug("Enter");
 
@@ -4361,15 +4374,13 @@ QDF_STATUS wma_wmi_work_close(void)
 	if (!wma_handle)
 		return QDF_STATUS_E_INVAL;
 
-	/* validate the wmi handle */
-	if (!wma_handle->wmi_handle) {
-		wma_err("Invalid wmi handle");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	/* remove the wmi work */
 	wma_debug("calling wmi_unified_remove_work");
-	wmi_unified_remove_work(wma_handle->wmi_handle);
+	wmi_unified_remove_work(wmi_handle);
 
 	wma_debug("Exit");
 	return QDF_STATUS_SUCCESS;
@@ -4386,6 +4397,7 @@ QDF_STATUS wma_close(void)
 	tp_wma_handle wma_handle;
 	struct target_psoc_info *tgt_psoc_info;
 	QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
+	struct wmi_unified *wmi_handle;
 
 	wma_debug("Enter");
 
@@ -4393,11 +4405,9 @@ QDF_STATUS wma_close(void)
 	if (!wma_handle)
 		return QDF_STATUS_E_INVAL;
 
-	/* validate the wmi handle */
-	if (!wma_handle->wmi_handle) {
-		wma_err("Invalid wmi handle");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	/* Free DBS list */
 	if (wma_handle->hw_mode.hw_mode_list) {
@@ -4422,7 +4432,7 @@ QDF_STATUS wma_close(void)
 	}
 
 	/* unregister Firmware debug log */
-	qdf_status = dbglog_deinit(wma_handle->wmi_handle);
+	qdf_status = dbglog_deinit(wmi_handle);
 	if (qdf_status != QDF_STATUS_SUCCESS)
 		wma_err("dbglog_deinit failed");
 
@@ -5413,10 +5423,8 @@ static int wma_update_hdd_cfg(tp_wma_handle wma_handle)
 	service_ext_param =
 			target_psoc_get_service_ext_param(tgt_hdl);
 	wmi_handle = get_wmi_unified_hdl_from_psoc(wma_handle->psoc);
-	if (!wmi_handle) {
-		wma_err("wmi handle is NULL");
+	if (wmi_validate_handle(wmi_handle))
 		return -EINVAL;
-	}
 
 	wma_update_mlme_related_tgt_caps(wma_handle->psoc, wmi_handle);
 
@@ -5704,10 +5712,8 @@ int wma_rx_service_ready_event(void *handle, uint8_t *cmd_param_info,
 
 	wma_debug("Enter");
 
-	if (!handle) {
-		wma_err("wma_handle passed is NULL");
+	if (wma_validate_handle(wma_handle))
 		return -EINVAL;
-	}
 
 	tgt_hdl = wlan_psoc_get_tgt_if_handle(wma_handle->psoc);
 	if (!tgt_hdl) {
@@ -5732,10 +5738,8 @@ int wma_rx_service_ready_event(void *handle, uint8_t *cmd_param_info,
 	}
 
 	wmi_handle = get_wmi_unified_hdl_from_psoc(wma_handle->psoc);
-	if (!wmi_handle) {
-		wma_err("wmi handle is NULL");
+	if (wmi_validate_handle(wmi_handle))
 		return -EINVAL;
-	}
 
 	wma_debug("WMA <-- WMI_SERVICE_READY_EVENTID");
 
@@ -7279,18 +7283,21 @@ static QDF_STATUS wma_update_tx_fail_cnt_th(tp_wma_handle wma,
 	u_int8_t vdev_id;
 	u_int32_t tx_fail_disconn_th;
 	int ret = -EIO;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue Tx pkt fail count threshold");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_INVAL;
-	}
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
 	vdev_id = tx_fail_cnt_th->session_id;
 	tx_fail_disconn_th = tx_fail_cnt_th->tx_fail_cnt_threshold;
 	wma_debug("Set TX pkt fail count threshold  vdevId %d count %d",
 			vdev_id, tx_fail_disconn_th);
 
-
-	ret = wma_vdev_set_param(wma->wmi_handle, vdev_id,
+	ret = wma_vdev_set_param(wmi_handle, vdev_id,
 			WMI_VDEV_PARAM_DISCONNECT_TH,
 			tx_fail_disconn_th);
 
@@ -7318,17 +7325,21 @@ static QDF_STATUS wma_update_short_retry_limit(tp_wma_handle wma,
 	uint8_t vdev_id;
 	uint32_t short_retry_limit;
 	int ret;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue short retry limit threshold");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_INVAL;
-	}
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
 	vdev_id = short_retry_limit_th->session_id;
 	short_retry_limit = short_retry_limit_th->short_retry_limit;
 	wma_debug("Set short retry limit threshold  vdevId %d count %d",
 		vdev_id, short_retry_limit);
 
-	ret = wma_vdev_set_param(wma->wmi_handle, vdev_id,
+	ret = wma_vdev_set_param(wmi_handle, vdev_id,
 		WMI_VDEV_PARAM_NON_AGG_SW_RETRY_TH,
 		short_retry_limit);
 
@@ -7355,17 +7366,21 @@ static QDF_STATUS wma_update_long_retry_limit(tp_wma_handle wma,
 	uint8_t vdev_id;
 	uint32_t long_retry_limit;
 	int ret;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue long retry limit threshold");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_INVAL;
-	}
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
 	vdev_id = long_retry_limit_th->session_id;
 	long_retry_limit = long_retry_limit_th->long_retry_limit;
 	wma_debug("Set TX pkt fail count threshold  vdevId %d count %d",
 		vdev_id, long_retry_limit);
 
-	ret  = wma_vdev_set_param(wma->wmi_handle, vdev_id,
+	ret  = wma_vdev_set_param(wmi_handle, vdev_id,
 			WMI_VDEV_PARAM_AGG_SW_RETRY_TH,
 			long_retry_limit);
 
@@ -7396,27 +7411,31 @@ void wma_update_sta_inactivity_timeout(tp_wma_handle wma,
 	uint8_t vdev_id;
 	uint32_t max_unresponsive_time;
 	uint32_t min_inactive_time, max_inactive_time;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue sta_inactivity_timeout");
+	if (wma_validate_handle(wma))
 		return;
-	}
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return;
+
 	vdev_id = sta_inactivity_timer->session_id;
 	max_unresponsive_time = sta_inactivity_timer->sta_inactivity_timeout;
 	max_inactive_time = max_unresponsive_time * TWO_THIRD;
 	min_inactive_time = max_unresponsive_time - max_inactive_time;
 
-	if (wma_vdev_set_param(wma->wmi_handle, vdev_id,
+	if (wma_vdev_set_param(wmi_handle, vdev_id,
 			WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS,
 			min_inactive_time))
 		wma_err("Failed to Set AP MIN IDLE INACTIVE TIME");
 
-	if (wma_vdev_set_param(wma->wmi_handle, vdev_id,
+	if (wma_vdev_set_param(wmi_handle, vdev_id,
 			WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS,
 			max_inactive_time))
 		wma_err("Failed to Set AP MAX IDLE INACTIVE TIME");
 
-	if (wma_vdev_set_param(wma->wmi_handle, vdev_id,
+	if (wma_vdev_set_param(wmi_handle, vdev_id,
 		WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS,
 		max_unresponsive_time))
 		wma_err("Failed to Set MAX UNRESPONSIVE TIME");
@@ -7607,11 +7626,14 @@ static void wma_set_arp_req_stats(WMA_HANDLE handle,
 	struct set_arp_stats *arp_stats;
 	tp_wma_handle wma_handle = (tp_wma_handle) handle;
 	struct wlan_objmgr_vdev *vdev;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, cannot send per roam config");
+	if (wma_validate_handle(wma_handle))
+		return;
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return;
-	}
 
 	if (!wma_is_vdev_valid(req_buf->vdev_id)) {
 		wma_err("vdev id:%d is not active", req_buf->vdev_id);
@@ -7632,8 +7654,7 @@ static void wma_set_arp_req_stats(WMA_HANDLE handle,
 	}
 
 	arp_stats = (struct set_arp_stats *)req_buf;
-	status = wmi_unified_set_arp_stats_req(wma_handle->wmi_handle,
-					       arp_stats);
+	status = wmi_unified_set_arp_stats_req(wmi_handle, arp_stats);
 	if (QDF_IS_STATUS_ERROR(status))
 		wma_err("failed to set arp stats to FW");
 
@@ -7654,19 +7675,22 @@ static void wma_get_arp_req_stats(WMA_HANDLE handle,
 	QDF_STATUS status;
 	struct get_arp_stats *arp_stats;
 	tp_wma_handle wma_handle = (tp_wma_handle) handle;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, cannot send per roam config");
+	if (wma_validate_handle(wma_handle))
 		return;
-	}
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return;
+
 	if (!wma_is_vdev_valid(req_buf->vdev_id)) {
 		wma_err("vdev id:%d is not active", req_buf->vdev_id);
 		return;
 	}
 
 	arp_stats = (struct get_arp_stats *)req_buf;
-	status = wmi_unified_get_arp_stats_req(wma_handle->wmi_handle,
-					       arp_stats);
+	status = wmi_unified_get_arp_stats_req(wmi_handle, arp_stats);
 	if (QDF_IS_STATUS_ERROR(status))
 		wma_err("failed to send get arp stats to FW");
 }
@@ -7683,14 +7707,16 @@ static void wma_set_del_pmkid_cache(WMA_HANDLE handle,
 {
 	QDF_STATUS status;
 	tp_wma_handle wma_handle = (tp_wma_handle) handle;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, cannot send set del pmkid");
+	if (wma_validate_handle(wma_handle))
+		return;
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return;
-	}
 
-	status = wmi_unified_set_del_pmkid_cache(wma_handle->wmi_handle,
-						 pmk_cache);
+	status = wmi_unified_set_del_pmkid_cache(wmi_handle, pmk_cache);
 	if (QDF_IS_STATUS_ERROR(status))
 		wma_err("failed to send set/del pmkid cmd to fw");
 }
@@ -7710,14 +7736,16 @@ void wma_send_invoke_neighbor_report(WMA_HANDLE handle,
 {
 	QDF_STATUS status;
 	tp_wma_handle wma_handle = (tp_wma_handle) handle;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, cannot send invoke neighbor report");
+	if (wma_validate_handle(wma_handle))
+		return;
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return;
-	}
 
-	status = wmi_unified_invoke_neighbor_report_cmd(wma_handle->wmi_handle,
-							params);
+	status = wmi_unified_invoke_neighbor_report_cmd(wmi_handle, params);
 
 	if (status != QDF_STATUS_SUCCESS)
 		wma_err("failed to send invoke neighbor report command");

+ 9 - 5
core/wma/src/wma_power.c

@@ -1087,11 +1087,15 @@ QDF_STATUS wma_process_tx_power_limits(WMA_HANDLE handle,
 	uint32_t txpower_params2g = 0;
 	uint32_t txpower_params5g = 0;
 	struct pdev_params pdevparam;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue tx power limit");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_INVAL;
-	}
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
 	/* Set value and reason code for 2g and 5g power limit */
 
 	SET_PDEV_PARAM_TXPOWER_REASON(txpower_params2g,
@@ -1107,7 +1111,7 @@ QDF_STATUS wma_process_tx_power_limits(WMA_HANDLE handle,
 
 	pdevparam.param_id = WMI_PDEV_PARAM_TXPOWER_LIMIT2G;
 	pdevparam.param_value = txpower_params2g;
-	ret = wmi_unified_pdev_param_send(wma->wmi_handle,
+	ret = wmi_unified_pdev_param_send(wmi_handle,
 					 &pdevparam,
 					 WMA_WILDCARD_PDEV_ID);
 	if (ret) {
@@ -1116,7 +1120,7 @@ QDF_STATUS wma_process_tx_power_limits(WMA_HANDLE handle,
 	}
 	pdevparam.param_id = WMI_PDEV_PARAM_TXPOWER_LIMIT5G;
 	pdevparam.param_value = txpower_params5g;
-	ret = wmi_unified_pdev_param_send(wma->wmi_handle,
+	ret = wmi_unified_pdev_param_send(wmi_handle,
 					 &pdevparam,
 					 WMA_WILDCARD_PDEV_ID);
 	if (ret) {

+ 145 - 94
core/wma/src/wma_scan_roam.c

@@ -584,14 +584,16 @@ wma_send_roam_preauth_status(tp_wma_handle wma_handle,
 			     struct wmi_roam_auth_status_params *params)
 {
 	QDF_STATUS status;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, cannot send roam prauth status");
+	if (wma_validate_handle(wma_handle))
+		return;
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return;
-	}
 
-	status = wmi_unified_send_roam_preauth_status(wma_handle->wmi_handle,
-						      params);
+	status = wmi_unified_send_roam_preauth_status(wmi_handle, params);
 	if (QDF_IS_STATUS_ERROR(status))
 		wma_err("failed to send disconnect roam preauth status");
 }
@@ -613,18 +615,21 @@ void wma_process_roam_invoke(WMA_HANDLE handle,
 {
 	tp_wma_handle wma_handle = (tp_wma_handle) handle;
 	uint32_t ch_hz;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, can not send roam invoke");
+	if (wma_validate_handle(wma_handle))
+		goto free_frame_buf;
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		goto free_frame_buf;
-	}
 
 	if (!wma_is_vdev_valid(roaminvoke->vdev_id)) {
 		wma_err("Invalid vdev id:%d", roaminvoke->vdev_id);
 		goto free_frame_buf;
 	}
 	ch_hz = roaminvoke->ch_freq;
-	wmi_unified_roam_invoke_cmd(wma_handle->wmi_handle,
+	wmi_unified_roam_invoke_cmd(wmi_handle,
 				(struct wmi_roam_invoke_cmd *)roaminvoke,
 				ch_hz);
 free_frame_buf:
@@ -645,11 +650,15 @@ void wma_process_roam_synch_fail(WMA_HANDLE handle,
 				 struct roam_offload_synch_fail *synch_fail)
 {
 	tp_wma_handle wma_handle = (tp_wma_handle) handle;
+	struct wmi_unified *wmi_handle;
+
+	if (wma_validate_handle(wma_handle))
+		return;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, can not clean-up roam synch");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return;
-	}
+
 	wlan_roam_debug_log(synch_fail->session_id,
 			    DEBUG_ROAM_SYNCH_FAIL,
 			    DEBUG_INVALID_PEER_ID, NULL, NULL, 0, 0);
@@ -2607,17 +2616,19 @@ wma_roam_ho_fail_handler(tp_wma_handle wma, uint32_t vdev_id,
 void wma_process_roam_synch_complete(WMA_HANDLE handle, uint8_t vdev_id)
 {
 	tp_wma_handle wma_handle = (tp_wma_handle) handle;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma_handle || !wma_handle->wmi_handle) {
-		wma_err("WMA is closed, can not issue roam synch cnf");
+	if (wma_validate_handle(wma_handle))
+		return;
+
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return;
-	}
 
 	if (!wma_is_vdev_valid(vdev_id))
 		return;
 
-	if (wmi_unified_roam_synch_complete_cmd(wma_handle->wmi_handle,
-						vdev_id))
+	if (wmi_unified_roam_synch_complete_cmd(wmi_handle, vdev_id))
 		return;
 
 	DPTRACE(qdf_dp_trace_record_event(QDF_DP_TRACE_EVENT_RECORD,
@@ -2949,10 +2960,9 @@ int wma_extscan_start_stop_event_handler(void *handle,
 	uint16_t event_type;
 	struct mac_context *mac = cds_get_context(QDF_MODULE_ID_PE);
 
-	if (!mac) {
-		wma_err("Invalid mac");
+	if (!mac)
 		return -EINVAL;
-	}
+
 	if (!mac->sme.ext_scan_ind_cb) {
 		wma_err("Callback not registered");
 		return -EINVAL;
@@ -3046,10 +3056,9 @@ int wma_extscan_operations_event_handler(void *handle,
 	uint32_t cnt;
 	struct mac_context *mac = cds_get_context(QDF_MODULE_ID_PE);
 
-	if (!mac) {
-		wma_err("Invalid mac");
+	if (!mac)
 		return -EINVAL;
-	}
+
 	if (!mac->sme.ext_scan_ind_cb) {
 		wma_err("Callback not registered");
 		return -EINVAL;
@@ -3154,10 +3163,9 @@ int wma_extscan_table_usage_event_handler(void *handle,
 	tSirExtScanResultsAvailableIndParams *tbl_usg_ind;
 	struct mac_context *mac = cds_get_context(QDF_MODULE_ID_PE);
 
-	if (!mac) {
-		wma_err("Invalid mac");
+	if (!mac)
 		return -EINVAL;
-	}
+
 	if (!mac->sme.ext_scan_ind_cb) {
 		wma_err("Callback not registered");
 		return -EINVAL;
@@ -3206,10 +3214,9 @@ int wma_extscan_capabilities_event_handler(void *handle,
 	struct ext_scan_capabilities_response  *dest_capab;
 	struct mac_context *mac = cds_get_context(QDF_MODULE_ID_PE);
 
-	if (!mac) {
-		wma_err("Invalid mac");
+	if (!mac)
 		return -EINVAL;
-	}
+
 	if (!mac->sme.ext_scan_ind_cb) {
 		wma_err("Callback not registered");
 		return -EINVAL;
@@ -3311,10 +3318,9 @@ int wma_extscan_hotlist_match_event_handler(void *handle,
 	uint32_t buf_len;
 	struct mac_context *mac = cds_get_context(QDF_MODULE_ID_PE);
 
-	if (!mac) {
-		wma_err("Invalid mac");
+	if (!mac)
 		return -EINVAL;
-	}
+
 	if (!mac->sme.ext_scan_ind_cb) {
 		wma_err("Callback not registered");
 		return -EINVAL;
@@ -3995,12 +4001,16 @@ QDF_STATUS wma_start_extscan(tp_wma_handle wma,
 			     struct wifi_scan_cmd_req_params *params)
 {
 	QDF_STATUS status;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue cmd");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_INVAL;
-	}
-	if (!wmi_service_enabled(wma->wmi_handle, wmi_service_extscan)) {
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
+	if (!wmi_service_enabled(wmi_handle, wmi_service_extscan)) {
 		wma_err("extscan not enabled");
 		return QDF_STATUS_E_FAILURE;
 	}
@@ -4010,7 +4020,7 @@ QDF_STATUS wma_start_extscan(tp_wma_handle wma,
 		return QDF_STATUS_E_NOMEM;
 	}
 
-	status = wmi_unified_start_extscan_cmd(wma->wmi_handle, params);
+	status = wmi_unified_start_extscan_cmd(wmi_handle, params);
 	if (QDF_IS_STATUS_SUCCESS(status))
 		wma->interfaces[params->vdev_id].extscan_in_progress = true;
 
@@ -4023,17 +4033,21 @@ QDF_STATUS wma_stop_extscan(tp_wma_handle wma,
 			    struct extscan_stop_req_params *params)
 {
 	QDF_STATUS status;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, cannot issue cmd");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_INVAL;
-	}
-	if (!wmi_service_enabled(wma->wmi_handle, wmi_service_extscan)) {
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
+	if (!wmi_service_enabled(wmi_handle, wmi_service_extscan)) {
 		wma_err("extscan not enabled");
 		return QDF_STATUS_E_FAILURE;
 	}
 
-	status = wmi_unified_stop_extscan_cmd(wma->wmi_handle, params);
+	status = wmi_unified_stop_extscan_cmd(wmi_handle, params);
 	if (QDF_IS_STATUS_ERROR(status))
 		return status;
 
@@ -4047,39 +4061,46 @@ QDF_STATUS wma_stop_extscan(tp_wma_handle wma,
 QDF_STATUS wma_extscan_start_hotlist_monitor(tp_wma_handle wma,
 			struct extscan_bssid_hotlist_set_params *params)
 {
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue hotlist cmd");
+	struct wmi_unified *wmi_handle;
+
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	if (!params) {
 		wma_err("Invalid params");
 		return QDF_STATUS_E_INVAL;
 	}
 
-	return wmi_unified_extscan_start_hotlist_monitor_cmd(wma->wmi_handle,
+	return wmi_unified_extscan_start_hotlist_monitor_cmd(wmi_handle,
 							     params);
 }
 
 QDF_STATUS wma_extscan_stop_hotlist_monitor(tp_wma_handle wma,
 		    struct extscan_bssid_hotlist_reset_params *params)
 {
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue cmd");
+	struct wmi_unified *wmi_handle;
+
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	if (!params) {
 		wma_err("Invalid params");
 		return QDF_STATUS_E_INVAL;
 	}
-	if (!wmi_service_enabled(wma->wmi_handle,
-				 wmi_service_extscan)) {
+	if (!wmi_service_enabled(wmi_handle, wmi_service_extscan)) {
 		wma_err("extscan not enabled");
 		return QDF_STATUS_E_FAILURE;
 	}
 
-	return wmi_unified_extscan_stop_hotlist_monitor_cmd(wma->wmi_handle,
+	return wmi_unified_extscan_stop_hotlist_monitor_cmd(wmi_handle,
 							    params);
 }
 
@@ -4088,18 +4109,21 @@ wma_extscan_start_change_monitor(tp_wma_handle wma,
 			struct extscan_set_sig_changereq_params *params)
 {
 	QDF_STATUS status;
+	struct wmi_unified *wmi_handle;
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed,can not issue cmd");
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	if (!params) {
 		wma_err("NULL params");
 		return QDF_STATUS_E_NOMEM;
 	}
 
-	status = wmi_unified_extscan_start_change_monitor_cmd(wma->wmi_handle,
+	status = wmi_unified_extscan_start_change_monitor_cmd(wmi_handle,
 							      params);
 	return status;
 }
@@ -4107,17 +4131,21 @@ wma_extscan_start_change_monitor(tp_wma_handle wma,
 QDF_STATUS wma_extscan_stop_change_monitor(tp_wma_handle wma,
 			struct extscan_capabilities_reset_params *params)
 {
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue cmd");
+	struct wmi_unified *wmi_handle;
+
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_INVAL;
-	}
-	if (!wmi_service_enabled(wma->wmi_handle,
-				    wmi_service_extscan)) {
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
+	if (!wmi_service_enabled(wmi_handle, wmi_service_extscan)) {
 		wma_err("ext scan not enabled");
 		return QDF_STATUS_E_FAILURE;
 	}
 
-	return wmi_unified_extscan_stop_change_monitor_cmd(wma->wmi_handle,
+	return wmi_unified_extscan_stop_change_monitor_cmd(wmi_handle,
 							   params);
 }
 
@@ -4125,16 +4153,21 @@ QDF_STATUS
 wma_extscan_get_cached_results(tp_wma_handle wma,
 			       struct extscan_cached_result_params *params)
 {
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, cannot issue cmd");
+	struct wmi_unified *wmi_handle;
+
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_INVAL;
-	}
-	if (!wmi_service_enabled(wma->wmi_handle, wmi_service_extscan)) {
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
+	if (!wmi_service_enabled(wmi_handle, wmi_service_extscan)) {
 		wma_err("extscan not enabled");
 		return QDF_STATUS_E_FAILURE;
 	}
 
-	return wmi_unified_extscan_get_cached_results_cmd(wma->wmi_handle,
+	return wmi_unified_extscan_get_cached_results_cmd(wmi_handle,
 							  params);
 }
 
@@ -4142,16 +4175,21 @@ QDF_STATUS
 wma_extscan_get_capabilities(tp_wma_handle wma,
 			     struct extscan_capabilities_params *params)
 {
-	if (!wma || !wma->wmi_handle) {
-		wma_er("WMA is closed, can not issue cmd");
+	struct wmi_unified *wmi_handle;
+
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_INVAL;
-	}
-	if (!wmi_service_enabled(wma->wmi_handle, wmi_service_extscan)) {
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_INVAL;
+
+	if (!wmi_service_enabled(wmi_handle, wmi_service_extscan)) {
 		wma_err("extscan not enabled");
 		return QDF_STATUS_E_FAILURE;
 	}
 
-	return wmi_unified_extscan_get_capabilities_cmd(wma->wmi_handle,
+	return wmi_unified_extscan_get_capabilities_cmd(wmi_handle,
 							params);
 }
 
@@ -4159,20 +4197,23 @@ QDF_STATUS wma_set_epno_network_list(tp_wma_handle wma,
 				     struct wifi_enhanced_pno_params *req)
 {
 	QDF_STATUS status;
+	struct wmi_unified *wmi_handle;
 
 	wma_debug("Enter");
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue cmd");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_FAILURE;
-	}
 
-	if (!wmi_service_enabled(wma->wmi_handle, wmi_service_extscan)) {
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_FAILURE;
+
+	if (!wmi_service_enabled(wmi_handle, wmi_service_extscan)) {
 		wma_err("extscan not enabled");
 		return QDF_STATUS_E_NOSUPPORT;
 	}
 
-	status = wmi_unified_set_epno_network_list_cmd(wma->wmi_handle, req);
+	status = wmi_unified_set_epno_network_list_cmd(wmi_handle, req);
 	wma_debug("Exit, vdev %d, status %d", req->vdev_id, status);
 
 	return status;
@@ -4183,19 +4224,23 @@ wma_set_passpoint_network_list(tp_wma_handle wma,
 			       struct wifi_passpoint_req_param *params)
 {
 	QDF_STATUS status;
+	struct wmi_unified *wmi_handle;
 
 	wma_debug("Enter");
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue cmd");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_FAILURE;
-	}
-	if (!wmi_service_enabled(wma->wmi_handle, wmi_service_extscan)) {
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_FAILURE;
+
+	if (!wmi_service_enabled(wmi_handle, wmi_service_extscan)) {
 		wma_err("extscan not enabled");
 		return QDF_STATUS_E_NOSUPPORT;
 	}
 
-	status = wmi_unified_set_passpoint_network_list_cmd(wma->wmi_handle,
+	status = wmi_unified_set_passpoint_network_list_cmd(wmi_handle,
 							    params);
 	wma_debug("Exit, vdev %d, status %d", params->vdev_id, status);
 
@@ -4207,19 +4252,23 @@ wma_reset_passpoint_network_list(tp_wma_handle wma,
 				 struct wifi_passpoint_req_param *params)
 {
 	QDF_STATUS status;
+	struct wmi_unified *wmi_handle;
 
 	wma_debug("Enter");
 
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue cmd");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_FAILURE;
-	}
-	if (!wmi_service_enabled(wma->wmi_handle, wmi_service_extscan)) {
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
+		return QDF_STATUS_E_FAILURE;
+
+	if (!wmi_service_enabled(wmi_handle, wmi_service_extscan)) {
 		wma_err("extscan not enabled");
 		return QDF_STATUS_E_NOSUPPORT;
 	}
 
-	status = wmi_unified_reset_passpoint_network_list_cmd(wma->wmi_handle,
+	status = wmi_unified_reset_passpoint_network_list_cmd(wmi_handle,
 							      params);
 	wma_debug("Exit, vdev %d, status %d", params->vdev_id, status);
 
@@ -4231,17 +4280,21 @@ wma_reset_passpoint_network_list(tp_wma_handle wma,
 QDF_STATUS wma_scan_probe_setoui(tp_wma_handle wma,
 				 struct scan_mac_oui *set_oui)
 {
-	if (!wma || !wma->wmi_handle) {
-		wma_err("WMA is closed, can not issue cmd");
+	struct wmi_unified *wmi_handle;
+
+	if (wma_validate_handle(wma))
+		return QDF_STATUS_E_INVAL;
+
+	wmi_handle = wma->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	if (!wma_is_vdev_valid(set_oui->vdev_id)) {
 		wma_err("vdev_id: %d is not active", set_oui->vdev_id);
 		return QDF_STATUS_E_INVAL;
 	}
 
-	return wmi_unified_scan_probe_setoui_cmd(wma->wmi_handle, set_oui);
+	return wmi_unified_scan_probe_setoui_cmd(wmi_handle, set_oui);
 }
 
 /**
@@ -4572,10 +4625,8 @@ int wma_roam_event_callback(WMA_HANDLE handle, uint8_t *event_buf,
 QDF_STATUS wma_set_gateway_params(tp_wma_handle wma,
 				  struct gateway_update_req_param *req)
 {
-	if (!wma) {
-		wma_err("wma handle is NULL");
+	if (wma_validate_handle(wma))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	return wmi_unified_set_gateway_params_cmd(wma->wmi_handle, req);
 }

+ 21 - 39
core/wma/src/wma_twt.c

@@ -69,11 +69,10 @@ int wma_twt_en_complete_event_handler(void *handle,
 	if (wma_validate_handle(wma_handle))
 		return status;
 
-	wmi_handle = (wmi_unified_t)wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("Invalid wmi handle for TWT complete");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return status;
-	}
+
 	if (!mac)
 		return status;
 
@@ -126,10 +125,8 @@ int wma_twt_disable_comp_event_handler(void *handle, uint8_t *event,
 	struct mac_context *mac;
 
 	mac = (struct mac_context *)cds_get_context(QDF_MODULE_ID_PE);
-	if (!mac) {
-		wma_err("Invalid MAC context");
+	if (!mac)
 		return -EINVAL;
-	}
 
 	wma_debug("TWT: Rcvd TWT disable comp event");
 
@@ -155,11 +152,9 @@ QDF_STATUS wma_twt_process_add_dialog(t_wma_handle *wma_handle,
 	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
 
-	wmi_handle = (wmi_unified_t)wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("Invalid wmi handle, twt add dialog failed");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	return wmi_unified_twt_add_dialog_cmd(wmi_handle, params);
 }
@@ -190,11 +185,9 @@ int wma_twt_add_dialog_complete_event_handler(void *handle,
 	if (!mac)
 		return -EINVAL;
 
-	wmi_handle = (wmi_unified_t)wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("Invalid wma handle for TWT add dialog complete");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return -EINVAL;
-	}
 
 	add_dialog_event = qdf_mem_malloc(sizeof(*add_dialog_event));
 	if (!add_dialog_event)
@@ -237,11 +230,9 @@ wma_twt_process_del_dialog(t_wma_handle *wma_handle,
 	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
 
-	wmi_handle = (wmi_unified_t)wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("Invalid wmi handle, twt del dialog failed");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	return wmi_unified_twt_del_dialog_cmd(wmi_handle, params);
 }
@@ -269,11 +260,10 @@ int wma_twt_del_dialog_complete_event_handler(void *handle,
 	if (wma_validate_handle(wma_handle))
 		return status;
 
-	wmi_handle = (wmi_unified_t)wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("Invalid wma handle for TWT del dialog complete");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return status;
-	}
+
 	if (!mac)
 		return status;
 
@@ -306,11 +296,9 @@ wma_twt_process_pause_dialog(t_wma_handle *wma_handle,
 	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
 
-	wmi_handle = (wmi_unified_t)wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("Invalid wmi handle, twt pause dialog failed");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	return wmi_unified_twt_pause_dialog_cmd(wmi_handle, params);
 }
@@ -341,11 +329,9 @@ int wma_twt_pause_dialog_complete_event_handler(void *handle, uint8_t *event,
 	if (wma_validate_handle(wma_handle))
 		return status;
 
-	wmi_handle = (wmi_unified_t)wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("Invalid wmi handle for TWT pause dialog complete");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return status;
-	}
 
 	param = qdf_mem_malloc(sizeof(*param));
 	if (!param)
@@ -378,11 +364,9 @@ wma_twt_process_resume_dialog(t_wma_handle *wma_handle,
 	if (wma_validate_handle(wma_handle))
 		return QDF_STATUS_E_INVAL;
 
-	wmi_handle = (wmi_unified_t)wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("Invalid wmi handle, twt resume dialog failed");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return QDF_STATUS_E_INVAL;
-	}
 
 	return wmi_unified_twt_resume_dialog_cmd(wmi_handle, params);
 }
@@ -413,11 +397,9 @@ int wma_twt_resume_dialog_complete_event_handler(void *handle, uint8_t *event,
 	if (wma_validate_handle(wma_handle))
 		return status;
 
-	wmi_handle = (wmi_unified_t)wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("Invalid wmi handle for TWT resume dialog complete");
+	wmi_handle = wma_handle->wmi_handle;
+	if (wmi_validate_handle(wmi_handle))
 		return status;
-	}
 
 	param = qdf_mem_malloc(sizeof(*param));
 	if (!param)

+ 2 - 6
core/wma/src/wma_utils.c

@@ -4061,10 +4061,8 @@ int wma_roam_scan_stats_event_handler(void *handle, uint8_t *event,
 		return -EINVAL;
 
 	wmi_handle = wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("NULL wmi_handle");
+	if (wmi_validate_handle(wmi_handle))
 		return -EINVAL;
-	}
 
 	status = wmi_extract_roam_scan_stats_res_evt(wmi_handle, event,
 						     &vdev_id,
@@ -4555,10 +4553,8 @@ int wma_wlm_stats_req(int vdev_id, uint32_t bitmask, uint32_t max_size,
 		return -EINVAL;
 
 	wmi_handle = wma_handle->wmi_handle;
-	if (!wmi_handle) {
-		wma_err("Invalid wmi handle for wlm_stats_event_handler");
+	if (wmi_validate_handle(wmi_handle))
 		return -EINVAL;
-	}
 
 	if (!wmi_service_enabled(wmi_handle, wmi_service_wlm_stats_support)) {
 		wma_err("Feature not supported by firmware");