Skip to contentSkip to conversation

staging: rtl8723bs: remove copy function

PATCH In review Bera Yüzlü 3 participants 6 messages Mar 20 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8723bs: remove copy function

GetU1ByteIntegerFromStringInDecimal() is a copy of kstrtou8(). Remove its usages to kstrtou8() and check the return value.

---
 drivers/staging/rtl8723bs/hal/hal_com.c       | 19 -------------------
 .../staging/rtl8723bs/hal/hal_com_phycfg.c    | 14 ++++++++++----
 drivers/staging/rtl8723bs/include/hal_com.h   |  2 --
 3 files changed, 10 insertions(+), 25 deletions(-)
drivers/staging/rtl8723bs/hal/hal_com.c +0 -19
index 50370b14ce7c..4f4a430c9f87 100644
@@ -751,25 +751,6 @@ void SetHalODMVar(
 	}
 }
 
-
-bool GetU1ByteIntegerFromStringInDecimal(char *Str, u8 *pInt)
-{
-	u16 i = 0;
-	*pInt = 0;
-
-	while (Str[i] != '\0') {
-		if (Str[i] >= '0' && Str[i] <= '9') {
-			*pInt *= 10;
-			*pInt += (Str[i] - '0');
-		} else
-			return false;
-
-		++i;
-	}
-
-	return true;
-}
-
 void rtw_hal_check_rxfifo_full(struct adapter *adapter)
 {
 	/* switch counter to RX fifo */
drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +10 -4
index bdd595a99b98..447b72954804 100644
@@ -816,11 +816,17 @@ void PHY_SetTxPowerLimit(
 )
 {
 	struct hal_com_data	*pHalData = GET_HAL_DATA(Adapter);
-	u8 regulation = 0, bandwidth = 0, rateSection = 0, channel;
-	s8 powerLimit = 0, prevPowerLimit, channelIndex;
+	u8 regulation = 0, bandwidth = 0, rateSection = 0, channel, powerLimit;
+	s8 prevPowerLimit, channelIndex;
+	int ret;
 
-	GetU1ByteIntegerFromStringInDecimal((s8 *)Channel, &channel);
-	GetU1ByteIntegerFromStringInDecimal((s8 *)PowerLimit, &powerLimit);
+	ret = kstrtou8((const char *)Channel, 10, &channel);
+	if (ret)
+		return;
+
+	ret = kstrtou8((const char *)PowerLimit, 10, &powerLimit);
+	if (ret)
+		return;
 
 	powerLimit = powerLimit > MAX_POWER_INDEX ? MAX_POWER_INDEX : powerLimit;
 
drivers/staging/rtl8723bs/include/hal_com.h +0 -2
index 483f0390addc..7c67fee148fa 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 GetU1ByteIntegerFromStringInDecimal(char *str, u8 *in);
-
 #define		HWSET_MAX_SIZE			512
 
 void rtw_bb_rf_gain_offset(struct adapter *padapter);
Signature · 1 line
2.53.0
#2 lore raw
In reply to Bera Yüzlü
Quoted 2 lines · Bera Yüzlü

GetU1ByteIntegerFromStringInDecimal() is a copy of kstrtou8(). Remove its usages to kstrtou8() and check the return value.

...

Quoted 8 lines

void PHY_SetTxPowerLimit( ... )
{

drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +3 -2
 	struct hal_com_data	*pHalData = GET_HAL_DATA(Adapter);
-	u8 regulation = 0, bandwidth = 0, rateSection = 0, channel;
-	s8 powerLimit = 0, prevPowerLimit, channelIndex;
+	u8 regulation = 0, bandwidth = 0, rateSection = 0, channel, powerLimit;
+	s8 prevPowerLimit, channelIndex;
+	int ret;

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

Quoted 10 lines
drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +7 -2
 
-	GetU1ByteIntegerFromStringInDecimal((s8 *)Channel, &channel);
-	GetU1ByteIntegerFromStringInDecimal((s8 *)PowerLimit, &powerLimit);
+	ret = kstrtou8((const char *)Channel, 10, &channel);
+	if (ret)
+		return;
+
+	ret = kstrtou8((const char *)PowerLimit, 10, &powerLimit);
+	if (ret)
+		return;

This will change behaviour on the invalid data. Before it was just partially converted here and continue, now it breaks an execution. The commit message does not explain if it's safe to do or not (i.o.w. if there is a guarantee that in current state the input will be always in the correct form).

Otherwise, you probably want to use one of simple_strtou*().

Quoted 1 line

powerLimit = powerLimit > MAX_POWER_INDEX ? MAX_POWER_INDEX : powerLimit;

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 24 lines · Andy Shevchenko
Quoted 8 lines

void PHY_SetTxPowerLimit( ... )
{

drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +3 -2
 	struct hal_com_data	*pHalData = GET_HAL_DATA(Adapter);
-	u8 regulation = 0, bandwidth = 0, rateSection = 0, channel;
-	s8 powerLimit = 0, prevPowerLimit, channelIndex;
+	u8 regulation = 0, bandwidth = 0, rateSection = 0, channel, powerLimit;
+	s8 prevPowerLimit, channelIndex;
+	int ret;

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

Quoted 10 lines
drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +7 -2
 
-	GetU1ByteIntegerFromStringInDecimal((s8 *)Channel, &channel);
-	GetU1ByteIntegerFromStringInDecimal((s8 *)PowerLimit, &powerLimit);
+	ret = kstrtou8((const char *)Channel, 10, &channel);
+	if (ret)
+		return;
+
+	ret = kstrtou8((const char *)PowerLimit, 10, &powerLimit);
+	if (ret)
+		return;

This will change behaviour on the invalid data. Before it was just partially converted here and continue, now it breaks an execution. The commit message does not explain if it's safe to do or not (i.o.w. if there is a guarantee that in current state the input will be always in the correct form).

Quoted 1 line

Otherwise, you probably want to use one of simple_strtou*().

It only indirectly called from ODM_ReadAndConfig_MP_8723B_TXPWR_LMT() with constant values. Maybe we can convert this strings to ints so we don't need to do it at runtime. We can also remove the wrapper odm_ConfigBB_TXPWR_LMT_8723B(). This should be a seperate patch, right?

Thanks,
Bera

#4 lore raw
Quoted 27 lines · Bera Yüzlü
Quoted 24 lines · Andy Shevchenko
Quoted 8 lines

void PHY_SetTxPowerLimit( ... )
{

drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +3 -2
 	struct hal_com_data	*pHalData = GET_HAL_DATA(Adapter);
-	u8 regulation = 0, bandwidth = 0, rateSection = 0, channel;
-	s8 powerLimit = 0, prevPowerLimit, channelIndex;
+	u8 regulation = 0, bandwidth = 0, rateSection = 0, channel, powerLimit;
+	s8 prevPowerLimit, channelIndex;
+	int ret;

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

Quoted 10 lines
drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +7 -2
 
-	GetU1ByteIntegerFromStringInDecimal((s8 *)Channel, &channel);
-	GetU1ByteIntegerFromStringInDecimal((s8 *)PowerLimit, &powerLimit);
+	ret = kstrtou8((const char *)Channel, 10, &channel);
+	if (ret)
+		return;
+
+	ret = kstrtou8((const char *)PowerLimit, 10, &powerLimit);
+	if (ret)
+		return;

This will change behaviour on the invalid data. Before it was just partially converted here and continue, now it breaks an execution. The commit message does not explain if it's safe to do or not (i.o.w. if there is a guarantee that in current state the input will be always in the correct form).

Quoted 1 line

Otherwise, you probably want to use one of simple_strtou*().

Quoted 7 lines

It only indirectly called from ODM_ReadAndConfig_MP_8723B_TXPWR_LMT() with constant values. Maybe we can convert this strings to ints so we don't need to do it at runtime. We can also remove the wrapper odm_ConfigBB_TXPWR_LMT_8723B(). This should be a seperate patch, right?

Thanks,
Bera

Just noticed ODM_ReadAndConfig_MP_8723B_TXPWR_LMT() didn't called anywhere. I will remove:
GetU1ByteIntegerFromStringInDecimal()
PHY_SetTxPowerLimit()
odm_ConfigBB_TXPWR_LMT_8723B() ODM_ReadAndConfig_MP_8723B_TXPWR_LMT()
in v2. They are all unusued.

Thanks,
Bera.

#5 lore raw
Quoted 2 lines · Bera Yüzlü
Quoted 1 line · Bera Yüzlü

On Fri, 20 Mar 2026 08:27:22 +0000, Andy Shevchenko wrote:

...

Quoted 22 lines
Quoted 15 lines
Quoted 14 lines

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

Quoted 9 lines
drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +7 -2
-	GetU1ByteIntegerFromStringInDecimal((s8 *)Channel, &channel);
-	GetU1ByteIntegerFromStringInDecimal((s8 *)PowerLimit, &powerLimit);
+	ret = kstrtou8((const char *)Channel, 10, &channel);
+	if (ret)
+		return;
+
+	ret = kstrtou8((const char *)PowerLimit, 10, &powerLimit);
+	if (ret)
+		return;

This will change behaviour on the invalid data. Before it was just partially converted here and continue, now it breaks an execution. The commit message does not explain if it's safe to do or not (i.o.w. if there is a guarantee that in current state the input will be always in the correct form).

Quoted 6 lines
Quoted 1 line

Otherwise, you probably want to use one of simple_strtou*().

It only indirectly called from ODM_ReadAndConfig_MP_8723B_TXPWR_LMT() with constant values. Maybe we can convert this strings to ints so we don't need to do it at runtime. We can also remove the wrapper odm_ConfigBB_TXPWR_LMT_8723B(). This should be a seperate patch, right?

Quoted 7 lines

Just noticed ODM_ReadAndConfig_MP_8723B_TXPWR_LMT() didn't called anywhere. I will remove:
GetU1ByteIntegerFromStringInDecimal()
PHY_SetTxPowerLimit()
odm_ConfigBB_TXPWR_LMT_8723B() ODM_ReadAndConfig_MP_8723B_TXPWR_LMT()
in v2. They are all unusued.

Sounds good to me.

Signature · 2 lines
With Best Regards,
Andy Shevchenko