Bladeren bron

qcacld-3.0: use QDF API for mem allocation

Replace usage of k[mz]alloc()/kfree() with qdf_mem_malloc()/
qdf_mem_free(). The API qdf_mem_malloc() calls kzalloc() with proper
allocation flags depending on the context.

QDF module has debugging capabilities like detect memory leak, list
allocation..etc.

Change-Id: I6655bc54675b5bdc0a8ce17753a08205e711d806
CRs-Fixed: 1085826
Mahesh Kumar Kalikot Veetil 8 jaren geleden
bovenliggende
commit
9c65618338

+ 16 - 19
core/hdd/src/wlan_hdd_assoc.c

@@ -933,19 +933,18 @@ hdd_send_ft_assoc_response(struct net_device *dev,
 		   (unsigned int)pFTAssocRsp[1]);
 
 	/* We need to send the IEs to the supplicant. */
-	buff = kmalloc(IW_GENERIC_IE_MAX, GFP_ATOMIC);
+	buff = qdf_mem_malloc(IW_GENERIC_IE_MAX);
 	if (buff == NULL) {
-		hdd_err("kmalloc unable to allocate memory");
+		hdd_err("unable to allocate memory");
 		return;
 	}
 	/* Send the Assoc Resp, the supplicant needs this for initial Auth. */
 	len = pCsrRoamInfo->nAssocRspLength - FT_ASSOC_RSP_IES_OFFSET;
 	wrqu.data.length = len;
-	memset(buff, 0, IW_GENERIC_IE_MAX);
 	memcpy(buff, pFTAssocRsp, len);
 	wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, buff);
 
-	kfree(buff);
+	qdf_mem_free(buff);
 }
 
 /**
@@ -1018,12 +1017,11 @@ static void hdd_send_ft_event(hdd_adapter_t *pAdapter)
 
 #else
 	/* We need to send the IEs to the supplicant */
-	buff = kmalloc(IW_CUSTOM_MAX, GFP_ATOMIC);
+	buff = qdf_mem_malloc(IW_CUSTOM_MAX);
 	if (buff == NULL) {
-		hdd_err("kmalloc unable to allocate memory");
+		hdd_err("unable to allocate memory");
 		return;
 	}
-	qdf_mem_zero(buff, IW_CUSTOM_MAX);
 
 	/* Sme needs to send the RIC IEs first */
 	str_len = strlcpy(buff, "RIC=", IW_CUSTOM_MAX);
@@ -1045,7 +1043,7 @@ static void hdd_send_ft_event(hdd_adapter_t *pAdapter)
 				     (IW_CUSTOM_MAX - str_len), &auth_resp_len);
 
 	if (auth_resp_len == 0) {
-		kfree(buff);
+		qdf_mem_free(buff);
 		hdd_err("AuthRsp FTIES is of length 0");
 		return;
 	}
@@ -1053,7 +1051,7 @@ static void hdd_send_ft_event(hdd_adapter_t *pAdapter)
 	wrqu.data.length = str_len + auth_resp_len;
 	wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, buff);
 
-	kfree(buff);
+	qdf_mem_free(buff);
 #endif
 }
 
@@ -1133,12 +1131,11 @@ hdd_send_update_beacon_ies_event(hdd_adapter_t *pAdapter,
 		   pCsrRoamInfo->nBeaconLength - BEACON_FRAME_IES_OFFSET);
 
 	/* We need to send the IEs to the supplicant. */
-	buff = kmalloc(IW_CUSTOM_MAX, GFP_ATOMIC);
+	buff = qdf_mem_malloc(IW_CUSTOM_MAX);
 	if (buff == NULL) {
-		hdd_err("kmalloc unable to allocate memory");
+		hdd_err("unable to allocate memory");
 		return;
 	}
-	qdf_mem_zero(buff, IW_CUSTOM_MAX);
 
 	strLen = strlcpy(buff, "BEACONIEs=", IW_CUSTOM_MAX);
 	currentLen = strLen + 1;
@@ -1168,7 +1165,7 @@ hdd_send_update_beacon_ies_event(hdd_adapter_t *pAdapter,
 		wireless_send_event(pAdapter->dev, IWEVCUSTOM, &wrqu, buff);
 	} while (totalIeLen > 0);
 
-	kfree(buff);
+	qdf_mem_free(buff);
 }
 
 /**
@@ -1933,8 +1930,8 @@ static void hdd_send_re_assoc_event(struct net_device *dev,
 {
 	unsigned int len = 0;
 	u8 *pFTAssocRsp = NULL;
-	uint8_t *rspRsnIe = kmalloc(IW_GENERIC_IE_MAX, GFP_KERNEL);
-	uint8_t *assoc_req_ies = kmalloc(IW_GENERIC_IE_MAX, GFP_KERNEL);
+	uint8_t *rspRsnIe = qdf_mem_malloc(IW_GENERIC_IE_MAX);
+	uint8_t *assoc_req_ies = qdf_mem_malloc(IW_GENERIC_IE_MAX);
 	uint32_t rspRsnLength = 0;
 	struct ieee80211_channel *chan;
 	uint8_t buf_ssid_ie[2 + SIR_MAC_SSID_EID_MAX]; /* 2 bytes-EID and len */
@@ -2018,7 +2015,7 @@ static void hdd_send_re_assoc_event(struct net_device *dev,
 	hdd_notice("SSIDIE:");
 	QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
 			   buf_ssid_ie, ssid_ie_len);
-	final_req_ie = kmalloc(IW_GENERIC_IE_MAX, GFP_KERNEL);
+	final_req_ie = qdf_mem_malloc(IW_GENERIC_IE_MAX);
 	if (final_req_ie == NULL)
 		goto done;
 	buf_ptr = final_req_ie;
@@ -2050,9 +2047,9 @@ static void hdd_send_re_assoc_event(struct net_device *dev,
 done:
 	sme_roam_free_connect_profile(&roam_profile);
 	if (final_req_ie)
-		kfree(final_req_ie);
-	kfree(rspRsnIe);
-	kfree(assoc_req_ies);
+		qdf_mem_free(final_req_ie);
+	qdf_mem_free(rspRsnIe);
+	qdf_mem_free(assoc_req_ies);
 }
 
 /**

+ 4 - 4
core/hdd/src/wlan_hdd_cfg80211.c

@@ -11204,7 +11204,7 @@ struct cfg80211_bss *wlan_hdd_cfg80211_inform_bss_frame(hdd_adapter_t *pAdapter,
 		return NULL;
 
 	cfg_param = pHddCtx->config;
-	mgmt = kzalloc((sizeof(struct ieee80211_mgmt) + ie_length), GFP_KERNEL);
+	mgmt = qdf_mem_malloc((sizeof(struct ieee80211_mgmt) + ie_length));
 	if (!mgmt) {
 		hdd_err("memory allocation failed");
 		return NULL;
@@ -11269,7 +11269,7 @@ struct cfg80211_bss *wlan_hdd_cfg80211_inform_bss_frame(hdd_adapter_t *pAdapter,
 						       NL80211_BAND_5GHZ);
 	} else {
 		hdd_err("Invalid chan_no %d", chan_no);
-		kfree(mgmt);
+		qdf_mem_free(mgmt);
 		return NULL;
 	}
 
@@ -11298,7 +11298,7 @@ struct cfg80211_bss *wlan_hdd_cfg80211_inform_bss_frame(hdd_adapter_t *pAdapter,
 	if (chan == NULL) {
 		hdd_err("chan pointer is NULL, chan_no: %d freq: %d",
 			chan_no, freq);
-		kfree(mgmt);
+		qdf_mem_free(mgmt);
 		return NULL;
 	}
 
@@ -11321,7 +11321,7 @@ struct cfg80211_bss *wlan_hdd_cfg80211_inform_bss_frame(hdd_adapter_t *pAdapter,
 		cfg80211_inform_bss_frame(wiphy, chan, mgmt, frame_len, rssi,
 					  GFP_KERNEL);
 	pHddCtx->beacon_probe_rsp_cnt_per_scan++;
-	kfree(mgmt);
+	qdf_mem_free(mgmt);
 	return bss_status;
 }
 

+ 6 - 6
core/hdd/src/wlan_hdd_ftm.c

@@ -218,7 +218,7 @@ static int wlan_hdd_qcmbr_command(hdd_adapter_t *adapter,
 		if (!ret) {
 			memcpy(pqcmbr_data->buf, qcmbr_buf->utf_buf,
 			       (MAX_UTF_LENGTH + 4));
-			kfree(qcmbr_buf);
+			qdf_mem_free(qcmbr_buf);
 		} else {
 			ret = -EAGAIN;
 		}
@@ -243,7 +243,7 @@ static int wlan_hdd_qcmbr_compat_ioctl(hdd_adapter_t *adapter,
 	qcmbr_data_t *qcmbr_data;
 	int ret = 0;
 
-	qcmbr_data = kzalloc(sizeof(qcmbr_data_t), GFP_KERNEL);
+	qcmbr_data = qdf_mem_malloc(sizeof(qcmbr_data_t));
 	if (qcmbr_data == NULL)
 		return -ENOMEM;
 
@@ -259,7 +259,7 @@ static int wlan_hdd_qcmbr_compat_ioctl(hdd_adapter_t *adapter,
 	}
 
 exit:
-	kfree(qcmbr_data);
+	qdf_mem_free(qcmbr_data);
 	return ret;
 }
 #else                           /* CONFIG_COMPAT */
@@ -282,7 +282,7 @@ static int wlan_hdd_qcmbr_ioctl(hdd_adapter_t *adapter, struct ifreq *ifr)
 	qcmbr_data_t *qcmbr_data;
 	int ret = 0;
 
-	qcmbr_data = kzalloc(sizeof(qcmbr_data_t), GFP_KERNEL);
+	qcmbr_data = qdf_mem_malloc(sizeof(qcmbr_data_t));
 	if (qcmbr_data == NULL)
 		return -ENOMEM;
 
@@ -298,7 +298,7 @@ static int wlan_hdd_qcmbr_ioctl(hdd_adapter_t *adapter, struct ifreq *ifr)
 	}
 
 exit:
-	kfree(qcmbr_data);
+	qdf_mem_free(qcmbr_data);
 	return ret;
 }
 
@@ -334,7 +334,7 @@ static void wlanqcmbr_mc_process_msg(void *message)
 	uint32_t data_len;
 
 	data_len = *((uint32_t *) message) + sizeof(uint32_t);
-	qcmbr_buf = kzalloc(sizeof(qcmbr_queue_t), GFP_KERNEL);
+	qcmbr_buf = qdf_mem_malloc(sizeof(qcmbr_queue_t));
 	if (qcmbr_buf != NULL) {
 		memcpy(qcmbr_buf->utf_buf, message, data_len);
 		spin_lock_bh(&qcmbr_queue_lock);

+ 2 - 2
core/hdd/src/wlan_hdd_hostapd.c

@@ -3855,7 +3855,7 @@ static __iw_softap_getassoc_stamacaddr(struct net_device *dev,
 	}
 
 	/* allocate local buffer to build the response */
-	buf = kmalloc(wrqu->data.length, GFP_KERNEL);
+	buf = qdf_mem_malloc(wrqu->data.length);
 	if (!buf) {
 		hdd_notice("failed to allocate response buffer");
 		return -ENOMEM;
@@ -3884,7 +3884,7 @@ static __iw_softap_getassoc_stamacaddr(struct net_device *dev,
 		hdd_notice("failed to copy response to user buffer");
 		ret = -EFAULT;
 	}
-	kfree(buf);
+	qdf_mem_free(buf);
 	EXIT();
 	return ret;
 }

+ 6 - 6
core/hdd/src/wlan_hdd_ioctl.c

@@ -5056,11 +5056,11 @@ static int drv_cmd_get_ibss_peer_info_all(hdd_adapter_t *adapter,
 		 * exceeds the size of 1024 bytes of default stack size. On
 		 * 64 bit devices, the default max stack size of 2048 bytes
 		 */
-		extra = kmalloc(WLAN_MAX_BUF_SIZE, GFP_KERNEL);
+		extra = qdf_mem_malloc(WLAN_MAX_BUF_SIZE);
 
 		if (NULL == extra) {
-			hdd_err("kmalloc failed");
-			ret = -EINVAL;
+			hdd_err("memory allocation failed");
+			ret = -ENOMEM;
 			goto exit;
 		}
 
@@ -5131,7 +5131,7 @@ static int drv_cmd_get_ibss_peer_info_all(hdd_adapter_t *adapter,
 		}
 
 		/* Free temporary buffer */
-		kfree(extra);
+		qdf_mem_free(extra);
 	} else {
 		/* Command failed, log error */
 		hdd_err("GETIBSSPEERINFOALL command failed with status code %d",
@@ -7308,7 +7308,7 @@ static int hdd_driver_command(hdd_adapter_t *adapter,
 	}
 
 	/* Allocate +1 for '\0' */
-	command = kmalloc(priv_data->total_len + 1, GFP_KERNEL);
+	command = qdf_mem_malloc(priv_data->total_len + 1);
 	if (!command) {
 		hdd_err("failed to allocate memory");
 		ret = -ENOMEM;
@@ -7328,7 +7328,7 @@ static int hdd_driver_command(hdd_adapter_t *adapter,
 
 exit:
 	if (command)
-		kfree(command);
+		qdf_mem_free(command);
 	EXIT();
 	return ret;
 }

+ 1 - 1
core/hdd/src/wlan_hdd_power.c

@@ -1615,7 +1615,7 @@ err_wiphy_unregister:
 		nl_srv_exit();
 
 		/* Free up dynamically allocated members inside HDD Adapter */
-		kfree(pHddCtx->config);
+		qdf_mem_free(pHddCtx->config);
 		pHddCtx->config = NULL;
 		wlan_hdd_deinit_tx_rx_histogram(pHddCtx);
 		wiphy_unregister(pHddCtx->wiphy);

+ 5 - 5
core/hdd/src/wlan_hdd_wext.c

@@ -1074,7 +1074,7 @@ void *mem_alloc_copy_from_user_helper(const __user void *wrqu_data, size_t len)
 		return NULL;
 	}
 
-	ptr = kmalloc(len + 1, GFP_KERNEL);
+	ptr = qdf_mem_malloc(len + 1);
 	if (NULL == ptr) {
 		hdd_err("unable to allocate memory");
 		return NULL;
@@ -1082,7 +1082,7 @@ void *mem_alloc_copy_from_user_helper(const __user void *wrqu_data, size_t len)
 
 	if (copy_from_user(ptr, wrqu_data, len)) {
 		hdd_err("failed to copy data to user buffer");
-		kfree(ptr);
+		qdf_mem_free(ptr);
 		return NULL;
 	}
 	ptr[len] = '\0';
@@ -3475,7 +3475,7 @@ static int __iw_set_genie(struct net_device *dev,
 	}
 exit:
 	EXIT();
-	kfree(base_genie);
+	qdf_mem_free(base_genie);
 	return ret;
 }
 
@@ -7059,7 +7059,7 @@ static int __iw_setchar_getnone(struct net_device *dev,
 		break;
 	}
 	}
-	kfree(pBuffer);
+	qdf_mem_free(pBuffer);
 	EXIT();
 	return ret;
 }
@@ -9989,7 +9989,7 @@ static int __iw_set_packet_filter_params(struct net_device *dev,
 
 	ret = wlan_hdd_set_filter(hdd_ctx, request, adapter->sessionId);
 
-	kfree(request);
+	qdf_mem_free(request);
 	EXIT();
 	return ret;
 }

+ 4 - 4
core/hdd/src/wlan_hdd_wmm.c

@@ -275,7 +275,7 @@ static void hdd_wmm_free_context(hdd_wmm_qos_context_t *pQosContext)
 	mutex_unlock(&pAdapter->hddWmmStatus.wmmLock);
 
 	/* reclaim memory */
-	kfree(pQosContext);
+	qdf_mem_free(pQosContext);
 
 }
 
@@ -1042,7 +1042,7 @@ static void __hdd_wmm_do_implicit_qos(struct work_struct *work)
 	if (!pAc->wmmAcAccessNeeded) {
 		hdd_err("AC %d doesn't need service", acType);
 		pQosContext->magic = 0;
-		kfree(pQosContext);
+		qdf_mem_free(pQosContext);
 		return;
 	}
 
@@ -1752,7 +1752,7 @@ QDF_STATUS hdd_wmm_acquire_access(hdd_adapter_t *pAdapter,
 
 	pAdapter->hddWmmStatus.wmmAcStatus[acType].wmmAcAccessNeeded = true;
 
-	pQosContext = kmalloc(sizeof(*pQosContext), GFP_ATOMIC);
+	pQosContext = qdf_mem_malloc(sizeof(*pQosContext));
 	if (NULL == pQosContext) {
 		/* no memory for QoS context.  Nothing we can do but
 		 * let data flow
@@ -2138,7 +2138,7 @@ hdd_wlan_wmm_status_e hdd_wmm_addts(hdd_adapter_t *pAdapter,
 		return status;
 	}
 
-	pQosContext = kmalloc(sizeof(*pQosContext), GFP_KERNEL);
+	pQosContext = qdf_mem_malloc(sizeof(*pQosContext));
 	if (NULL == pQosContext) {
 		/* no memory for QoS context.  Nothing we can do */
 		hdd_err("Unable to allocate QoS context");

+ 5 - 5
core/hdd/src/wlan_hdd_wowl.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2017 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
@@ -215,9 +215,9 @@ bool hdd_add_wowl_ptrn(hdd_adapter_t *pAdapter, const char *ptrn)
 
 		/* All is good. Store the pattern locally */
 		g_hdd_wowl_ptrns[first_empty_slot] =
-			kmalloc(len + 1, GFP_KERNEL);
+			qdf_mem_malloc(len + 1);
 		if (g_hdd_wowl_ptrns[first_empty_slot] == NULL) {
-			hdd_err(" kmalloc failure");
+			hdd_err("memory allocation failure");
 			return false;
 		}
 
@@ -235,7 +235,7 @@ bool hdd_add_wowl_ptrn(hdd_adapter_t *pAdapter, const char *ptrn)
 			/* Add failed, so invalidate the local storage */
 			hdd_err("sme_wowl_add_bcast_pattern failed with error code (%d)",
 				  qdf_ret_status);
-			kfree(g_hdd_wowl_ptrns[first_empty_slot]);
+			qdf_mem_free(g_hdd_wowl_ptrns[first_empty_slot]);
 			g_hdd_wowl_ptrns[first_empty_slot] = NULL;
 		}
 
@@ -293,7 +293,7 @@ bool hdd_del_wowl_ptrn(hdd_adapter_t *pAdapter, const char *ptrn)
 			hdd_err("Deleted pattern with id %d [%s]", id,
 				  g_hdd_wowl_ptrns[id]);
 
-			kfree(g_hdd_wowl_ptrns[id]);
+			qdf_mem_free(g_hdd_wowl_ptrns[id]);
 			g_hdd_wowl_ptrns[id] = NULL;
 			return true;
 		}