Skip to contentSkip to conversation

staging: rtl8192e: simplify rtl92e_evm_db_to_percent()

PATCH New Michael Straube 1 participant 3 messages Jan 18, 2020 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 staging: rtl8192e: simplify rtl92e_evm_db_to_percent()

Use clamp() to simplify function rtl92e_evm_db_to_percent() and reduce object file size.

---
 drivers/staging/rtl8192e/rtl8192e/rtl_core.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/staging/rtl8192e/rtl8192e/rtl_core.c +2 -9
index dace81a7d1ba..caf36b6bf0dc 100644
@@ -1973,18 +1973,11 @@ u8 rtl92e_rx_db_to_percent(s8 antpower)
 
 u8 rtl92e_evm_db_to_percent(s8 value)
 {
-	s8 ret_val;
+	s8 ret_val = clamp(-value, 0, 33) * 3;
 
-	ret_val = value;
-
-	if (ret_val >= 0)
-		ret_val = 0;
-	if (ret_val <= -33)
-		ret_val = -33;
-	ret_val = 0 - ret_val;
-	ret_val *= 3;
 	if (ret_val == 99)
 		ret_val = 100;
+
 	return ret_val;
 }
 
Signature · 1 line
2.24.1
#1 lore raw

PATCH 2/3 staging: rtl8192u: simplify rtl819x_evm_dbtopercentage()

Use clamp() to simplify function rtl819x_evm_dbtopercentage() and reduce object file size.

---
 drivers/staging/rtl8192u/r8192U_core.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/staging/rtl8192u/r8192U_core.c +2 -9
index 00fdcbf64b0b..a40ce0d7a467 100644
@@ -3954,18 +3954,11 @@ static u8 rtl819x_query_rxpwrpercentage(s8 antpower)
 
 static u8 rtl819x_evm_dbtopercentage(s8 value)
 {
-	s8 ret_val;
+	s8 ret_val = clamp(-value, 0, 33) * 3;
 
-	ret_val = value;
-
-	if (ret_val >= 0)
-		ret_val = 0;
-	if (ret_val <= -33)
-		ret_val = -33;
-	ret_val = 0 - ret_val;
-	ret_val *= 3;
 	if (ret_val == 99)
 		ret_val = 100;
+
 	return ret_val;
 }
 
Signature · 1 line
2.24.1
#2 lore raw

PATCH 3/3 staging: rtl8712: simplify evm_db2percentage()

In reply to Michael Straube

Use clamp() to simplify function evm_db2percentage() and reduce object file size.

---
 drivers/staging/rtl8712/rtl8712_recv.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/staging/rtl8712/rtl8712_recv.c +2 -8
index 00ea0beb12c9..116773943a2e 100644
@@ -663,17 +663,11 @@ static u8 evm_db2percentage(s8 value)
 	/*
 	 * -33dB~0dB to 0%~99%
 	 */
-	s8 ret_val;
+	s8 ret_val = clamp(-value, 0, 33) * 3;
 
-	ret_val = value;
-	if (ret_val >= 0)
-		ret_val = 0;
-	if (ret_val <= -33)
-		ret_val = -33;
-	ret_val = -ret_val;
-	ret_val *= 3;
 	if (ret_val == 99)
 		ret_val = 100;
+
 	return ret_val;
 }
 
Signature · 1 line
2.24.1