qcacld-3.0: Fix FTM mode malfunction and memory leak

Current driver will create two apdaters in FTM mode, with device_mode
STA and P2P, where STA is incorrect and P2P is unnecessary.
And those types will cause memory leak in
qdf_mem_malloc()/sme_deregister_mgmt_frame(), when unloading driver.

Also, it is improper to fix the interface name to wlan0 for FTM mode,
as some platforms may use different naming rule.

Only create one adapter with FTM mode, with variable interface name.

CRs-Fixed: 2160513
Change-Id: If3bf4444e5535e6fe88c3ad2d87da217534984a0
diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c
index a138908..305d51f 100644
--- a/core/hdd/src/wlan_hdd_main.c
+++ b/core/hdd/src/wlan_hdd_main.c
@@ -2102,6 +2102,8 @@
 		ret = hdd_start_ftm_adapter(adapter);
 		if (ret)
 			goto err_start_adapter;
+		else
+			goto ftm_complete;
 	break;
 	default:
 		hdd_err("Invalid session type %d", device_mode);
@@ -2121,6 +2123,7 @@
 		goto err_start_adapter;
 	}
 
+ftm_complete:
 	EXIT();
 	return 0;
 err_start_adapter:
@@ -4337,7 +4340,7 @@
 	case QDF_FTM_MODE:
 		adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
 						    name_assign_type,
-						    "wlan0");
+						    iface_name);
 		if (NULL == adapter) {
 			hdd_err("Failed to allocate adapter for FTM mode");
 			return NULL;
@@ -8422,14 +8425,19 @@
 	int ret;
 
 	/* open monitor mode adapter if con_mode is monitor mode */
-	if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
-		adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
-				wlan_hdd_get_intf_addr(hdd_ctx),
-				NET_NAME_UNKNOWN, rtnl_held);
+	if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
+	    con_mode == QDF_GLOBAL_FTM_MODE) {
+		uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
+						QDF_MONITOR_MODE : QDF_FTM_MODE;
+
+		adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
+					   wlan_hdd_get_intf_addr(hdd_ctx),
+					   NET_NAME_UNKNOWN, rtnl_held);
 		if (!adapter) {
 			hdd_err("open adapter failed");
 			return -ENOSPC;
 		}
+
 		return 0;
 	}