Staging: vt6655: Refactor switch case statement.
PATCH 1/1 Staging: vt6655: Refactor switch case statement.
Replaces nested if-else within switch case with ternary logic and variable setting to limit returns. Exposes primary logic to aid readability.
--- drivers/staging/vt6655/rxtx.c | 101 +++++++++++++--------------------- 1 file changed, 39 insertions(+), 62 deletions(-)
drivers/staging/vt6655/rxtx.c +39 -62
@@ -240,6 +240,7 @@ s_uGetDataDuration( {bool bLastFrag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true;
@@ -254,17 +255,18 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength; + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopCCKBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , pDevice->byTopCCKBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -277,17 +279,18 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength; + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -300,35 +303,24 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); - } +if (wRate <RATE_18M ) + wRate =RATE_18M ; +else if (wRate >RATE_54M ) + wRate =RATE_54M ; + + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength; +/* (byFBOption == AUTO_FB_0 || byFBOption == AUTO_FB_1) */ + uNextPktTime = (byFBOption ==AUTO_FB_0 ) ?s_uGetTxRsvTime (pDevice, byPktType, len, wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], bNeedAck) : +s_uGetTxRsvTime (pDevice, byPktType, len, wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], bNeedAck);if (bNeedAck) { uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -341,34 +333,19 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); - } + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength; +/* (byFBOption == AUTO_FB_0 || byFBOption == AUTO_FB_1) */ + uNextPktTime = (byFBOption ==AUTO_FB_0 ) ?s_uGetTxRsvTime (pDevice, byPktType, len, wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], bNeedAck) : + s_uGetTxRsvTime(pDevice, byPktType, len, wFB_Opt1[FB_RATE0][wRate - RATE_18M], bNeedAck) +if (bNeedAck) { uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; }else { -return pDevice->uSIFS + uNextPktTime; + uAcktime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
Signature · 1 line
2.24.1
Greg KH
maintainerQuoted 3 lines · Briana Oursler
Replaces nested if-else within switch case with ternary logic and variable setting to limit returns. Exposes primary logic to aid readability.
Wrap your changelog at the same size for each line, don't make it up :)
Quoted 5 lines
Signed-off-by Briana Oursler <[email protected]>--- drivers/staging/vt6655/rxtx.c | 101 +++++++++++++--------------------- 1 file changed, 39 insertions(+), 62 deletions(-)
Where did the "}" character come from on the subject line?
Quoted 14 lines
drivers/staging/vt6655/rxtx.c +1
-0@@ -240,6 +240,7 @@ s_uGetDataDuration( {bool bLastFrag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true;
drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 259
Quoted 9 lines
drivers/staging/vt6655/rxtx.c +2
-4@@ -254,17 +255,18 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength;
Ugh, I hate ? : logic.
Spell it out, be specific, this is just much harder to read now than before.
drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 264
Quoted 7 lines
drivers/staging/vt6655/rxtx.c +3
-2+ uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopCCKBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , pDevice->byTopCCKBasicRate);
You didn't wrap this properly?
Quoted 10 lines
drivers/staging/vt6655/rxtx.c +3
-1}else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 283
Quoted 9 lines
drivers/staging/vt6655/rxtx.c +2
-4@@ -277,17 +279,18 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength;
Same here, this makes it harder to understand.
thanks,
greg k-h
Quoted 8 lines · Greg KH
Quoted 4 lines · Briana Oursler
Replaces nested if-else within switch case with ternary logic and variable
setting to limit returns. Exposes primary logic to aid readability.Wrap your changelog at the same size for each line, don't make it up :)
Thanks, I will avoid wrapping them manually going forward.
Quoted 38 lines
Quoted 6 lines
Signed-off-by Briana Oursler <[email protected]>--- drivers/staging/vt6655/rxtx.c | 101 +++++++++++++----------------- ---- 1 file changed, 39 insertions(+), 62 deletions(-)Where did the "}" character come from on the subject line?
Quoted 15 lines
drivers/staging/vt6655/rxtx.c +1
-0@@ -240,6 +240,7 @@ s_uGetDataDuration( {bool bLastFrag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true;@@ -254,17 +255,18 @@ s_uGetDataDuration(return 0 ;drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 261
Quoted 10 lines
drivers/staging/vt6655/rxtx.c +2
-4} }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength;Ugh, I hate ? : logic.
Quoted 2 lines
Spell it out, be specific, this is just much harder to read now than before.
I'll remove the ternary logic. Would it be better to use a bool and if/else to determine the uNextPktTime? I think changing it to a bool instead would have the advantage that it would match a strategy used elsewhere on that same switch case with bNeedAck. Should I perhaps resubmit using that strategy? Or would it be better for me to either leave this one as is or go back to the drawing board on it?
Quoted 7 lines
Quoted 7 lines
drivers/staging/vt6655/rxtx.c +1
-1+ uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice- >byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
Quoted 9 lines
Quoted 6 lines
drivers/staging/vt6655/rxtx.c +2
-1-return pDevice->uSIFS + uAckTime +uNextPktTime ; + uAckTime = BBuGetFrameTime(pDevice- >byPreambleType, + byPktType,14,
pDevice->byTopCCKBasicRate);You didn't wrap this properly?
Sorry, I'll fix that.
Quoted 26 lines
Quoted 13 lines
drivers/staging/vt6655/rxtx.c +3
-1}else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + + return pDevice->uSIFS + uAckTime +uNextPktTime;
drivers/staging/vt6655/rxtx.c +0
-0}break ;@@ -277,17 +279,18 @@ s_uGetDataDuration(return 0 ;drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 285
Quoted 10 lines
drivers/staging/vt6655/rxtx.c +2
-4} }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength;Same here, this makes it harder to understand.
Quoted 3 lines
thanks,
greg k-h
Thanks for the input, I appreciate it.
--Briana
Quoted 114 lines · Briana Oursler
Quoted 9 lines · Greg KH
Quoted 4 lines · Briana Oursler
Replaces nested if-else within switch case with ternary logic and variable
setting to limit returns. Exposes primary logic to aid readability.Wrap your changelog at the same size for each line, don't make it up
:)Thanks, I will avoid wrapping them manually going forward.
Quoted 38 lines
Quoted 6 lines
Signed-off-by Briana Oursler <[email protected]>--- drivers/staging/vt6655/rxtx.c | 101 +++++++++++++--------------- -- ---- 1 file changed, 39 insertions(+), 62 deletions(-)Where did the "}" character come from on the subject line?
Quoted 15 lines
drivers/staging/vt6655/rxtx.c +1
-0@@ -240,6 +240,7 @@ s_uGetDataDuration( {bool bLastFrag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true;@@ -254,17 +255,18 @@ s_uGetDataDuration(return 0 ;drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 261
Quoted 10 lines
drivers/staging/vt6655/rxtx.c +2
-4} }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength;Ugh, I hate ? : logic.
Quoted 3 lines
Spell it out, be specific, this is just much harder to read now than
before.I'll remove the ternary logic. Would it be better to use a bool and if/else to determine the uNextPktTime? I think changing it to a bool instead would have the advantage that it would match a strategy used elsewhere on that same switch case with bNeedAck. Should I perhaps resubmit using that strategy? Or would it be better for me to either leave this one as is or go back to the drawing board on it?
Quoted 6 lines
Quoted 6 lines
drivers/staging/vt6655/rxtx.c +1
-1+ uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice- > byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);Quoted 9 lines
Quoted 6 lines
drivers/staging/vt6655/rxtx.c +2
-1-return pDevice->uSIFS + uAckTime +uNextPktTime ; + uAckTime = BBuGetFrameTime(pDevice- > byPreambleType, + byPktType,14,
pDevice->byTopCCKBasicRate);You didn't wrap this properly?
Sorry, I'll fix that.
Quoted 25 lines
Quoted 12 lines
drivers/staging/vt6655/rxtx.c +3
-1}else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + + return pDevice->uSIFS + uAckTime +uNextPktTime;
drivers/staging/vt6655/rxtx.c +0
-0}break ;@@ -277,17 +279,18 @@ s_uGetDataDuration(return 0 ;drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 285
Quoted 10 lines
drivers/staging/vt6655/rxtx.c +2
-4} }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength;Same here, this makes it harder to understand.
Quoted 3 lines
thanks,
greg k-h
Thanks for the input, I appreciate it.
--Briana
Quoted 8 lines · Greg KH
Quoted 4 lines · Briana Oursler
Replaces nested if-else within switch case with ternary logic and variable
setting to limit returns. Exposes primary logic to aid readability.Wrap your changelog at the same size for each line, don't make it up :)
Thanks, I will avoid wrapping them manually going forward.
Quoted 38 lines
Quoted 6 lines
Signed-off-by Briana Oursler <[email protected]>--- drivers/staging/vt6655/rxtx.c | 101 +++++++++++++----------------- ---- 1 file changed, 39 insertions(+), 62 deletions(-)Where did the "}" character come from on the subject line?
Quoted 15 lines
drivers/staging/vt6655/rxtx.c +1
-0@@ -240,6 +240,7 @@ s_uGetDataDuration( {bool bLastFrag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true;@@ -254,17 +255,18 @@ s_uGetDataDuration(return 0 ;drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 261
Quoted 10 lines
drivers/staging/vt6655/rxtx.c +2
-4} }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength;Ugh, I hate ? : logic.
Quoted 2 lines
Spell it out, be specific, this is just much harder to read now than before.
I'll remove the ternary logic. Would it be better to use a bool and if/else to determine the uNextPktTime? I think changing it to a bool instead would have the advantage that it would match a strategy used elsewhere on that same switch case with bNeedAck. Should I perhaps resubmit using that strategy? Or would it be better for me to either leave this one as is or go back to the drawing board on it?
Quoted 7 lines
Quoted 7 lines
drivers/staging/vt6655/rxtx.c +1
-1+ uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice- >byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
Quoted 9 lines
Quoted 6 lines
drivers/staging/vt6655/rxtx.c +2
-1-return pDevice->uSIFS + uAckTime +uNextPktTime ; + uAckTime = BBuGetFrameTime(pDevice- >byPreambleType, + byPktType,14,
pDevice->byTopCCKBasicRate);You didn't wrap this properly?
Sorry, I'll fix that.
Quoted 26 lines
Quoted 13 lines
drivers/staging/vt6655/rxtx.c +3
-1}else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + + return pDevice->uSIFS + uAckTime +uNextPktTime;
drivers/staging/vt6655/rxtx.c +0
-0}break ;@@ -277,17 +279,18 @@ s_uGetDataDuration(return 0 ;drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 285
Quoted 10 lines
drivers/staging/vt6655/rxtx.c +2
-4} }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength;Same here, this makes it harder to understand.
Quoted 3 lines
thanks,
greg k-h
Thanks for the input, I appreciate it.
--Briana
Quoted 8 lines · Greg KH
Quoted 4 lines · Briana Oursler
Replaces nested if-else within switch case with ternary logic and variable
setting to limit returns. Exposes primary logic to aid readability.Wrap your changelog at the same size for each line, don't make it up :)
Thanks, I will avoid wrapping them manually going forward.
Quoted 38 lines
Quoted 6 lines
Signed-off-by Briana Oursler <[email protected]>--- drivers/staging/vt6655/rxtx.c | 101 +++++++++++++----------------- ---- 1 file changed, 39 insertions(+), 62 deletions(-)Where did the "}" character come from on the subject line?
Quoted 15 lines
drivers/staging/vt6655/rxtx.c +1
-0@@ -240,6 +240,7 @@ s_uGetDataDuration( {bool bLastFrag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true;@@ -254,17 +255,18 @@ s_uGetDataDuration(return 0 ;drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 261
Quoted 10 lines
drivers/staging/vt6655/rxtx.c +2
-4} }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength;Ugh, I hate ? : logic.
Quoted 2 lines
Spell it out, be specific, this is just much harder to read now than before.
I'll remove the ternary logic. Would it be better to use a bool and if/else to determine the uNextPktTime? I think changing it to a bool instead would have the advantage that it would match a strategy used elsewhere on that same switch case with bNeedAck. Should I perhaps resubmit using that strategy? Or would it be better for me to either leave this one as is or go back to the drawing board on it?
Quoted 7 lines
Quoted 7 lines
drivers/staging/vt6655/rxtx.c +1
-1+ uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice- >byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
Quoted 9 lines
Quoted 6 lines
drivers/staging/vt6655/rxtx.c +2
-1-return pDevice->uSIFS + uAckTime +uNextPktTime ; + uAckTime = BBuGetFrameTime(pDevice- >byPreambleType, + byPktType,14,
pDevice->byTopCCKBasicRate);You didn't wrap this properly?
Sorry, I'll fix that.
Quoted 26 lines
Quoted 13 lines
drivers/staging/vt6655/rxtx.c +3
-1}else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + + return pDevice->uSIFS + uAckTime +uNextPktTime;
drivers/staging/vt6655/rxtx.c +0
-0}break ;@@ -277,17 +279,18 @@ s_uGetDataDuration(return 0 ;drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 285
Quoted 10 lines
drivers/staging/vt6655/rxtx.c +2
-4} }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + len = (uMacfragNum -2 == uFragIdx) ? + cbLastFragmentSize : cbFrameLength;Same here, this makes it harder to understand.
Quoted 3 lines
thanks,
greg k-h
Thanks for the input, I appreciate it.
--Briana
PATCH v2 1/1 Staging: vt6655: Refactor switch case statement.
In reply to Greg KHPulls some logic branches above switch case and holds outcomes in variables to improve readability and reduce code duplication within switch case.
---
Changes in v2:
- Removes ternary logic.
switch case.
- Introduces 'flag' bool.
- Moves len definition above switch case.
drivers/staging/vt6655/rxtx.c | 128 ++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 62 deletions(-)
drivers/staging/vt6655/rxtx.c +66 -62
@@ -239,11 +239,21 @@ s_uGetDataDuration( ) {bool bLastFrag = false; +bool flag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true; +if (uFragIdx == (uMACfragNum -2 )) + len = cbLastFragmentSize; +else + len = cbFrameLength; + +if (byFBOption ==AUTO_FB_0 ) + flag = true; +switch (byDurType) {case DATADUR_B :/* DATADUR_B */ if (((uMACfragNum ==1 )) || bLastFrag) {/* Non Frag or Last Frag */
@@ -254,17 +264,17 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopCCKBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopCCKBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -277,17 +287,18 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, + wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -300,35 +311,33 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); +if (wRate <RATE_18M ) + wRate =RATE_18M ; +else if (wRate >RATE_54M ) + wRate =RATE_54M ; + +/* flag true if (byFBOption == AUTO_FB_0) */ +if (flag) { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); }if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -341,34 +350,29 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); + +/* flag true if (byFBOption == AUTO_FB_0) */ +if (flag) { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); } +if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
Signature · 1 line
2.24.1
On 3/26/20 5:33 PM, Briana Oursler wrote:
Hi Briana,
Quoted 3 lines
Pulls some logic branches above switch case and holds outcomes in variables to improve readability and reduce code duplication within switch case.
I have copy & pasted the guidance Julia Lawall had pointed to on how "subject" and "patch description" should be written. Please see below:
https://kernelnewbies.org/PatchPhilosophy suggests:
In patch descriptions and in the subject, it is common and preferable to use present-tense, imperative language. Write as if you are telling git what to do with your patch.
It provides the following as an example of a good description:
somedriver: fix sleep while atomic in send_a_packet()
The send_a_packet() function is called in atomic context but takes a mutex, causing a sleeping while atomic warning. Change the skb_lock to be a spinlock instead of a mutex to fix.
thanks,
-lakshmi
PATCH v3 1/1 Staging: vt6655: Refactor switch case statement.
Pull some logic branches above switch case. Create variables to reduce code duplication and improve readability.
---
Changes in v3:
- Update grammar and meaning in patch description.
Changes in v2:
- Remove ternary logic in switch case.
- Introduce 'flag' bool.
- Move len definition above switch case.
drivers/staging/vt6655/rxtx.c | 128 ++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 62 deletions(-)
drivers/staging/vt6655/rxtx.c +66 -62
@@ -239,11 +239,21 @@ s_uGetDataDuration( ) {bool bLastFrag = false; +bool flag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true; +if (uFragIdx == (uMACfragNum -2 )) + len = cbLastFragmentSize; +else + len = cbFrameLength; + +if (byFBOption ==AUTO_FB_0 ) + flag = true; +switch (byDurType) {case DATADUR_B :/* DATADUR_B */ if (((uMACfragNum ==1 )) || bLastFrag) {/* Non Frag or Last Frag */
@@ -254,17 +264,17 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopCCKBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopCCKBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -277,17 +287,18 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, + wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -300,35 +311,33 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); +if (wRate <RATE_18M ) + wRate =RATE_18M ; +else if (wRate >RATE_54M ) + wRate =RATE_54M ; + +/* flag true if (byFBOption == AUTO_FB_0) */ +if (flag) { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); }if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -341,34 +350,29 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); + +/* flag true if (byFBOption == AUTO_FB_0) */ +if (flag) { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); } +if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
Signature · 1 line
2.24.1
Greg KH
maintainerQuoted 29 lines · Briana Oursler
Pull some logic branches above switch case. Create variables to reduce code duplication and improve readability.
Signed-off-by Briana Oursler <[email protected]>---
Changes in v3:
- Update grammar and meaning in patch description.Changes in v2:
- Remove ternary logic in switch case.
- Introduce 'flag' bool.
- Move len definition above switch case.drivers/staging/vt6655/rxtx.c | 128 ++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 62 deletions(-)drivers/staging/vt6655/rxtx.c +2
-0@@ -239,11 +239,21 @@ s_uGetDataDuration( ) {bool bLastFrag = false; +bool flag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;
drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 255
Quoted 10 lines
drivers/staging/vt6655/rxtx.c +7
-0if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true; +if (uFragIdx == (uMACfragNum -2 )) + len = cbLastFragmentSize; +else + len = cbFrameLength; + +if (byFBOption ==AUTO_FB_0 ) + flag = true;
"flag" is horrible to try to remember what it really is for.
You already know this, because you say so in your code change:
drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 257
Quoted 2 lines
drivers/staging/vt6655/rxtx.c +2
-0+/* flag true if (byFBOption == AUTO_FB_0) */ +if (flag) {
Why not just test for the == statement here?
Also, your comment is indented incorrectly, didn't checkpatch catch that when you ran it against your patch?
drivers/staging/vt6655/rxtx.c s_uGetDataDuration( · line 259
Quoted 2 lines
drivers/staging/vt6655/rxtx.c +2
-0+/* flag true if (byFBOption == AUTO_FB_0) */ +if (flag) {
Same goes here as well.
I don't see why adding that new variable saved any space or logic, it only made the code harder to follow and forced you to write the logic out anyway, in the comment :)
thanks,
greg k-h
PATCH v4 1/1 Staging: vt6655: Refactor switch case statement.
Simplify switch case statement to improve readability and limit code duplication. Define len variable for next packet time function input. Lift logic out of nested if else. Format long lines.
---
Changes in v4:
- Remove 'flag' bool and return comparison to switch case.
- Remove comment.
- Update patch description to better describe changes.
Changes in v3:
- Update grammar and meaning in patch description.
Changes in v2:
- Remove ternary logic in switch case.
- Introduce 'flag' bool.
- Move len definition above switch case.
drivers/staging/vt6655/rxtx.c | 118 +++++++++++++++++----------------- 1 file changed, 58 insertions(+), 60 deletions(-)
drivers/staging/vt6655/rxtx.c +58 -60
@@ -240,10 +240,16 @@ s_uGetDataDuration( {bool bLastFrag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true; +if (uFragIdx == (uMACfragNum -2 )) + len = cbLastFragmentSize; +else + len = cbFrameLength; +switch (byDurType) {case DATADUR_B :/* DATADUR_B */ if (((uMACfragNum ==1 )) || bLastFrag) {/* Non Frag or Last Frag */
@@ -254,17 +260,17 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopCCKBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopCCKBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -277,17 +283,18 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, + wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -300,35 +307,32 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ +if (wRate <RATE_18M ) + wRate =RATE_18M ; +else if (wRate >RATE_54M ) + wRate =RATE_54M ; +if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); }if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -341,34 +345,28 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ +if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); } +if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
Signature · 1 line
2.24.1
Quoted 3 lines · Briana Oursler
Simplify switch case statement to improve readability and limit code duplication. Define len variable for next packet time function input. Lift logic out of nested if else. Format long lines.
The subject and log message seem very misleading. You don't seem to modify either a switch or a case. I guess you mean that you are focusing on the branches of a single switch statement. But the switch doesn't seem like the important part. The log message lists a variety of things that are done. What is the main theme of the patch?
julia
Quoted 208 lines
Signed-off-by Briana Oursler <[email protected]>---
Changes in v4:
- Remove 'flag' bool and return comparison to switch case.
- Remove comment.
- Update patch description to better describe changes.Changes in v3:
- Update grammar and meaning in patch description.Changes in v2:
- Remove ternary logic in switch case.
- Introduce 'flag' bool.
- Move len definition above switch case.drivers/staging/vt6655/rxtx.c | 118 +++++++++++++++++----------------- 1 file changed, 58 insertions(+), 60 deletions(-)drivers/staging/vt6655/rxtx.c +58
-61@@ -240,10 +240,16 @@ s_uGetDataDuration( {bool bLastFrag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true; +if (uFragIdx == (uMACfragNum -2 )) + len = cbLastFragmentSize; +else + len = cbFrameLength; +switch (byDurType) {case DATADUR_B :/* DATADUR_B */ if (((uMACfragNum ==1 )) || bLastFrag) {/* Non Frag or Last Frag */ @@ -254,17 +260,17 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopCCKBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopCCKBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;@@ -277,17 +283,18 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, + wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;@@ -300,35 +307,32 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ +if (wRate <RATE_18M ) + wRate =RATE_18M ; +else if (wRate >RATE_54M ) + wRate =RATE_54M ; +if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); }if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;@@ -341,34 +345,28 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ +if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); } +if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ; --2.24.1
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20200327213253.22230-1-briana.oursler%40gmail.com.
PATCH v5 1/1 Staging: vt6655: Reduce statement complexity
Move duplicated code out of nested if else statements and make other simplifying changes, shortening line length and improving readability.
---
Changes in v5:
- Update patch description to better describe changes.
Changes in v4:
- Remove 'flag' bool and return comparison to switch case.
- Remove comment.
- Update path description to better describe changes.
Changes in v3:
- Update grammar and meaning in patch description.
Changes in v2:
- Remove ternary logic in switch case.
- Introduce 'flag' bool.
- Move len definition above switch case.
drivers/staging/vt6655/rxtx.c | 118 +++++++++++++++++----------------- 1 file changed, 58 insertions(+), 60 deletions(-)
drivers/staging/vt6655/rxtx.c +58 -60
@@ -240,10 +240,16 @@ s_uGetDataDuration( {bool bLastFrag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true; +if (uFragIdx == (uMACfragNum -2 )) + len = cbLastFragmentSize; +else + len = cbFrameLength; +switch (byDurType) {case DATADUR_B :/* DATADUR_B */ if (((uMACfragNum ==1 )) || bLastFrag) {/* Non Frag or Last Frag */
@@ -254,17 +260,17 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopCCKBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopCCKBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -277,17 +283,18 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, + wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -300,35 +307,32 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ +if (wRate <RATE_18M ) + wRate =RATE_18M ; +else if (wRate >RATE_54M ) + wRate =RATE_54M ; +if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); }if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
@@ -341,34 +345,28 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ +if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); } +if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;
Signature · 1 line
2.24.1
Re: [patch v5] Staging: vt6655: Reduce statement complexity
Quoted 2 lines · Briana Oursler
Move duplicated code out of nested if else statements and make other simplifying changes, shortening line length and improving readability.
Should this really be multiple patches? For example, does the len thing need to be with the rest?
A line is added under an else in the hunk starting with line 341 that doesn't look necessary.
julia
Quoted 206 lines
Signed-off-by Briana Oursler <[email protected]>---
Changes in v5:
- Update patch description to better describe changes.Changes in v4:
- Remove 'flag' bool and return comparison to switch case.
- Remove comment.
- Update path description to better describe changes.Changes in v3:
- Update grammar and meaning in patch description.Changes in v2:
- Remove ternary logic in switch case.
- Introduce 'flag' bool.
- Move len definition above switch case.drivers/staging/vt6655/rxtx.c | 118 +++++++++++++++++----------------- 1 file changed, 58 insertions(+), 60 deletions(-)drivers/staging/vt6655/rxtx.c +58
-61@@ -240,10 +240,16 @@ s_uGetDataDuration( {bool bLastFrag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true; +if (uFragIdx == (uMACfragNum -2 )) + len = cbLastFragmentSize; +else + len = cbFrameLength; +switch (byDurType) {case DATADUR_B :/* DATADUR_B */ if (((uMACfragNum ==1 )) || bLastFrag) {/* Non Frag or Last Frag */ @@ -254,17 +260,17 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopCCKBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopCCKBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;@@ -277,17 +283,18 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, + wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;@@ -300,35 +307,32 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ +if (wRate <RATE_18M ) + wRate =RATE_18M ; +else if (wRate >RATE_54M ) + wRate =RATE_54M ; +if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); }if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ;@@ -341,34 +345,28 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ +if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt0[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len, + wFB_Opt1[FB_RATE0 ][wRate -RATE_18M ], + bNeedAck); } +if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice->byPreambleType, byPktType,14 , pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime =BBuGetFrameTime (pDevice->byPreambleType, + byPktType,14 , + pDevice->byTopOFDMBasicRate); }else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + +return pDevice->uSIFS + uAckTime + uNextPktTime; }break ; --2.24.1
Re: [patch v5] Staging: vt6655: Reduce statement complexity
Quoted 8 lines · Julia Lawall
Quoted 4 lines · Briana Oursler
Move duplicated code out of nested if else statements and make other
simplifying changes, shortening line length and improving readability.
Quoted 6 lines
Should this really be multiple patches? For example, does the len thing
need to be with the rest?A line is added under an else in the hunk starting with line 341 that doesn't look necessary.
I see what you mean. Thanks for reviewing, I'll go ahead and resend as a patch series.
Thanks,
--Briana
Quoted 270 lines
julia
Quoted 267 lines
Signed-off-by Briana Oursler <[email protected]>---
Changes in v5:
- Update patch description to better describe changes.Changes in v4:
- Remove 'flag' bool and return comparison to switch case.
- Remove comment.
- Update path description to better describe changes.Changes in v3:
- Update grammar and meaning in patch description.Changes in v2:
- Remove ternary logic in switch case.
- Introduce 'flag' bool.
- Move len definition above switch case.drivers/staging/vt6655/rxtx.c | 118 +++++++++++++++++------------- ---- 1 file changed, 58 insertions(+), 60 deletions(-)drivers/staging/vt6655/rxtx.c +6
-0@@ -240,10 +240,16 @@ s_uGetDataDuration( {bool bLastFrag = false;unsigned int uAckTime =0 , uNextPktTime =0 ; +unsigned int len;if (uFragIdx == (uMACfragNum -1 )) bLastFrag = true; +if (uFragIdx == (uMACfragNum -2 )) + len = cbLastFragmentSize; +else + len = cbFrameLength; +switch (byDurType) {case DATADUR_B :/* DATADUR_B */ if (((uMACfragNum ==1 )) || bLastFrag) {/* Non Frag or Last Frag */
drivers/staging/vt6655/rxtx.c +3
-6@@ -254,17 +260,17 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice- >byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime = BBuGetFrameTime(pDevice- >byPreambleType, + byPktType,14,
drivers/staging/vt6655/rxtx.c +1
-0+ pDevice-Quoted 1 line
byTopCCKBasicRate);
drivers/staging/vt6655/rxtx.c +3
-1}else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + + return pDevice->uSIFS + uAckTime +uNextPktTime;
drivers/staging/vt6655/rxtx.c +3
-6}break ;@@ -277,17 +283,18 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wRate, bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, len, + wRate, bNeedAck);if (bNeedAck) { - uAckTime =BBuGetFrameTime (pDevice- >byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); -return pDevice->uSIFS + uAckTime + uNextPktTime; + uAckTime = BBuGetFrameTime(pDevice-Quoted 1 line
byPreambleType,
drivers/staging/vt6655/rxtx.c +1
-0+ byPktType,14,
drivers/staging/vt6655/rxtx.c +1
-0+ pDevice-Quoted 1 line
byTopOFDMBasicRate);
drivers/staging/vt6655/rxtx.c +3
-1}else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + + return pDevice->uSIFS + uAckTime +uNextPktTime;
drivers/staging/vt6655/rxtx.c +12
-20}break ;@@ -300,35 +307,32 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ +if (wRate <RATE_18M ) + wRate =RATE_18M ; +else if (wRate >RATE_54M ) + wRate =RATE_54M ; +if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0 ][wRate-RATE_18M ], bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktTyp e, len, + wFB_Opt0 [FB_RATE0 ][wRate -RATE_18M ], + bNeedAck ); + }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len,
drivers/staging/vt6655/rxtx.c +1
-0+ wFB_Opt1[FB_RATE0][wRate -
RATE_18M],drivers/staging/vt6655/rxtx.c +1
-0+ bNeedAck);
drivers/staging/vt6655/rxtx.c +0
-1}if (bNeedAck) { - uAckTime = BBuGetFrameTime(pDevice-Quoted 1 line
byPreambleType, byPktType, 14,
pDevice->byTopOFDMBasicRate);drivers/staging/vt6655/rxtx.c +0
-1- return pDevice->uSIFS + uAckTime +uNextPktTime;
drivers/staging/vt6655/rxtx.c +1
-0+ uAckTime = BBuGetFrameTime(pDevice-Quoted 1 line
byPreambleType,
drivers/staging/vt6655/rxtx.c +1
-0+ byPktType,14,
drivers/staging/vt6655/rxtx.c +1
-0+ pDevice-Quoted 1 line
byTopOFDMBasicRate);
drivers/staging/vt6655/rxtx.c +3
-1}else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + + return pDevice->uSIFS + uAckTime +uNextPktTime;
drivers/staging/vt6655/rxtx.c +5
-20}break ;@@ -341,34 +345,28 @@ s_uGetDataDuration(return 0 ; } }else {/* First Frag or Mid Frag */ +if (byFBOption ==AUTO_FB_0 ) { -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); - - }else {/* (byFBOption == AUTO_FB_1) */ -if (wRate <RATE_18M ) - wRate =RATE_18M ; -else if (wRate >RATE_54M ) - wRate =RATE_54M ; - -if (uFragIdx == (uMACfragNum -2 )) - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); -else - uNextPktTime =s_uGetTxRsvTime (pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1 ][wRate-RATE_18M ], bNeedAck); + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktTyp e, len, + wFB_Opt0 [FB_RATE0 ][wRate -RATE_18M ], + bNeedAck);
drivers/staging/vt6655/rxtx.c +3
-0+ }else { + uNextPktTime =s_uGetTxRsvTime (pDevice, + byPktType, len,
drivers/staging/vt6655/rxtx.c +1
-0+ wFB_Opt1[FB_RATE0][wRate -
RATE_18M],drivers/staging/vt6655/rxtx.c +1
-0+ bNeedAck);
drivers/staging/vt6655/rxtx.c +1
-1} +if (bNeedAck) { - uAckTime = BBuGetFrameTime(pDevice-Quoted 1 line
byPreambleType, byPktType, 14,
pDevice->byTopOFDMBasicRate);drivers/staging/vt6655/rxtx.c +0
-1- return pDevice->uSIFS + uAckTime +uNextPktTime;
drivers/staging/vt6655/rxtx.c +1
-0+ uAckTime = BBuGetFrameTime(pDevice-Quoted 1 line
byPreambleType,
drivers/staging/vt6655/rxtx.c +1
-0+ byPktType,14,
drivers/staging/vt6655/rxtx.c +1
-0+ pDevice-Quoted 1 line
byTopOFDMBasicRate);
drivers/staging/vt6655/rxtx.c +3
-1}else { -return pDevice->uSIFS + uNextPktTime; + uAckTime =0 ; } + + return pDevice->uSIFS + uAckTime +uNextPktTime;
drivers/staging/vt6655/rxtx.c +0
-1}break ; --2.24.1