Search Linux Wireless

[PATCH 2/4] mwifiex: use dynamic allocation for large size structure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Amitkumar Karwar <akarwar@xxxxxxxxxxx>

'make checkstack' found:
0x0000f9ee mwifiex_cfg80211_results [mwifiex]:    760

struct mwifiex_user_scan_cfg has big array inside.
Change the code to use kzalloc so that mwifiex_cfg80211_results()
routine uses less than 512 bytes on the stack.

Signed-off-by: Amitkumar Karwar <akarwar@xxxxxxxxxxx>
Signed-off-by: Bing Zhao <bzhao@xxxxxxxxxxx>
---
 drivers/net/wireless/mwifiex/cfg80211.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/mwifiex/cfg80211.c b/drivers/net/wireless/mwifiex/cfg80211.c
index 6aa5962..d34c622 100644
--- a/drivers/net/wireless/mwifiex/cfg80211.c
+++ b/drivers/net/wireless/mwifiex/cfg80211.c
@@ -1453,32 +1453,38 @@ mwifiex_cfg80211_results(struct work_struct *work)
 {
 	struct mwifiex_private *priv =
 		container_of(work, struct mwifiex_private, cfg_workqueue);
-	struct mwifiex_user_scan_cfg scan_req;
+	struct mwifiex_user_scan_cfg *scan_req;
 	int ret = 0, i;
 	struct ieee80211_channel *chan;
 
 	if (priv->scan_request) {
-		memset(&scan_req, 0x00, sizeof(scan_req));
+		scan_req = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
+				   GFP_KERNEL);
+		if (!scan_req) {
+			dev_err(priv->adapter->dev, "failed to alloc "
+						    "scan_req\n");
+			return;
+		}
 		for (i = 0; i < priv->scan_request->n_ssids; i++) {
-			memcpy(scan_req.ssid_list[i].ssid,
+			memcpy(scan_req->ssid_list[i].ssid,
 					priv->scan_request->ssids[i].ssid,
 					priv->scan_request->ssids[i].ssid_len);
-			scan_req.ssid_list[i].max_len =
+			scan_req->ssid_list[i].max_len =
 					priv->scan_request->ssids[i].ssid_len;
 		}
 		for (i = 0; i < priv->scan_request->n_channels; i++) {
 			chan = priv->scan_request->channels[i];
-			scan_req.chan_list[i].chan_number = chan->hw_value;
-			scan_req.chan_list[i].radio_type = chan->band;
+			scan_req->chan_list[i].chan_number = chan->hw_value;
+			scan_req->chan_list[i].radio_type = chan->band;
 			if (chan->flags & IEEE80211_CHAN_DISABLED)
-				scan_req.chan_list[i].scan_type =
+				scan_req->chan_list[i].scan_type =
 					MWIFIEX_SCAN_TYPE_PASSIVE;
 			else
-				scan_req.chan_list[i].scan_type =
+				scan_req->chan_list[i].scan_type =
 					MWIFIEX_SCAN_TYPE_ACTIVE;
-			scan_req.chan_list[i].scan_time = 0;
+			scan_req->chan_list[i].scan_time = 0;
 		}
-		if (mwifiex_set_user_scan_ioctl(priv, &scan_req)) {
+		if (mwifiex_set_user_scan_ioctl(priv, scan_req)) {
 			ret = -EFAULT;
 			goto done;
 		}
@@ -1491,6 +1497,7 @@ done:
 		cfg80211_scan_done(priv->scan_request,
 				(priv->scan_result_status < 0));
 		priv->scan_request = NULL;
+		kfree(scan_req);
 	}
 
 	if (priv->assoc_request) {
-- 
1.7.0.2

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux