lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1471706400-13264-1-git-send-email-claudiu.beznea@gmail.com>
Date:   Sat, 20 Aug 2016 18:20:00 +0300
From:   Claudiu Beznea <claudiu.beznea@...il.com>
To:     gregkh@...uxfoundation.org
Cc:     devel@...verdev.osuosl.org, linux-kernel@...r.kernel.org,
        Claudiu Beznea <claudiu.beznea@...il.com>
Subject: [PATCH] Staging: wlan-ng: improved code in p80211req.c file

This patch improves code from p80211req.c file by removing
duplicate code, by keeping count of returning code of
the called functions and also aesthetically.

Signed-off-by: Claudiu Beznea <claudiu.beznea@...il.com>
---
 drivers/staging/wlan-ng/p80211req.c | 163 +++++++++++++++++++-----------------
 1 file changed, 84 insertions(+), 79 deletions(-)

diff --git a/drivers/staging/wlan-ng/p80211req.c b/drivers/staging/wlan-ng/p80211req.c
index 4b84b56..900635e 100644
--- a/drivers/staging/wlan-ng/p80211req.c
+++ b/drivers/staging/wlan-ng/p80211req.c
@@ -72,10 +72,12 @@
 #include "p80211metastruct.h"
 #include "p80211req.h"
 
-static void p80211req_handlemsg(wlandevice_t *wlandev, struct p80211msg *msg);
-static void p80211req_mibset_mibget(wlandevice_t *wlandev,
+static int p80211req_handlemsg(wlandevice_t *wlandev, struct p80211msg *msg);
+static int p80211req_mibset_mibget(wlandevice_t *wlandev,
 				   struct p80211msg_dot11req_mibget *mib_msg,
 				   int isget);
+static void p80211req_handle_action(struct wlandevice *wlandev, u32 *data,
+				    int isget, u32 flag);
 
 /*----------------------------------------------------------------
 * p80211req_dorequest
@@ -96,6 +98,7 @@ static void p80211req_mibset_mibget(wlandevice_t *wlandev,
 int p80211req_dorequest(wlandevice_t *wlandev, u8 *msgbuf)
 {
 	struct p80211msg *msg = (struct p80211msg *) msgbuf;
+	int rc = 0;
 
 	/* Check to make sure the MSD is running */
 	if (!((wlandev->msdstate == WLAN_MSD_HWPRESENT &&
@@ -107,7 +110,7 @@ int p80211req_dorequest(wlandevice_t *wlandev, u8 *msgbuf)
 
 	/* Check Permissions */
 	if (!capable(CAP_NET_ADMIN) &&
-	(msg->msgcode != DIDmsg_dot11req_mibget)) {
+	    (msg->msgcode != DIDmsg_dot11req_mibget)) {
 		netdev_err(wlandev->netdev,
 			   "%s: only dot11req_mibget allowed for non-root.\n",
 			   wlandev->name);
@@ -115,20 +118,23 @@ int p80211req_dorequest(wlandevice_t *wlandev, u8 *msgbuf)
 	}
 
 	/* Check for busy status */
-	if (test_and_set_bit(1, &(wlandev->request_pending)))
+	if (test_and_set_bit(1, &wlandev->request_pending))
 		return -EBUSY;
 
 	/* Allow p80211 to look at msg and handle if desired. */
 	/* So far, all p80211 msgs are immediate, no waitq/timer necessary */
 	/* This may change. */
-	p80211req_handlemsg(wlandev, msg);
+	rc = p80211req_handlemsg(wlandev, msg);
+	if (rc != 0)
+		goto exit;
 
 	/* Pass it down to wlandev via wlandev->mlmerequest */
 	if (wlandev->mlmerequest != NULL)
-		wlandev->mlmerequest(wlandev, msg);
+		rc = wlandev->mlmerequest(wlandev, msg);
 
-	clear_bit(1, &(wlandev->request_pending));
-	return 0;	/* if result==0, msg->status still may contain an err */
+exit:
+	clear_bit(1, &wlandev->request_pending);
+	return rc;	/* if result==0, msg->status still may contain an err */
 }
 
 /*----------------------------------------------------------------
@@ -149,64 +155,63 @@ int p80211req_dorequest(wlandevice_t *wlandev, u8 *msgbuf)
 * Call context:
 *	Process thread
 ----------------------------------------------------------------*/
-static void p80211req_handlemsg(wlandevice_t *wlandev, struct p80211msg *msg)
+static int p80211req_handlemsg(wlandevice_t *wlandev, struct p80211msg *msg)
 {
-	switch (msg->msgcode) {
+	struct p80211msg_lnxreq_hostwep *req;
+	struct p80211msg_dot11req_mibget *mib_msg;
+	int isget;
+	int rc = 0;
 
-	case DIDmsg_lnxreq_hostwep:{
-		struct p80211msg_lnxreq_hostwep *req =
-			(struct p80211msg_lnxreq_hostwep *) msg;
-		wlandev->hostwep &=
-				~(HOSTWEP_DECRYPT | HOSTWEP_ENCRYPT);
+	switch (msg->msgcode) {
+	case DIDmsg_lnxreq_hostwep:
+		req = (struct p80211msg_lnxreq_hostwep *)msg;
+		wlandev->hostwep &= ~(HOSTWEP_DECRYPT | HOSTWEP_ENCRYPT);
 		if (req->decrypt.data == P80211ENUM_truth_true)
 			wlandev->hostwep |= HOSTWEP_DECRYPT;
 		if (req->encrypt.data == P80211ENUM_truth_true)
 			wlandev->hostwep |= HOSTWEP_ENCRYPT;
 
-	break;
-	}
+		break;
+
 	case DIDmsg_dot11req_mibget:
-	case DIDmsg_dot11req_mibset:{
-		int isget = (msg->msgcode == DIDmsg_dot11req_mibget);
-		struct p80211msg_dot11req_mibget *mib_msg =
-			(struct p80211msg_dot11req_mibget *) msg;
-		p80211req_mibset_mibget(wlandev, mib_msg, isget);
-	break;
+	case DIDmsg_dot11req_mibset:
+		isget = (msg->msgcode == DIDmsg_dot11req_mibget);
+		mib_msg = (struct p80211msg_dot11req_mibget *)msg;
+		rc = p80211req_mibset_mibget(wlandev, mib_msg, isget);
+
+		break;
 	}
-	}			/* switch msg->msgcode */
+
+	return rc;
 }
 
-static void p80211req_mibset_mibget(wlandevice_t *wlandev,
+static int p80211req_mibset_mibget(wlandevice_t *wlandev,
 				   struct p80211msg_dot11req_mibget *mib_msg,
 				   int isget)
 {
-	p80211itemd_t *mibitem = (p80211itemd_t *) mib_msg->mibattribute.data;
-	p80211pstrd_t *pstr = (p80211pstrd_t *) mibitem->data;
-	u8 *key = mibitem->data + sizeof(p80211pstrd_t);
+	struct p80211itemd *mibitem =
+			(struct p80211itemd *)mib_msg->mibattribute.data;
+	struct p80211pstrd *pstr;
+	u8 *key;
+	u32 *data;
+	int rc = 0;
 
 	switch (mibitem->did) {
-	case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0:{
-		if (!isget)
-			wep_change_key(wlandev, 0, key, pstr->len);
-	break;
-	}
-	case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1:{
-		if (!isget)
-			wep_change_key(wlandev, 1, key, pstr->len);
-	break;
-	}
-	case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2:{
-		if (!isget)
-			wep_change_key(wlandev, 2, key, pstr->len);
-	break;
-	}
-	case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3:{
-		if (!isget)
-			wep_change_key(wlandev, 3, key, pstr->len);
-	break;
-	}
-	case DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID:{
-		u32 *data = (u32 *) mibitem->data;
+	case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0:
+	case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1:
+	case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2:
+	case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3:
+		if (!isget) {
+			pstr = (struct p80211pstrd *)mibitem->data;
+			key = mibitem->data + sizeof(struct p80211pstrd);
+			rc = wep_change_key(wlandev,
+					    P80211DID_ITEM(mibitem->did) - 1,
+					    key, pstr->len);
+		}
+		break;
+
+	case DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID:
+		data = (u32 *)mibitem->data;
 
 		if (isget) {
 			*data = wlandev->hostwep & HOSTWEP_DEFAULTKEY_MASK;
@@ -214,37 +219,37 @@ static void p80211req_mibset_mibget(wlandevice_t *wlandev,
 			wlandev->hostwep &= ~(HOSTWEP_DEFAULTKEY_MASK);
 			wlandev->hostwep |= (*data & HOSTWEP_DEFAULTKEY_MASK);
 		}
-	break;
-	}
-	case DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked:{
-		u32 *data = (u32 *) mibitem->data;
+		break;
 
-		if (isget) {
-			if (wlandev->hostwep & HOSTWEP_PRIVACYINVOKED)
-				*data = P80211ENUM_truth_true;
-			else
-				*data = P80211ENUM_truth_false;
-		} else {
-			wlandev->hostwep &= ~(HOSTWEP_PRIVACYINVOKED);
-			if (*data == P80211ENUM_truth_true)
-				wlandev->hostwep |= HOSTWEP_PRIVACYINVOKED;
-		}
-	break;
-	}
-	case DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted:{
-		u32 *data = (u32 *) mibitem->data;
+	case DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked:
+		data = (u32 *)mibitem->data;
 
-		if (isget) {
-			if (wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED)
-				*data = P80211ENUM_truth_true;
-			else
-				*data = P80211ENUM_truth_false;
-		} else {
-			wlandev->hostwep &= ~(HOSTWEP_EXCLUDEUNENCRYPTED);
-			if (*data == P80211ENUM_truth_true)
-				wlandev->hostwep |= HOSTWEP_EXCLUDEUNENCRYPTED;
-		}
-	break;
+		p80211req_handle_action(wlandev, data, isget,
+					HOSTWEP_PRIVACYINVOKED);
+		break;
+
+	case DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted:
+		data = (u32 *)mibitem->data;
+
+		p80211req_handle_action(wlandev, data, isget,
+					HOSTWEP_EXCLUDEUNENCRYPTED);
+		break;
 	}
+
+	return rc;
+}
+
+static void p80211req_handle_action(struct wlandevice *wlandev, u32 *data,
+				    int isget, u32 flag)
+{
+	if (isget) {
+		if (wlandev->hostwep & flag)
+			*data = P80211ENUM_truth_true;
+		else
+			*data = P80211ENUM_truth_false;
+	} else {
+		wlandev->hostwep &= ~flag;
+		if (*data == P80211ENUM_truth_true)
+			wlandev->hostwep |= flag;
 	}
 }
-- 
1.9.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ