Skip to contentSkip to conversation

staging: r8188eu: clean up phy_CalculateBitShift()

PATCH In review Michael Straube 2 participants 5 messages Aug 6, 2022 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: r8188eu: clean up phy_CalculateBitShift()

This series simplifies the function phy_CalculateBitShift() and cleans up coding style issues in that function.

Tested on x86_64 with Inter-Tech DMG-02.

Michael Straube (3):
staging: r8188eu: use ffs() in phy_CalculateBitShift()
staging: r8188eu: avoid camel case in phy_CalculateBitShift()
staging: r8188eu: clean up comment for phy_calculate_bit_shift()

 drivers/staging/r8188eu/hal/rtl8188e_phycfg.c | 30 +++++--------------
 1 file changed, 8 insertions(+), 22 deletions(-)
Signature · 1 line
2.37.1
#1 lore raw

PATCH 1/3 staging: r8188eu: use ffs() in phy_CalculateBitShift()

Use ffs() in phy_CalculateBitShift() to simplify the function and improve readability.

---
 drivers/staging/r8188eu/hal/rtl8188e_phycfg.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/r8188eu/hal/rtl8188e_phycfg.c +2 -6
index dea6d915a1f4..3d8fcc1f0b6a 100644
@@ -25,13 +25,9 @@
 */
 static	u32 phy_CalculateBitShift(u32 BitMask)
 {
-	u32 i;
+	u32 i = ffs(BitMask);
 
-	for (i = 0; i <= 31; i++) {
-		if (((BitMask >> i) & 0x1) == 1)
-			break;
-	}
-	return i;
+	return i ? i - 1 : 32;
 }
 
 /**
Signature · 1 line
2.37.1
#2 lore raw

PATCH 2/3 staging: r8188eu: avoid camel case in phy_CalculateBitShift()

In reply to Michael Straube

Rename the function phy_CalculateBitShift() and its parameter BitMask to avoid camel case.

phy_CalculateBitShift -> phy_calculate_bit_shift
BitMask -> bitmask

---
 drivers/staging/r8188eu/hal/rtl8188e_phycfg.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/staging/r8188eu/hal/rtl8188e_phycfg.c +6 -6
index 3d8fcc1f0b6a..e9e24efabd76 100644
@@ -23,9 +23,9 @@
 * Output:	none
 * Return:		u32		Return the shift bit bit position of the mask
 */
-static	u32 phy_CalculateBitShift(u32 BitMask)
+static u32 phy_calculate_bit_shift(u32 bitmask)
 {
-	u32 i = ffs(BitMask);
+	u32 i = ffs(bitmask);
 
 	return i ? i - 1 : 32;
 }
@@ -58,7 +58,7 @@ rtl8188e_PHY_QueryBBReg(
 	if (res)
 		return 0;
 
-	BitShift = phy_CalculateBitShift(BitMask);
+	BitShift = phy_calculate_bit_shift(BitMask);
 	ReturnValue = (OriginalValue & BitMask) >> BitShift;
 	return ReturnValue;
 }
@@ -91,7 +91,7 @@ void rtl8188e_PHY_SetBBReg(struct adapter *Adapter, u32 RegAddr, u32 BitMask, u3
 		if (res)
 			return;
 
-		BitShift = phy_CalculateBitShift(BitMask);
+		BitShift = phy_calculate_bit_shift(BitMask);
 		Data = ((OriginalValue & (~BitMask)) | (Data << BitShift));
 	}
 
@@ -263,7 +263,7 @@ u32 rtl8188e_PHY_QueryRFReg(struct adapter *Adapter, u32 RegAddr, u32 BitMask)
 
 	Original_Value = phy_RFSerialRead(Adapter, RegAddr);
 
-	BitShift =  phy_CalculateBitShift(BitMask);
+	BitShift =  phy_calculate_bit_shift(BitMask);
 	Readback_Value = (Original_Value & BitMask) >> BitShift;
 	return Readback_Value;
 }
@@ -298,7 +298,7 @@ rtl8188e_PHY_SetRFReg(
 	/*  RF data is 12 bits only */
 	if (BitMask != bRFRegOffsetMask) {
 		Original_Value = phy_RFSerialRead(Adapter, RegAddr);
-		BitShift =  phy_CalculateBitShift(BitMask);
+		BitShift =  phy_calculate_bit_shift(BitMask);
 		Data = ((Original_Value & (~BitMask)) | (Data << BitShift));
 	}
 
Signature · 1 line
2.37.1
#3 lore raw

PATCH 3/3 staging: r8188eu: clean up comment for phy_calculate_bit_shift()

In reply to Michael Straube

Clean up the comment for function phy_calculate_bit_shift().

---
 drivers/staging/r8188eu/hal/rtl8188e_phycfg.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/staging/r8188eu/hal/rtl8188e_phycfg.c +1 -11
index e9e24efabd76..a435ec65d4b1 100644
@@ -12,17 +12,7 @@
 /*  1. BB register R/W API */
 /*  */
 
-/**
-* Function:	phy_CalculateBitShift
-*
-* OverView:	Get shifted position of the BitMask
-*
-* Input:
-*			u32		BitMask,
-*
-* Output:	none
-* Return:		u32		Return the shift bit bit position of the mask
-*/
+/* Get shifted position of the bit mask */
 static u32 phy_calculate_bit_shift(u32 bitmask)
 {
 	u32 i = ffs(bitmask);
Signature · 1 line
2.37.1
Tested-by on the v1 series
#4 lore raw
In reply to Michael Straube
Quoted 5 lines · Michael Straube

This series simplifies the function phy_CalculateBitShift() and cleans up coding style issues in that function.

Tested on x86_64 with Inter-Tech DMG-02.

Quoted 8 lines

Michael Straube (3):
staging: r8188eu: use ffs() in phy_CalculateBitShift()
staging: r8188eu: avoid camel case in phy_CalculateBitShift()
staging: r8188eu: clean up comment for phy_calculate_bit_shift()

  drivers/staging/r8188eu/hal/rtl8188e_phycfg.c | 30 +++++--------------
  1 file changed, 8 insertions(+), 22 deletions(-)