[PATCH v2] staging: rtl8723bs: change custom comparing function to strcmp()

Bera Yüzlü posted 1 patch 1 month ago
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(-)
[PATCH v2] staging: rtl8723bs: change custom comparing function to strcmp()
Posted by Bera Yüzlü 1 month ago
eqNByte() function is a redundant reimplementation of strcmp().
Remove eqNByte() and switch its usages to strcmp().
No functional change.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bera Yüzlü <b9788213@gmail.com>
---
V2: Used strcmp() instead of memcmp()
V1 link: https://lore.kernel.org/linux-staging/20260227200637.47130-1-b9788213@gmail.com/
 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(-)

diff --git a/drivers/staging/rtl8723bs/hal/hal_com.c b/drivers/staging/rtl8723bs/hal/hal_com.c
index 31b3e880a..a7720f821 100644
--- a/drivers/staging/rtl8723bs/hal/hal_com.c
+++ b/drivers/staging/rtl8723bs/hal/hal_com.c
@@ -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;
diff --git a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
index dc2da49e6..61c6b6e10 100644
--- a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
+++ b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
@@ -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 (strcmp(Regulation, "FCC") == 0)
 		regulation = 0;
-	else if (eqNByte(Regulation, (u8 *)("MKK"), 3))
+	else if (strcmp(Regulation, "MKK") == 0)
 		regulation = 1;
-	else if (eqNByte(Regulation, (u8 *)("ETSI"), 4))
+	else if (strcmp(Regulation, "ETSI") == 0)
 		regulation = 2;
-	else if (eqNByte(Regulation, (u8 *)("WW13"), 4))
+	else if (strcmp(Regulation, "WW13") == 0)
 		regulation = 3;
 
-	if (eqNByte(RateSection, (u8 *)("CCK"), 3) && eqNByte(RfPath, (u8 *)("1T"), 2))
+	if (strcmp(RateSection, "CCK") == 0 && strcmp(RfPath, "1T") == 0)
 		rateSection = 0;
-	else if (eqNByte(RateSection, (u8 *)("OFDM"), 4) && eqNByte(RfPath, (u8 *)("1T"), 2))
+	else if (strcmp(RateSection, "OFDM") == 0 && strcmp(RfPath, "1T") == 0)
 		rateSection = 1;
-	else if (eqNByte(RateSection, (u8 *)("HT"), 2) && eqNByte(RfPath, (u8 *)("1T"), 2))
+	else if (strcmp(RateSection, "HT") == 0 && strcmp(RfPath, "1T") == 0)
 		rateSection = 2;
 	else
 		return;
 
-	if (eqNByte(Bandwidth, (u8 *)("20M"), 3))
+	if (strcmp(Bandwidth, "20M") == 0)
 		bandwidth = 0;
-	else if (eqNByte(Bandwidth, (u8 *)("40M"), 3))
+	else if (strcmp(Bandwidth, "40M") == 0)
 		bandwidth = 1;
 
 	channelIndex = phy_GetChannelIndexOfTxPowerLimit(channel);
diff --git a/drivers/staging/rtl8723bs/include/hal_com.h b/drivers/staging/rtl8723bs/include/hal_com.h
index 74d6c892c..483f0390a 100644
--- a/drivers/staging/rtl8723bs/include/hal_com.h
+++ b/drivers/staging/rtl8723bs/include/hal_com.h
@@ -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
-- 
2.43.0

Re: [PATCH v2] staging: rtl8723bs: change custom comparing function to strcmp()
Posted by Andy Shevchenko 3 weeks, 1 day ago
On Mon, Mar 09, 2026 at 09:45:56PM +0300, Bera Yüzlü wrote:
> eqNByte() function is a redundant reimplementation of strcmp().
> Remove eqNByte() and switch its usages to strcmp().
> No functional change.

...

> +	if (strcmp(Regulation, "FCC") == 0)
>  		regulation = 0;
> +	else if (strcmp(Regulation, "MKK") == 0)
>  		regulation = 1;
> +	else if (strcmp(Regulation, "ETSI") == 0)
>  		regulation = 2;
> +	else if (strcmp(Regulation, "WW13") == 0)
>  		regulation = 3;

Now you can move it towards match_string().

static const char * const regulations[] = { "FCC", "MKK", "ETSI", "WW13" };

	regulation = match_string(regulations, ARRAY_SIZE(regulations), Regulation);
	if (regulation < 0)
		...ai-ai-ai...

and so on for the rest.

-- 
With Best Regards,
Andy Shevchenko