[OPW,kernel] staging: rtl8192: introduce temprary variables to improve readability
diff mbox

Message ID 20141029121049.GA15408@localhost
State New, archived
Headers show

Commit Message

Jiayi Ye Oct. 29, 2014, 12:10 p.m. UTC
Introduce some temprary variables to make the code a little more readable.

Signed-off-by: Jiayi Ye <yejiayily@gmail.com>
---
 drivers/staging/rtl8192e/rtl8192e/rtl_dm.c | 37 ++++++++++++++------------
 drivers/staging/rtl8192u/r8192U_dm.c       | 42 ++++++++++++++++--------------
 2 files changed, 43 insertions(+), 36 deletions(-)

Comments

Greg Kroah-Hartman Oct. 29, 2014, 11:04 p.m. UTC | #1
On Wed, Oct 29, 2014 at 08:10:49PM +0800, Jiayi Ye wrote:
> Introduce some temprary variables to make the code a little more readable.
> 
> Signed-off-by: Jiayi Ye <yejiayily@gmail.com>
> ---
>  drivers/staging/rtl8192e/rtl8192e/rtl_dm.c | 37 ++++++++++++++------------
>  drivers/staging/rtl8192u/r8192U_dm.c       | 42 ++++++++++++++++--------------
>  2 files changed, 43 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
> index 885315c..daa4d83 100644
> --- a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
> +++ b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
> @@ -1444,32 +1444,37 @@ static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool  bInCH14)
>  	struct r8192_priv *priv = rtllib_priv(dev);
>  
>  	TempVal = 0;
> +	u8 CCKPresentAttentuation = (u8)(priv->CCKPresentAttentuation);

This line should have given you a build warning, right?  That's not ok
:(

>  	if (!bInCH14) {
> -		TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[0] +
> -			  (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[1]<<8)) ;
> +		struct ccktxbbgain cck_txbbgain_table_item =
> +						priv->cck_txbbgain_table[CCKPresentAttentuation];
> +		TempVal = (u32)(cck_txbbgain_table_item.ccktxbb_valuearray[0] +
> +			  (cck_txbbgain_table_item.ccktxbb_valuearray[1] << 8));
>  
>  		rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
> -		TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[2] +
> -			  (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[3]<<8) +
> -			  (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[4]<<16)+
> -			  (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[5]<<24));
> +		TempVal = (u32)(cck_txbbgain_table_item.ccktxbb_valuearray[2] +
> +			  (cck_txbbgain_table_item.ccktxbb_valuearray[3] << 8) +
> +			  (cck_txbbgain_table_item.ccktxbb_valuearray[4] << 16)+
> +			  (cck_txbbgain_table_item.ccktxbb_valuearray[5] << 24));
>  		rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
> -		TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[6] +
> -			  (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[7]<<8)) ;
> +		TempVal = (u32)(cck_txbbgain_table_item.ccktxbb_valuearray[6] +
> +			  (cck_txbbgain_table_item.ccktxbb_valuearray[7] << 8));
>  
>  		rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
>  	} else {
> -		TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[0] +
> -			  (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[1]<<8)) ;
> +		struct ccktxbbgain cck_txbbgain_ch14_table_item =
> +						priv->cck_txbbgain_ch14_table[CCKPresentAttentuation];
> +		TempVal = (u32)(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[0] +
> +			  (cck_txbbgain_ch14_table_item.ccktxbb_valuearray[1] << 8)) ;
>  
>  		rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
> -		TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[2] +
> -			  (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[3]<<8) +
> -			  (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[4]<<16)+
> -			  (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[5]<<24));
> +		TempVal = (u32)(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[2] +
> +			  (cck_txbbgain_ch14_table_item.ccktxbb_valuearray[3] << 8) +
> +			  (cck_txbbgain_ch14_table_item.ccktxbb_valuearray[4] << 16)+
> +			  (cck_txbbgain_ch14_table_item.ccktxbb_valuearray[5] << 24));
>  		rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
> -		TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[6] +
> -			  (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[7]<<8)) ;
> +		TempVal = (u32)(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[6] +
> +			  (cck_txbbgain_ch14_table_item.ccktxbb_valuearray[7] << 8)) ;
>  
>  		rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
>  	}
> diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c
> index 936565d..e92fabd 100644
> --- a/drivers/staging/rtl8192u/r8192U_dm.c
> +++ b/drivers/staging/rtl8192u/r8192U_dm.c
> @@ -1469,40 +1469,42 @@ static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool  bInCH14)
>  	struct r8192_priv *priv = ieee80211_priv(dev);
>  	//Write 0xa22 0xa23
>  	TempVal = 0;
> +	s8 cck_present_attentuation = priv->cck_present_attentuation;
>  	if(!bInCH14){
> +		struct ccktxbbgain cck_txbbgain_table_item =
> +					priv->cck_txbbgain_table[cck_present_attentuation];
>  		//Write 0xa22 0xa23
> -		TempVal =	priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] +
> -					(priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8) ;
> -
> +		TempVal = cck_txbbgain_table_item.ccktxbb_valuearray[0] +
> +				(cck_txbbgain_table_item.ccktxbb_valuearray[1] << 8);
>  		rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
>  		//Write 0xa24 ~ 0xa27
> -		TempVal =	priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] +
> -					(priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) +
> -					(priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16)+
> -					(priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24);
> +		TempVal = cck_txbbgain_table_item.ccktxbb_valuearray[2] +
> +				(cck_txbbgain_table_item.ccktxbb_valuearray[3] << 8) +
> +				(cck_txbbgain_table_item.ccktxbb_valuearray[4] << 16) +
> +				(cck_txbbgain_table_item.ccktxbb_valuearray[5] << 24);
>  		rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
>  		//Write 0xa28  0xa29
> -		TempVal =	priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] +
> -					(priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ;
> -
> +		TempVal = cck_txbbgain_table_item.ccktxbb_valuearray[6] +
> +				(cck_txbbgain_table_item.ccktxbb_valuearray[7] << 8);
>  		rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
>  	}
>  	else
>  	{
> -		TempVal =	priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] +
> -					(priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8) ;
> -
> +		struct ccktxbbgain cck_txbbgain_ch14_table_item =
> +					priv->cck_txbbgain_ch14_table[cck_present_attentuation];
> +		//Write 0xa22 0xa23
> +		TempVal = cck_txbbgain_ch14_table_item.ccktxbb_valuearray[0] +
> +				(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[1] << 8);
>  		rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
>  		//Write 0xa24 ~ 0xa27
> -		TempVal =	priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] +
> -					(priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) +
> -					(priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16)+
> -					(priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24);
> +		TempVal = cck_txbbgain_ch14_table_item.ccktxbb_valuearray[2] +
> +				(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[3] << 8) +
> +				(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[4] << 16)+
> +				(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[5] << 24);
>  		rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
>  		//Write 0xa28  0xa29
> -		TempVal =	priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] +
> -					(priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ;
> -
> +		TempVal = cck_txbbgain_ch14_table_item.ccktxbb_valuearray[6] +
> +				(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[7] << 8) ;
>  		rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
>  	}

I don't see this being any more "readable", do you?  It's still a mess
:(

Patch
diff mbox

diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
index 885315c..daa4d83 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
@@ -1444,32 +1444,37 @@  static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool  bInCH14)
 	struct r8192_priv *priv = rtllib_priv(dev);
 
 	TempVal = 0;
+	u8 CCKPresentAttentuation = (u8)(priv->CCKPresentAttentuation);
 	if (!bInCH14) {
-		TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[0] +
-			  (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[1]<<8)) ;
+		struct ccktxbbgain cck_txbbgain_table_item =
+						priv->cck_txbbgain_table[CCKPresentAttentuation];
+		TempVal = (u32)(cck_txbbgain_table_item.ccktxbb_valuearray[0] +
+			  (cck_txbbgain_table_item.ccktxbb_valuearray[1] << 8));
 
 		rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
-		TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[2] +
-			  (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[3]<<8) +
-			  (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[4]<<16)+
-			  (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[5]<<24));
+		TempVal = (u32)(cck_txbbgain_table_item.ccktxbb_valuearray[2] +
+			  (cck_txbbgain_table_item.ccktxbb_valuearray[3] << 8) +
+			  (cck_txbbgain_table_item.ccktxbb_valuearray[4] << 16)+
+			  (cck_txbbgain_table_item.ccktxbb_valuearray[5] << 24));
 		rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
-		TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[6] +
-			  (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[7]<<8)) ;
+		TempVal = (u32)(cck_txbbgain_table_item.ccktxbb_valuearray[6] +
+			  (cck_txbbgain_table_item.ccktxbb_valuearray[7] << 8));
 
 		rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
 	} else {
-		TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[0] +
-			  (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[1]<<8)) ;
+		struct ccktxbbgain cck_txbbgain_ch14_table_item =
+						priv->cck_txbbgain_ch14_table[CCKPresentAttentuation];
+		TempVal = (u32)(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[0] +
+			  (cck_txbbgain_ch14_table_item.ccktxbb_valuearray[1] << 8)) ;
 
 		rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
-		TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[2] +
-			  (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[3]<<8) +
-			  (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[4]<<16)+
-			  (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[5]<<24));
+		TempVal = (u32)(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[2] +
+			  (cck_txbbgain_ch14_table_item.ccktxbb_valuearray[3] << 8) +
+			  (cck_txbbgain_ch14_table_item.ccktxbb_valuearray[4] << 16)+
+			  (cck_txbbgain_ch14_table_item.ccktxbb_valuearray[5] << 24));
 		rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
-		TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[6] +
-			  (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[7]<<8)) ;
+		TempVal = (u32)(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[6] +
+			  (cck_txbbgain_ch14_table_item.ccktxbb_valuearray[7] << 8)) ;
 
 		rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
 	}
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c
index 936565d..e92fabd 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -1469,40 +1469,42 @@  static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool  bInCH14)
 	struct r8192_priv *priv = ieee80211_priv(dev);
 	//Write 0xa22 0xa23
 	TempVal = 0;
+	s8 cck_present_attentuation = priv->cck_present_attentuation;
 	if(!bInCH14){
+		struct ccktxbbgain cck_txbbgain_table_item =
+					priv->cck_txbbgain_table[cck_present_attentuation];
 		//Write 0xa22 0xa23
-		TempVal =	priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] +
-					(priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8) ;
-
+		TempVal = cck_txbbgain_table_item.ccktxbb_valuearray[0] +
+				(cck_txbbgain_table_item.ccktxbb_valuearray[1] << 8);
 		rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
 		//Write 0xa24 ~ 0xa27
-		TempVal =	priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] +
-					(priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) +
-					(priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16)+
-					(priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24);
+		TempVal = cck_txbbgain_table_item.ccktxbb_valuearray[2] +
+				(cck_txbbgain_table_item.ccktxbb_valuearray[3] << 8) +
+				(cck_txbbgain_table_item.ccktxbb_valuearray[4] << 16) +
+				(cck_txbbgain_table_item.ccktxbb_valuearray[5] << 24);
 		rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
 		//Write 0xa28  0xa29
-		TempVal =	priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] +
-					(priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ;
-
+		TempVal = cck_txbbgain_table_item.ccktxbb_valuearray[6] +
+				(cck_txbbgain_table_item.ccktxbb_valuearray[7] << 8);
 		rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
 	}
 	else
 	{
-		TempVal =	priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] +
-					(priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8) ;
-
+		struct ccktxbbgain cck_txbbgain_ch14_table_item =
+					priv->cck_txbbgain_ch14_table[cck_present_attentuation];
+		//Write 0xa22 0xa23
+		TempVal = cck_txbbgain_ch14_table_item.ccktxbb_valuearray[0] +
+				(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[1] << 8);
 		rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
 		//Write 0xa24 ~ 0xa27
-		TempVal =	priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] +
-					(priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) +
-					(priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16)+
-					(priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24);
+		TempVal = cck_txbbgain_ch14_table_item.ccktxbb_valuearray[2] +
+				(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[3] << 8) +
+				(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[4] << 16)+
+				(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[5] << 24);
 		rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
 		//Write 0xa28  0xa29
-		TempVal =	priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] +
-					(priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ;
-
+		TempVal = cck_txbbgain_ch14_table_item.ccktxbb_valuearray[6] +
+				(cck_txbbgain_ch14_table_item.ccktxbb_valuearray[7] << 8) ;
 		rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
 	}