Skip to contentSkip to conversation

staging: wlan-ng: make use of GENMASK macro

PATCH In review Sergio Paracuellos 2 participants 8 messages Nov 10, 2016 – Nov 15, 2016 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: wlan-ng: make use of GENMASK macro

This patchset replaces mask stuff manipulation which is being used using BIT macro with or operators with the use of GENMASK macro.

Sergio Paracuellos (4):
staging: wlan-ng: use GENMASK macro in different defines of hfa384x.h
staging: wlan-ng: use GENMASK macro in different defines of

    p80211hdr.h

staging: wlan-ng: use GENMASK macro in define of p80211netdev.h
staging: wlan-ng: use GENMASK macro in two bitwise operations in
prism2sta.c

 drivers/staging/wlan-ng/hfa384x.h      | 29 ++++++++---------------------
 drivers/staging/wlan-ng/p80211hdr.h    |  5 ++---
 drivers/staging/wlan-ng/p80211netdev.h |  2 +-
 drivers/staging/wlan-ng/prism2sta.c    |  4 ++--
 4 files changed, 13 insertions(+), 27 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/4 staging: wlan-ng: use GENMASK macro in different defines of hfa384x.h

This patch replace actual mask stuff using BIT macros with or operators to make use of GENMASK macro which simplifies code clearity and readibility.

It applies for defines included in hfa384x.h header file.

---
 drivers/staging/wlan-ng/hfa384x.h | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)
drivers/staging/wlan-ng/hfa384x.h +8 -21
index 01945a9..60caf9c3 100644
@@ -137,21 +137,11 @@
 #define		HFA384x_DLSTATE_FLASHENABLED		2
 
 /*--- Register Field Masks --------------------------*/
-#define		HFA384x_CMD_AINFO		((u16)(BIT(14) | BIT(13) \
-							| BIT(12) | BIT(11) \
-							| BIT(10) | BIT(9) \
-							| BIT(8)))
-#define		HFA384x_CMD_MACPORT		((u16)(BIT(10) | BIT(9) | \
-							BIT(8)))
-#define		HFA384x_CMD_PROGMODE		((u16)(BIT(9) | BIT(8)))
-#define		HFA384x_CMD_CMDCODE		((u16)(BIT(5) | BIT(4) | \
-							BIT(3) | BIT(2) | \
-							BIT(1) | BIT(0)))
-
-#define		HFA384x_STATUS_RESULT		((u16)(BIT(14) | BIT(13) \
-							| BIT(12) | BIT(11) \
-							| BIT(10) | BIT(9) \
-							| BIT(8)))
+#define		HFA384x_CMD_AINFO		((u16)GENMASK(14, 8))
+#define		HFA384x_CMD_MACPORT		((u16)GENMASK(10, 8))
+#define		HFA384x_CMD_PROGMODE		((u16)GENMASK(9, 8))
+#define		HFA384x_CMD_CMDCODE		((u16)GENMASK(5, 0))
+#define		HFA384x_STATUS_RESULT		((u16)GENMASK(14, 8))
 
 /*--- Command Code Constants --------------------------*/
 /*--- Controller Commands --------------------------*/
@@ -511,9 +501,8 @@ struct hfa384x_tx_frame {
 #define		HFA384x_TXSTATUS_AGEDERR		((u16)BIT(1))
 #define		HFA384x_TXSTATUS_RETRYERR		((u16)BIT(0))
 /*-- Transmit Control Field --*/
-#define		HFA384x_TX_MACPORT			((u16)(BIT(10) | \
-							  BIT(9) | BIT(8)))
-#define		HFA384x_TX_STRUCTYPE			((u16)(BIT(4) | BIT(3)))
+#define		HFA384x_TX_MACPORT			((u16)GENMASK(10, 8))
+#define		HFA384x_TX_STRUCTYPE			((u16)GENMASK(4, 3))
 #define		HFA384x_TX_TXEX				((u16)BIT(2))
 #define		HFA384x_TX_TXOK				((u16)BIT(1))
 /*--------------------------------------------------------------------
@@ -571,9 +560,7 @@ struct hfa384x_rx_frame {
  */
 
 /*-- Status Fields --*/
-#define		HFA384x_RXSTATUS_MACPORT		((u16)(BIT(10) | \
-								BIT(9) | \
-								BIT(8)))
+#define		HFA384x_RXSTATUS_MACPORT		((u16)GENMASK(10, 8))
 #define		HFA384x_RXSTATUS_FCSERR			((u16)BIT(0))
 /*--------------------------------------------------------------------
  * Communication Frames: Test/Get/Set Field Values for Receive Frames
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 1/4] staging: wlan-ng: use GENMASK macro in different defines of hfa384x.h

Quoted 1 line · Sergio Paracuellos

+#define HFA384x_CMD_AINFO ((u16)GENMASK(14, 8))

The casts to u16 are pointless because of type promotion and half of these defines aren't used anyway (both that I looked at).

regards,
dan carpenter

#3 lore raw

PATCH 2/4 staging: wlan-ng: use GENMASK macro in different defines of p80211hdr.h

In reply to Sergio Paracuellos

This patch replace actual mask stuff using BIT macros with or operators to make use of GENMASK macro which simplifies code clearity and readibility.

It applies for defines included in p80211hdr.h header file.

---
 drivers/staging/wlan-ng/p80211hdr.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/wlan-ng/p80211hdr.h +2 -3
index c8f78d9..2c44c61 100644
@@ -131,9 +131,8 @@
 /*                        SET_FC_FSTYPE(WLAN_FSTYPE_RTS) );   */
 /*------------------------------------------------------------*/
 
-#define WLAN_GET_FC_FTYPE(n)	((((u16)(n)) & (BIT(2) | BIT(3))) >> 2)
-#define WLAN_GET_FC_FSTYPE(n)	((((u16)(n)) & \
-				(BIT(4) | BIT(5) | BIT(6) | BIT(7))) >> 4)
+#define WLAN_GET_FC_FTYPE(n)	((((u16)(n)) & GENMASK(3, 2)) >> 2)
+#define WLAN_GET_FC_FSTYPE(n)	((((u16)(n)) & GENMASK(7, 4)) >> 4)
 #define WLAN_GET_FC_TODS(n)	((((u16)(n)) & (BIT(8))) >> 8)
 #define WLAN_GET_FC_FROMDS(n)	((((u16)(n)) & (BIT(9))) >> 9)
 #define WLAN_GET_FC_ISWEP(n)	((((u16)(n)) & (BIT(14))) >> 14)
Signature · 1 line
1.9.1
#4 lore raw

Re: [PATCH 2/4] staging: wlan-ng: use GENMASK macro in different defines of p80211hdr.h

drivers/staging/wlan-ng/p80211hdr.h line 135

Quoted 5 lines · Sergio Paracuellos
drivers/staging/wlan-ng/p80211hdr.h +2 -3
-#define WLAN_GET_FC_FTYPE(n)	((((u16)(n)) & (BIT(2) | BIT(3))) >> 2)
-#define WLAN_GET_FC_FSTYPE(n)	((((u16)(n)) & \
-				(BIT(4) | BIT(5) | BIT(6) | BIT(7))) >> 4)
+#define WLAN_GET_FC_FTYPE(n)	((((u16)(n)) & GENMASK(3, 2)) >> 2)
+#define WLAN_GET_FC_FSTYPE(n)	((((u16)(n)) & GENMASK(7, 4)) >> 4)

The casts to u16 are not needed.

regards,
dan carpenter

#5 lore raw

PATCH 3/4 staging: wlan-ng: use GENMASK macro in define of p80211netdev.h

In reply to Sergio Paracuellos

This patch replace actual mask stuff using BIT macros with or operators to make use of GENMASK macro which simplifies code clearity and readibility.

It applies for defines included in p80211netdev.h header file.

---
 drivers/staging/wlan-ng/p80211netdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/wlan-ng/p80211netdev.h +1 -1
index 8066ac4..8e0d082 100644
@@ -143,7 +143,7 @@ struct p80211_frmrx {
 #define NUM_WEPKEYS 4
 #define MAX_KEYLEN 32
 
-#define HOSTWEP_DEFAULTKEY_MASK (BIT(1) | BIT(0))
+#define HOSTWEP_DEFAULTKEY_MASK GENMASK(1, 0)
 #define HOSTWEP_SHAREDKEY BIT(3)
 #define HOSTWEP_DECRYPT  BIT(4)
 #define HOSTWEP_ENCRYPT  BIT(5)
Signature · 1 line
1.9.1
#6 lore raw

PATCH 4/4 staging: wlan-ng: use GENMASK macro in two bitwise operations in prism2sta.c

In reply to Sergio Paracuellos

This patch replace actual mask stuff using BIT macros with or operators to make use of GENMASK macro which simplifies code clearity and readibility.

It applies for two bitwise operations included in prism2sta.c source file.

---
 drivers/staging/wlan-ng/prism2sta.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/wlan-ng/prism2sta.c +2 -2
index 351f08d..984804b 100644
@@ -654,8 +654,8 @@ static int prism2sta_getcardinfo(struct wlandevice *wlandev)
 	hw->ident_sta_fw.minor = le16_to_cpu(hw->ident_sta_fw.minor);
 
 	/* strip out the 'special' variant bits */
-	hw->mm_mods = hw->ident_sta_fw.variant & (BIT(14) | BIT(15));
-	hw->ident_sta_fw.variant &= ~((u16)(BIT(14) | BIT(15)));
+	hw->mm_mods = hw->ident_sta_fw.variant & GENMASK(15, 14);
+	hw->ident_sta_fw.variant &= ~((u16)GENMASK(15, 14));
 
 	if (hw->ident_sta_fw.id == 0x1f) {
 		netdev_info(wlandev->netdev,
Signature · 1 line
1.9.1
#7 lore raw

Re: [PATCH 4/4] staging: wlan-ng: use GENMASK macro in two bitwise operations in prism2sta.c

Quoted 16 lines · Sergio Paracuellos

This patch replace actual mask stuff using BIT macros with or operators to make use of GENMASK macro which simplifies code clearity and readibility.

It applies for two bitwise operations included in prism2sta.c source file.

---
 drivers/staging/wlan-ng/prism2sta.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/wlan-ng/prism2sta.c +0 -0
index 351f08d..984804b 100644

drivers/staging/wlan-ng/prism2sta.c static int prism2sta_getcardinfo(struct wlandevice *wlandev) · line 658

Quoted 7 lines
drivers/staging/wlan-ng/prism2sta.c +2 -2
@@ -654,8 +654,8 @@ static int prism2sta_getcardinfo(struct wlandevice *wlandev)
 	hw->ident_sta_fw.minor = le16_to_cpu(hw->ident_sta_fw.minor);
 
 	/* strip out the 'special' variant bits */
-	hw->mm_mods = hw->ident_sta_fw.variant & (BIT(14) | BIT(15));
-	hw->ident_sta_fw.variant &= ~((u16)(BIT(14) | BIT(15)));
+	hw->mm_mods = hw->ident_sta_fw.variant & GENMASK(15, 14);
+	hw->ident_sta_fw.variant &= ~((u16)GENMASK(15, 14));

The cast is a no-op because of type promotion. It gets cast to u16 then immediately recast to int before the bitwise negate op.

regards,
dan carpenter