qcacld-3.0: Fix pre cac work thread hung

wlan_hdd_sap_pre_cac_success run in the work thread
scheduled by sap_pre_cac_work.
But hdd_stop_adapter will call
cds_flush_work(&hdd_ctx->sap_pre_cac_work);
That means the work waits itself to finish.

The Fix is to add flag to hdd_stop_adapter
to identify the "stop" running in the work handler
and skip the "sync" cancel the work self.

Change-Id: I875c2f14ffd54272fc9ea0df1cecc6dd1171e310
CRs-Fixed: 2252085
diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c
index e271bc4..6bb6e2b 100644
--- a/core/hdd/src/wlan_hdd_main.c
+++ b/core/hdd/src/wlan_hdd_main.c
@@ -4831,8 +4831,8 @@
 	/* cleanup adapter */
 	policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
 					  adapter->device_mode);
-	hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
 	hdd_remove_adapter(hdd_ctx, adapter);
+	hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
 
 	/* conditionally restart the bw timer */
 	hdd_bus_bw_compute_timer_try_start(hdd_ctx);
@@ -4928,6 +4928,13 @@
 QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
 			    struct hdd_adapter *adapter)
 {
+	return hdd_stop_adapter_ext(hdd_ctx, adapter, 0);
+}
+
+QDF_STATUS hdd_stop_adapter_ext(struct hdd_context *hdd_ctx,
+				struct hdd_adapter *adapter,
+				enum hdd_adapter_stop_flag_t flag)
+{
 	QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
 	struct csr_roam_profile *roam_profile;
 	union iwreq_data wrqu;
@@ -5058,7 +5065,8 @@
 			wlansap_reset_sap_config_add_ie(sap_config,
 							eUPDATE_IE_ALL);
 		ucfg_ipa_flush(hdd_ctx->hdd_pdev);
-		cds_flush_work(&hdd_ctx->sap_pre_cac_work);
+		if (!(flag & HDD_IN_CAC_WORK_TH_CONTEXT))
+			cds_flush_work(&hdd_ctx->sap_pre_cac_work);
 		/* fallthrough */
 
 	case QDF_P2P_GO_MODE: