Skip to contentSkip to conversation

staging: rtl8723bs: change custom comparing function to memcmp()

PATCH Superseded Bera Yüzlü 3 participants 3 messages Feb 27 – Mar 9 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8723bs: change custom comparing function to memcmp()

eqNByte() function is a redundant reimplementation of memcmp(). Remove eqNByte() and switch its usages to memcmp(). No functional change.

---
 drivers/staging/rtl8723bs/hal/hal_com.c       | 12 ------------
 .../staging/rtl8723bs/hal/hal_com_phycfg.c    | 19 ++++++++++---------
 drivers/staging/rtl8723bs/include/hal_com.h   |  2 --
 3 files changed, 10 insertions(+), 23 deletions(-)
drivers/staging/rtl8723bs/hal/hal_com.c +0 -12
index 31b3e880ae6a..a7720f821823 100644
@@ -750,18 +750,6 @@ void SetHalODMVar(
 }
 
 
-bool eqNByte(u8 *str1, u8 *str2, u32 num)
-{
-	if (num == 0)
-		return false;
-	while (num > 0) {
-		num--;
-		if (str1[num] != str2[num])
-			return false;
-	}
-	return true;
-}
-
 bool GetU1ByteIntegerFromStringInDecimal(char *Str, u8 *pInt)
 {
 	u16 i = 0;
drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +10 -9
index dc2da49e6738..b5ba3eba597b 100644
@@ -8,6 +8,7 @@
 #include <drv_types.h>
 #include <hal_data.h>
 #include <linux/kernel.h>
+#include <linux/string.h>
 
 u8 PHY_GetTxPowerByRateBase(struct adapter *Adapter, u8 RfPath,
 			    enum rate_section RateSection)
@@ -819,27 +820,27 @@ void PHY_SetTxPowerLimit(
 
 	powerLimit = powerLimit > MAX_POWER_INDEX ? MAX_POWER_INDEX : powerLimit;
 
-	if (eqNByte(Regulation, (u8 *)("FCC"), 3))
+	if (memcmp(Regulation, "FCC", 3) == 0)
 		regulation = 0;
-	else if (eqNByte(Regulation, (u8 *)("MKK"), 3))
+	else if (memcmp(Regulation, "MKK", 3) == 0)
 		regulation = 1;
-	else if (eqNByte(Regulation, (u8 *)("ETSI"), 4))
+	else if (memcmp(Regulation, "ETSI", 4) == 0)
 		regulation = 2;
-	else if (eqNByte(Regulation, (u8 *)("WW13"), 4))
+	else if (memcmp(Regulation, "WW13", 4) == 0)
 		regulation = 3;
 
-	if (eqNByte(RateSection, (u8 *)("CCK"), 3) && eqNByte(RfPath, (u8 *)("1T"), 2))
+	if (memcmp(RateSection, "CCK", 3) == 0 && memcmp(RfPath, "1T", 2) == 0)
 		rateSection = 0;
-	else if (eqNByte(RateSection, (u8 *)("OFDM"), 4) && eqNByte(RfPath, (u8 *)("1T"), 2))
+	else if (memcmp(RateSection, "OFDM", 4) == 0 && memcmp(RfPath, "1T", 2) == 0)
 		rateSection = 1;
-	else if (eqNByte(RateSection, (u8 *)("HT"), 2) && eqNByte(RfPath, (u8 *)("1T"), 2))
+	else if (memcmp(RateSection, "HT", 2) == 0 && memcmp(RfPath, "1T", 2) == 0)
 		rateSection = 2;
 	else
 		return;
 
-	if (eqNByte(Bandwidth, (u8 *)("20M"), 3))
+	if (memcmp(Bandwidth, "20M", 3) == 0)
 		bandwidth = 0;
-	else if (eqNByte(Bandwidth, (u8 *)("40M"), 3))
+	else if (memcmp(Bandwidth, "40M", 3) == 0)
 		bandwidth = 1;
 
 	channelIndex = phy_GetChannelIndexOfTxPowerLimit(channel);
drivers/staging/rtl8723bs/include/hal_com.h +0 -2
index 74d6c892c401..483f0390addc 100644
@@ -141,8 +141,6 @@ void rtw_hal_check_rxfifo_full(struct adapter *adapter);
 u8 GetHalDefVar(struct adapter *adapter, enum hal_def_variable variable,
 		void *value);
 
-bool eqNByte(u8 *str1, u8 *str2, u32 num);
-
 bool GetU1ByteIntegerFromStringInDecimal(char *str, u8 *in);
 
 #define		HWSET_MAX_SIZE			512
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Bera Yüzlü

eqNByte() function is a redundant reimplementation of memcmp(). Remove eqNByte() and switch its usages to memcmp(). No functional change.

Can be something better like using match_string(), but that will require more study of the code and can be done later on.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#2 lore raw
In reply to Bera Yüzlü
Quoted 47 lines · Bera Yüzlü

eqNByte() function is a redundant reimplementation of memcmp(). Remove eqNByte() and switch its usages to memcmp(). No functional change.

---
 drivers/staging/rtl8723bs/hal/hal_com.c       | 12 ------------
 .../staging/rtl8723bs/hal/hal_com_phycfg.c    | 19 ++++++++++---------
 drivers/staging/rtl8723bs/include/hal_com.h   |  2 --
 3 files changed, 10 insertions(+), 23 deletions(-)
drivers/staging/rtl8723bs/hal/hal_com.c +0 -12
index 31b3e880ae6a..a7720f821823 100644
@@ -750,18 +750,6 @@ void SetHalODMVar(
 }
 
 
-bool eqNByte(u8 *str1, u8 *str2, u32 num)
-{
-	if (num == 0)
-		return false;
-	while (num > 0) {
-		num--;
-		if (str1[num] != str2[num])
-			return false;
-	}
-	return true;
-}
-
 bool GetU1ByteIntegerFromStringInDecimal(char *Str, u8 *pInt)
 {
 	u16 i = 0;
drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +1 -0
index dc2da49e6738..b5ba3eba597b 100644
@@ -8,6 +8,7 @@
 #include <drv_types.h>
 #include <hal_data.h>
 #include <linux/kernel.h>
+#include <linux/string.h>
 
 u8 PHY_GetTxPowerByRateBase(struct adapter *Adapter, u8 RfPath,
 			    enum rate_section RateSection)

drivers/staging/rtl8723bs/hal/hal_com_phycfg.c void PHY_SetTxPowerLimit( · line 824

Quoted 6 lines
drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +1 -1
@@ -819,27 +820,27 @@ void PHY_SetTxPowerLimit(
 
 	powerLimit = powerLimit > MAX_POWER_INDEX ? MAX_POWER_INDEX : powerLimit;
 
-	if (eqNByte(Regulation, (u8 *)("FCC"), 3))
+	if (memcmp(Regulation, "FCC", 3) == 0)
 		regulation = 0;

This should all be calls to strcmp() instead, right? These are strings, please treat them as such.

thanks,

greg k-h