2020-05-03 13:31:11

by Matej Dujava

[permalink] [raw]
Subject: [PATCH 0/5] Cleaning s_uGetDataDuration function

This patch set will eliminate few checkpatch LONG_LINE errors.
Simplify code paths by:
- returning at the end of case body
- removing unnecessary else branches

Matej Dujava (5):
staging: vt6655: merge two switch cases in s_uGetDataDuration
staging: vt6655: do calculation of uAckTime first
staging: vt6655: remove else after return and invert condition
staging: vt6655: return at the ond of case body
staging: vt6655: extract index manupulation out of function call

drivers/staging/vt6655/rxtx.c | 140 ++++++++++++----------------------
1 file changed, 48 insertions(+), 92 deletions(-)

--
2.26.2


2020-05-03 13:31:20

by Matej Dujava

[permalink] [raw]
Subject: [PATCH 2/5] staging: vt6655: do calculation of uAckTime first

This patch is extracting calculation of uAckTime in one place, at the
start of case body.

Signed-off-by: Matej Dujava <[email protected]>
---
drivers/staging/vt6655/rxtx.c | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c
index 28f0cda36dec..01ceace253a4 100644
--- a/drivers/staging/vt6655/rxtx.c
+++ b/drivers/staging/vt6655/rxtx.c
@@ -255,9 +255,13 @@ s_uGetDataDuration(

switch (byDurType) {
case DATADUR_B: /* DATADUR_B */
+ if (bNeedAck) {
+ uAckTime = bb_get_frame_time(pDevice->byPreambleType,
+ byPktType, 14,
+ pDevice->byTopCCKBasicRate);
+ }
if (((uMACfragNum == 1)) || bLastFrag) {/* Non Frag or Last Frag */
if (bNeedAck) {
- uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
return pDevice->uSIFS + uAckTime;
} else {
return 0;
@@ -265,19 +269,18 @@ s_uGetDataDuration(
} else {/* First Frag or Mid Frag */
uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, len, wRate, bNeedAck);

- if (bNeedAck) {
- uAckTime = bb_get_frame_time(pDevice->byPreambleType,
- byPktType, 14,
- pDevice->byTopCCKBasicRate);
- }
return pDevice->uSIFS + uAckTime + uNextPktTime;
}
break;

case DATADUR_A: /* DATADUR_A */
+ if (bNeedAck) {
+ uAckTime = bb_get_frame_time(pDevice->byPreambleType,
+ byPktType, 14,
+ pDevice->byTopOFDMBasicRate);
+ }
if (((uMACfragNum == 1)) || bLastFrag) {/* Non Frag or Last Frag */
if (bNeedAck) {
- uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
return pDevice->uSIFS + uAckTime;
} else {
return 0;
@@ -286,20 +289,19 @@ s_uGetDataDuration(
uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, len,
wRate, bNeedAck);

- if (bNeedAck) {
- uAckTime = bb_get_frame_time(pDevice->byPreambleType,
- byPktType, 14,
- pDevice->byTopOFDMBasicRate);
- }
return pDevice->uSIFS + uAckTime + uNextPktTime;
}
break;

case DATADUR_A_F0: /* DATADUR_A_F0 */
case DATADUR_A_F1: /* DATADUR_A_F1 */
+ if (bNeedAck) {
+ uAckTime = bb_get_frame_time(pDevice->byPreambleType,
+ byPktType, 14,
+ pDevice->byTopOFDMBasicRate);
+ }
if (((uMACfragNum == 1)) || bLastFrag) { /* Non Frag or Last Frag */
if (bNeedAck) {
- uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
return pDevice->uSIFS + uAckTime;
} else {
return 0;
@@ -322,11 +324,6 @@ s_uGetDataDuration(
bNeedAck);
}

- if (bNeedAck) {
- uAckTime = bb_get_frame_time(pDevice->byPreambleType,
- byPktType, 14,
- pDevice->byTopOFDMBasicRate);
- }
return pDevice->uSIFS + uAckTime + uNextPktTime;
}
break;
--
2.26.2

2020-05-03 13:31:42

by Matej Dujava

[permalink] [raw]
Subject: [PATCH 5/5] staging: vt6655: extract index manupulation out of function call

This patch will remove if/else by selecting proper argument before
function call, also index is updated before function call.

Signed-off-by: Matej Dujava <[email protected]>
---
drivers/staging/vt6655/rxtx.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c
index c4d62c27f1c1..1e025bb72810 100644
--- a/drivers/staging/vt6655/rxtx.c
+++ b/drivers/staging/vt6655/rxtx.c
@@ -266,7 +266,8 @@ s_uGetDataDuration(
return 0;
} else {
/* First Frag or Mid Frag */
- uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, len, wRate, bNeedAck);
+ uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType,
+ len, wRate, bNeedAck);
}

return pDevice->uSIFS + uAckTime + uNextPktTime;
@@ -283,8 +284,8 @@ s_uGetDataDuration(
return 0;
} else {
/* First Frag or Mid Frag */
- uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, len,
- wRate, bNeedAck);
+ uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType,
+ len, wRate, bNeedAck);
}

return pDevice->uSIFS + uAckTime + uNextPktTime;
@@ -307,17 +308,15 @@ s_uGetDataDuration(
else if (wRate > RATE_54M)
wRate = RATE_54M;

- if (byFBOption == AUTO_FB_0) {
- 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);
- }
+ wRate -= RATE_18M;
+
+ if (byFBOption == AUTO_FB_0)
+ wRate = wFB_Opt0[FB_RATE0][wRate];
+ else
+ wRate = wFB_Opt1[FB_RATE0][wRate];
+
+ uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType,
+ len, wRate, bNeedAck);
}

return pDevice->uSIFS + uAckTime + uNextPktTime;
--
2.26.2

2020-05-03 13:31:56

by Matej Dujava

[permalink] [raw]
Subject: [PATCH 1/5] staging: vt6655: merge two switch cases in s_uGetDataDuration

This patch will reuse code for two cases.

Signed-off-by: Matej Dujava <[email protected]>
---
drivers/staging/vt6655/rxtx.c | 34 ----------------------------------
1 file changed, 34 deletions(-)

diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c
index 2f9c2ead3cb8..28f0cda36dec 100644
--- a/drivers/staging/vt6655/rxtx.c
+++ b/drivers/staging/vt6655/rxtx.c
@@ -296,40 +296,6 @@ s_uGetDataDuration(
break;

case DATADUR_A_F0: /* DATADUR_A_F0 */
- if (((uMACfragNum == 1)) || bLastFrag) {/* Non Frag or Last Frag */
- if (bNeedAck) {
- uAckTime = bb_get_frame_time(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
- return pDevice->uSIFS + uAckTime;
- } else {
- 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) {
- 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 = bb_get_frame_time(pDevice->byPreambleType,
- byPktType, 14,
- pDevice->byTopOFDMBasicRate);
- }
- return pDevice->uSIFS + uAckTime + uNextPktTime;
- }
- break;
-
case DATADUR_A_F1: /* DATADUR_A_F1 */
if (((uMACfragNum == 1)) || bLastFrag) { /* Non Frag or Last Frag */
if (bNeedAck) {
--
2.26.2

2020-05-03 13:32:51

by Matej Dujava

[permalink] [raw]
Subject: [PATCH 3/5] staging: vt6655: remove else after return and invert condition

This patch will prepare us to make return at the end of case body

Signed-off-by: Matej Dujava <[email protected]>
---
drivers/staging/vt6655/rxtx.c | 36 +++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c
index 01ceace253a4..61f7077bb75f 100644
--- a/drivers/staging/vt6655/rxtx.c
+++ b/drivers/staging/vt6655/rxtx.c
@@ -260,13 +260,13 @@ s_uGetDataDuration(
byPktType, 14,
pDevice->byTopCCKBasicRate);
}
- if (((uMACfragNum == 1)) || bLastFrag) {/* Non Frag or Last Frag */
- if (bNeedAck) {
- return pDevice->uSIFS + uAckTime;
- } else {
+ /* Non Frag or Last Frag */
+ if ((uMACfragNum == 1) || bLastFrag) {
+ if (!bNeedAck)
return 0;
- }
- } else {/* First Frag or Mid Frag */
+ return pDevice->uSIFS + uAckTime;
+ } else {
+ /* First Frag or Mid Frag */
uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, len, wRate, bNeedAck);

return pDevice->uSIFS + uAckTime + uNextPktTime;
@@ -279,13 +279,13 @@ s_uGetDataDuration(
byPktType, 14,
pDevice->byTopOFDMBasicRate);
}
- if (((uMACfragNum == 1)) || bLastFrag) {/* Non Frag or Last Frag */
- if (bNeedAck) {
- return pDevice->uSIFS + uAckTime;
- } else {
+ /* Non Frag or Last Frag */
+ if ((uMACfragNum == 1) || bLastFrag) {
+ if (!bNeedAck)
return 0;
- }
- } else {/* First Frag or Mid Frag */
+ return pDevice->uSIFS + uAckTime;
+ } else {
+ /* First Frag or Mid Frag */
uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, len,
wRate, bNeedAck);

@@ -300,13 +300,13 @@ s_uGetDataDuration(
byPktType, 14,
pDevice->byTopOFDMBasicRate);
}
- if (((uMACfragNum == 1)) || bLastFrag) { /* Non Frag or Last Frag */
- if (bNeedAck) {
- return pDevice->uSIFS + uAckTime;
- } else {
+ /* Non Frag or Last Frag */
+ if ((uMACfragNum == 1) || bLastFrag) {
+ if (!bNeedAck)
return 0;
- }
- } else { /* First Frag or Mid Frag */
+ return pDevice->uSIFS + uAckTime;
+ } else {
+ /* First Frag or Mid Frag */
if (wRate < RATE_18M)
wRate = RATE_18M;
else if (wRate > RATE_54M)
--
2.26.2

2020-05-03 13:33:12

by Matej Dujava

[permalink] [raw]
Subject: [PATCH 4/5] staging: vt6655: return at the ond of case body

This patch will unify exit point for s_uGetDataDuration function.

Signed-off-by: Matej Dujava <[email protected]>
---
drivers/staging/vt6655/rxtx.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c
index 61f7077bb75f..c4d62c27f1c1 100644
--- a/drivers/staging/vt6655/rxtx.c
+++ b/drivers/staging/vt6655/rxtx.c
@@ -264,14 +264,12 @@ s_uGetDataDuration(
if ((uMACfragNum == 1) || bLastFrag) {
if (!bNeedAck)
return 0;
- return pDevice->uSIFS + uAckTime;
} else {
/* First Frag or Mid Frag */
uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, len, wRate, bNeedAck);
-
- return pDevice->uSIFS + uAckTime + uNextPktTime;
}
- break;
+
+ return pDevice->uSIFS + uAckTime + uNextPktTime;

case DATADUR_A: /* DATADUR_A */
if (bNeedAck) {
@@ -283,15 +281,13 @@ s_uGetDataDuration(
if ((uMACfragNum == 1) || bLastFrag) {
if (!bNeedAck)
return 0;
- return pDevice->uSIFS + uAckTime;
} else {
/* First Frag or Mid Frag */
uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, len,
wRate, bNeedAck);
-
- return pDevice->uSIFS + uAckTime + uNextPktTime;
}
- break;
+
+ return pDevice->uSIFS + uAckTime + uNextPktTime;

case DATADUR_A_F0: /* DATADUR_A_F0 */
case DATADUR_A_F1: /* DATADUR_A_F1 */
@@ -304,7 +300,6 @@ s_uGetDataDuration(
if ((uMACfragNum == 1) || bLastFrag) {
if (!bNeedAck)
return 0;
- return pDevice->uSIFS + uAckTime;
} else {
/* First Frag or Mid Frag */
if (wRate < RATE_18M)
@@ -323,10 +318,9 @@ s_uGetDataDuration(
wFB_Opt1[FB_RATE0][wRate - RATE_18M],
bNeedAck);
}
-
- return pDevice->uSIFS + uAckTime + uNextPktTime;
}
- break;
+
+ return pDevice->uSIFS + uAckTime + uNextPktTime;

default:
break;
--
2.26.2