[PATCH] staging: rtl8723bs: refactor halbtc8723b1ant_CoexTableWithType() to remove duplication

Bera Yüzlü posted 1 patch 1 day, 4 hours ago
.../staging/rtl8723bs/hal/HalBtc8723b1Ant.c   | 55 +++++--------------
1 file changed, 13 insertions(+), 42 deletions(-)
[PATCH] staging: rtl8723bs: refactor halbtc8723b1ant_CoexTableWithType() to remove duplication
Posted by Bera Yüzlü 1 day, 4 hours ago
Replace the verbose switch-case block with a constant 2D array lookup.
This makes the function much more concise and easier to read without
changing the underlying behavior.

Signed-off-by: Bera Yüzlü <b9788213@gmail.com>
---
 .../staging/rtl8723bs/hal/HalBtc8723b1Ant.c   | 55 +++++--------------
 1 file changed, 13 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
index b3d7f50fac4c..d3c7a4b32ff5 100644
--- a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
+++ b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
@@ -684,52 +684,23 @@ static void halbtc8723b1ant_CoexTableWithType(
 	struct btc_coexist *pBtCoexist, bool bForceExec, u8 type
 )
 {
+	static const u32 table[8][2] = {
+		{0x55555555, 0x55555555},
+		{0x55555555, 0x5a5a5a5a},
+		{0x5a5a5a5a, 0x5a5a5a5a},
+		{0xaaaa5555, 0xaaaa5a5a},
+		{0x55555555, 0xaaaa5a5a},
+		{0x5a5a5a5a, 0xaaaa5a5a},
+		{0x55555555, 0xaaaaaaaa},
+		{0xaaaaaaaa, 0xaaaaaaaa}
+	};
+
 	pCoexSta->nCoexTableType = type;
 
-	switch (type) {
-	case 0:
-		halbtc8723b1ant_CoexTable(
-			pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3
-		);
-		break;
-	case 1:
-		halbtc8723b1ant_CoexTable(
-			pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3
-		);
-		break;
-	case 2:
-		halbtc8723b1ant_CoexTable(
-			pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3
-		);
-		break;
-	case 3:
-		halbtc8723b1ant_CoexTable(
-			pBtCoexist, bForceExec, 0xaaaa5555, 0xaaaa5a5a, 0xffffff, 0x3
-		);
-		break;
-	case 4:
+	if (-1 < type && type < 8)
 		halbtc8723b1ant_CoexTable(
-			pBtCoexist, bForceExec, 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3
+			pBtCoexist, bForceExec, table[type][0], table[type][1], 0xffffff, 0x3
 		);
-		break;
-	case 5:
-		halbtc8723b1ant_CoexTable(
-			pBtCoexist, bForceExec, 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3
-		);
-		break;
-	case 6:
-		halbtc8723b1ant_CoexTable(
-			pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3
-		);
-		break;
-	case 7:
-		halbtc8723b1ant_CoexTable(
-			pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3
-		);
-		break;
-	default:
-		break;
-	}
 }
 
 static void halbtc8723b1ant_SetFwIgnoreWlanAct(
-- 
2.43.0
Re: [PATCH] staging: rtl8723bs: refactor halbtc8723b1ant_CoexTableWithType() to remove duplication
Posted by kernel test robot 22 hours ago
Hi Bera,

kernel test robot noticed the following build warnings:

[auto build test WARNING on staging/staging-testing]

url:    https://github.com/intel-lab-lkp/linux/commits/Bera-Y-zl/staging-rtl8723bs-refactor-halbtc8723b1ant_CoexTableWithType-to-remove-duplication/20260208-211800
base:   staging/staging-testing
patch link:    https://lore.kernel.org/r/aYiMi-X5r4aUEC32%40BERA.localdomain
patch subject: [PATCH] staging: rtl8723bs: refactor halbtc8723b1ant_CoexTableWithType() to remove duplication
config: sparc64-allmodconfig (https://download.01.org/0day-ci/archive/20260209/202602090207.A176hCPb-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 9b8addffa70cee5b2acc5454712d9cf78ce45710)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260209/202602090207.A176hCPb-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602090207.A176hCPb-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c:700:9: warning: result of comparison of constant -1 with expression of type 'u8' (aka 'unsigned char') is always true [-Wtautological-constant-out-of-range-compare]
     700 |         if (-1 < type && type < 8)
         |             ~~ ^ ~~~~
   1 warning generated.


vim +700 drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c

   682	
   683	static void halbtc8723b1ant_CoexTableWithType(
   684		struct btc_coexist *pBtCoexist, bool bForceExec, u8 type
   685	)
   686	{
   687		static const u32 table[8][2] = {
   688			{0x55555555, 0x55555555},
   689			{0x55555555, 0x5a5a5a5a},
   690			{0x5a5a5a5a, 0x5a5a5a5a},
   691			{0xaaaa5555, 0xaaaa5a5a},
   692			{0x55555555, 0xaaaa5a5a},
   693			{0x5a5a5a5a, 0xaaaa5a5a},
   694			{0x55555555, 0xaaaaaaaa},
   695			{0xaaaaaaaa, 0xaaaaaaaa}
   696		};
   697	
   698		pCoexSta->nCoexTableType = type;
   699	
 > 700		if (-1 < type && type < 8)
   701			halbtc8723b1ant_CoexTable(
   702				pBtCoexist, bForceExec, table[type][0], table[type][1], 0xffffff, 0x3
   703			);
   704	}
   705	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki