All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ajay Singh <ajay.kathat@microchip.com>
To: <linux-wireless@vger.kernel.org>
Cc: <devel@driverdev.osuosl.org>, <gregkh@linuxfoundation.org>,
	<ganesh.krishna@microchip.com>, <venkateswara.kaja@microchip.com>,
	<aditya.shankar@microchip.com>, <claudiu.beznea@microchip.com>,
	<adham.abozaeid@microchip.com>,
	Ajay Singh <ajay.kathat@microchip.com>
Subject: [PATCH 06/11] staging: wilc1000: refactor mgmt_tx to fix line over 80 chars
Date: Tue, 20 Mar 2018 22:25:39 +0530	[thread overview]
Message-ID: <1521564944-3565-7-git-send-email-ajay.kathat@microchip.com> (raw)
In-Reply-To: <1521564944-3565-1-git-send-email-ajay.kathat@microchip.com>

Refactor mgmt_tx() to fix line over 80 characters issue. Split the
function to avoid the checkpatch.pl warning. Returning the same error
code in case of memory allocation failure.

Signed-off-by: Ajay Singh <ajay.kathat@microchip.com>
---
 drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 187 +++++++++++++---------
 1 file changed, 111 insertions(+), 76 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index d7ff0a9..9950ca5 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -1555,6 +1555,58 @@ static int cancel_remain_on_channel(struct wiphy *wiphy,
 			priv->remain_on_ch_params.listen_session_id);
 }
 
+static void wilc_wfi_cfg_tx_vendor_spec(struct p2p_mgmt_data *mgmt_tx,
+					struct cfg80211_mgmt_tx_params *params,
+					u8 iftype, u32 buf_len)
+{
+	const u8 *buf = params->buf;
+	size_t len = params->len;
+	u32 i;
+	u8 subtype = buf[P2P_PUB_ACTION_SUBTYPE];
+
+	if (subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) {
+		if (p2p_local_random == 1 &&
+		    p2p_recv_random < p2p_local_random) {
+			get_random_bytes(&p2p_local_random, 1);
+			p2p_local_random++;
+		}
+	}
+
+	if (p2p_local_random > p2p_recv_random && (subtype == GO_NEG_REQ ||
+						   subtype == GO_NEG_RSP ||
+						   subtype == P2P_INV_REQ ||
+						   subtype == P2P_INV_RSP)) {
+		bool found = false;
+		bool oper_ch = false;
+
+		for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
+			if (buf[i] == P2PELEM_ATTR_ID &&
+			    !(memcmp(p2p_oui, &buf[i + 2], 4))) {
+				if (subtype == P2P_INV_REQ ||
+				    subtype == P2P_INV_RSP)
+					oper_ch = true;
+
+				found = true;
+				break;
+			}
+		}
+
+		if (found)
+			wilc_wfi_cfg_parse_tx_action(&mgmt_tx->buff[i + 6],
+						     len - (i + 6), oper_ch,
+						     iftype);
+
+		if (subtype != P2P_INV_REQ && subtype != P2P_INV_RSP) {
+			int vendor_spec_len = sizeof(p2p_vendor_spec);
+
+			memcpy(&mgmt_tx->buff[len], p2p_vendor_spec,
+			       vendor_spec_len);
+			mgmt_tx->buff[len + vendor_spec_len] = p2p_local_random;
+			mgmt_tx->size = buf_len;
+		}
+	}
+}
+
 static int mgmt_tx(struct wiphy *wiphy,
 		   struct wireless_dev *wdev,
 		   struct cfg80211_mgmt_tx_params *params,
@@ -1568,9 +1620,9 @@ static int mgmt_tx(struct wiphy *wiphy,
 	struct p2p_mgmt_data *mgmt_tx;
 	struct wilc_priv *priv;
 	struct host_if_drv *wfi_drv;
-	u32 i;
 	struct wilc_vif *vif;
 	u32 buf_len = len + sizeof(p2p_vendor_spec) + sizeof(p2p_local_random);
+	int ret = 0;
 
 	vif = netdev_priv(wdev->netdev);
 	priv = wiphy_priv(wiphy);
@@ -1580,92 +1632,75 @@ static int mgmt_tx(struct wiphy *wiphy,
 	priv->tx_cookie = *cookie;
 	mgmt = (const struct ieee80211_mgmt *)buf;
 
-	if (ieee80211_is_mgmt(mgmt->frame_control)) {
-		mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL);
-		if (!mgmt_tx)
-			return -EFAULT;
+	if (!ieee80211_is_mgmt(mgmt->frame_control))
+		goto out;
 
-		mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
-		if (!mgmt_tx->buff) {
-			kfree(mgmt_tx);
-			return -ENOMEM;
-		}
+	mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL);
+	if (!mgmt_tx) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
+	if (!mgmt_tx->buff) {
+		ret = -ENOMEM;
+		kfree(mgmt_tx);
+		goto out;
+	}
+
+	memcpy(mgmt_tx->buff, buf, len);
+	mgmt_tx->size = len;
+
+	if (ieee80211_is_probe_resp(mgmt->frame_control)) {
+		wilc_set_mac_chnl_num(vif, chan->hw_value);
+		curr_channel = chan->hw_value;
+		goto out_txq_add_pkt;
+	}
 
-		memcpy(mgmt_tx->buff, buf, len);
-		mgmt_tx->size = len;
+	if (!ieee80211_is_action(mgmt->frame_control))
+		goto out_txq_add_pkt;
 
-		if (ieee80211_is_probe_resp(mgmt->frame_control)) {
+	if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
+		if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC ||
+		    buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF) {
 			wilc_set_mac_chnl_num(vif, chan->hw_value);
 			curr_channel = chan->hw_value;
-		} else if (ieee80211_is_action(mgmt->frame_control))   {
-			if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
-				if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC ||
-				    buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF)	{
-					wilc_set_mac_chnl_num(vif,
-							      chan->hw_value);
-					curr_channel = chan->hw_value;
-				}
-				switch (buf[ACTION_SUBTYPE_ID])	{
-				case GAS_INITIAL_REQ:
-					break;
+		}
+		switch (buf[ACTION_SUBTYPE_ID]) {
+		case GAS_INITIAL_REQ:
+		case GAS_INITIAL_RSP:
+			break;
 
-				case GAS_INITIAL_RSP:
-					break;
+		case PUBLIC_ACT_VENDORSPEC:
+			if (!memcmp(p2p_oui, &buf[ACTION_SUBTYPE_ID + 1], 4))
+				wilc_wfi_cfg_tx_vendor_spec(mgmt_tx, params,
+							    vif->iftype,
+							    buf_len);
+			else
+				netdev_dbg(vif->ndev,
+					   "Not a P2P public action frame\n");
 
-				case PUBLIC_ACT_VENDORSPEC:
-				{
-					if (!memcmp(p2p_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) {
-						if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
-							if (p2p_local_random == 1 && p2p_recv_random < p2p_local_random) {
-								get_random_bytes(&p2p_local_random, 1);
-								p2p_local_random++;
-							}
-						}
-
-						if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP ||
-						     buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
-							if (p2p_local_random > p2p_recv_random)	{
-								for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
-									if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(p2p_oui, &buf[i + 2], 4))) {
-										if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
-											wilc_wfi_cfg_parse_tx_action(&mgmt_tx->buff[i + 6], len - (i + 6), true, vif->iftype);
-										else
-											wilc_wfi_cfg_parse_tx_action(&mgmt_tx->buff[i + 6], len - (i + 6), false, vif->iftype);
-										break;
-									}
-								}
-
-								if (buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_REQ && buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_RSP) {
-									memcpy(&mgmt_tx->buff[len], p2p_vendor_spec, sizeof(p2p_vendor_spec));
-									mgmt_tx->buff[len + sizeof(p2p_vendor_spec)] = p2p_local_random;
-									mgmt_tx->size = buf_len;
-								}
-							}
-						}
-
-					} else {
-						netdev_dbg(vif->ndev, "Not a P2P public action frame\n");
-					}
+			break;
 
-					break;
-				}
+		default:
+			netdev_dbg(vif->ndev,
+				   "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n",
+				   buf[ACTION_SUBTYPE_ID]);
+			break;
+		}
+	}
 
-				default:
-				{
-					netdev_dbg(vif->ndev, "NOT HANDLED PUBLIC ACTION FRAME TYPE:%x\n", buf[ACTION_SUBTYPE_ID]);
-					break;
-				}
-				}
-			}
+	wfi_drv->p2p_timeout = (jiffies + msecs_to_jiffies(wait));
 
-			wfi_drv->p2p_timeout = (jiffies + msecs_to_jiffies(wait));
-		}
+out_txq_add_pkt:
 
-		wilc_wlan_txq_add_mgmt_pkt(wdev->netdev, mgmt_tx,
-					   mgmt_tx->buff, mgmt_tx->size,
-					   wilc_wfi_mgmt_tx_complete);
-	}
-	return 0;
+	wilc_wlan_txq_add_mgmt_pkt(wdev->netdev, mgmt_tx,
+				   mgmt_tx->buff, mgmt_tx->size,
+				   wilc_wfi_mgmt_tx_complete);
+
+out:
+
+	return ret;
 }
 
 static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
-- 
2.7.4

  parent reply	other threads:[~2018-03-20 16:56 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-20 16:55 [PATCH 00/11] staging: wilc1000: fix for checkpatch and handled malloc memory properly Ajay Singh
2018-03-20 16:55 ` [PATCH 01/11] staging: wilc1000: refactor scan() to free kmalloc memory on failure cases Ajay Singh
2018-03-20 19:46   ` Dan Carpenter
2018-03-21  5:05     ` Ajay Singh
2018-03-20 16:55 ` [PATCH 02/11] staging: wilc1000: removed unused global variables for gtk and ptk information Ajay Singh
2018-03-20 16:55 ` [PATCH 03/11] staging: wilc1000: remove line over 80 char warnings in set_wiphy_params() Ajay Singh
2018-03-20 16:55 ` [PATCH 04/11] staging: wilc1000: refactor WILC_WFI_p2p_rx() to avoid line over 80 char Ajay Singh
2018-03-21  7:13   ` Dan Carpenter
2018-03-21 13:55   ` Claudiu Beznea
2018-03-20 16:55 ` [PATCH 05/11] staging: wilc1000: rename WILC_WFI_p2p_rx & s32Freq to avoid camelCase Ajay Singh
2018-03-20 16:55 ` Ajay Singh [this message]
2018-03-21  7:40   ` [PATCH 06/11] staging: wilc1000: refactor mgmt_tx to fix line over 80 chars Dan Carpenter
2018-03-21 13:59   ` Claudiu Beznea
2018-03-20 16:55 ` [PATCH 07/11] staging: wilc1000: rename hAgingTimer to avoid camelCase issue Ajay Singh
2018-03-20 16:55 ` [PATCH 08/11] staging: wilc1000: fix line over 80 char issue in clear_shadow_scan() Ajay Singh
2018-03-20 16:55 ` [PATCH 09/11] staging: wilc1000: remove line over 80 char in cfg_connect_result() Ajay Singh
2018-03-21  7:49   ` Dan Carpenter
2018-03-20 16:55 ` [PATCH 10/11] staging: wilc1000: remove unused 'struct add_key_params' Ajay Singh
2018-03-20 16:55 ` [PATCH 11/11] staging: wilc1000: remove line over 80 char warning in few functions Ajay Singh
2018-03-21  7:51 ` [PATCH 00/11] staging: wilc1000: fix for checkpatch and handled malloc memory properly Dan Carpenter
2018-03-21  9:20   ` Ajay Singh
2018-03-21 14:04     ` Claudiu Beznea
2018-03-27  7:22       ` Ajay Singh
2018-03-27  8:55         ` Claudiu Beznea
2018-03-27 13:16           ` Ajay Singh
2018-03-28 11:31         ` Greg KH
2018-04-04  5:15           ` Ajay Singh
2018-04-23 13:43             ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1521564944-3565-7-git-send-email-ajay.kathat@microchip.com \
    --to=ajay.kathat@microchip.com \
    --cc=adham.abozaeid@microchip.com \
    --cc=aditya.shankar@microchip.com \
    --cc=claudiu.beznea@microchip.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=ganesh.krishna@microchip.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=venkateswara.kaja@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.