Skip to contentSkip to conversation

wifi: rtw89: 8852a: remove redundant else statement

PATCH In review Colin Ian King 4 participants 4 messages Oct 30, 2024 – Nov 1, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: rtw89: 8852a: remove redundant else statement

The cascaded if statements covers all 16 bit values in the comparisons of dgain and the last else statement is not reachable and hence dead code. Remove it.

---
 drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c +0 -2
index 9db8713ac99b..f3568c4d0af6 100644
@@ -2248,8 +2248,6 @@ static s8 _dpk_dgain_mapping(struct rtw89_dev *rtwdev, u16 dgain)
 		offset = -9;
 	else if (dgain <= 0x155)
 		offset = -12;
-	else
-		offset = 0x0;
 
 	return offset;
 }
Signature · 1 line
2.39.5
#1 lore raw
Quoted 14 lines · Colin Ian King

The cascaded if statements covers all 16 bit values in the comparisons of dgain and the last else statement is not reachable and hence dead code. Remove it.

---
 drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c +0 -0
index 9db8713ac99b..f3568c4d0af6 100644

drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c static s8 _dpk_dgain_mapping(struct rtw89_dev *rtwdev, u16 dgain) · line 2249

Quoted 2 lines
drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c +0 -0
@@ -2248,8 +2248,6 @@ static s8 _dpk_dgain_mapping(struct rtw89_dev *rtwdev, u16 dgain)
 		offset = -9;
 	else if (dgain <= 0x155)

should you drop the test and unconditionally return -12 here?

Quoted 6 lines
drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c +0 -2
 		offset = -12;
-	else
-		offset = 0x0;
 
 	return offset;
 }
maintainer
#2 lore raw
Quoted 10 lines · Jeff Johnson
Quoted 9 lines · Colin Ian King

The cascaded if statements covers all 16 bit values in the comparisons of dgain and the last else statement is not reachable and hence dead code. Remove it.

---
 drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c | 2 --
 1 file changed, 2 deletions(-)
Quoted 9 lines

drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c static s8 _dpk_dgain_mapping(struct rtw89_dev *rtwdev, u16 dgain) · line 2249

Quoted 7 lines
drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c +0 -0
index 9db8713ac99b..f3568c4d0af6 100644
@@ -2248,8 +2248,6 @@ static s8 _dpk_dgain_mapping(struct rtw89_dev *rtwdev, u16 dgain)
              offset = -9;
      else if (dgain <= 0x155)

should you drop the test and unconditionally return -12 here?

Agree +1. People don't suspect the else case at first glance.

Quoted 8 lines
Quoted 7 lines
drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c +0 -2
              offset = -12;
-     else
-             offset = 0x0;
 
      return offset;
 }
#3 lore raw
In reply to Colin Ian King
kernel test robot noticed the following build warnings:

Hi Colin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on wireless-next/main]
[also build test WARNING on wireless/main linus/master v6.12-rc5 next-20241101] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Colin-Ian-King/wifi-rtw89-8852a-remove-redundant-else-statement/20241030-211507
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main
patch link:    https://lore.kernel.org/r/20241030131416.3091954-1-colin.i.king%40gmail.com
patch subject: [PATCH][next] wifi: rtw89: 8852a: remove redundant else statement
config: um-allmodconfig (https://download.01.org/0day-ci/archive/20241102/[email protected]/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 639a7ac648f1e50ccd2556e17d401c04f9cce625)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241102/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c:5:
In file included from drivers/net/wireless/realtek/rtw89/coex.h:8:
In file included from drivers/net/wireless/realtek/rtw89/core.h:12:
In file included from include/linux/iopoll.h:14:
In file included from include/linux/io.h:14:
In file included from arch/um/include/asm/io.h:24:
include/asm-generic/io.h:548:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]

     548 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:561:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     561 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
         |                                                   ^
   In file included from drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c:5:
   In file included from drivers/net/wireless/realtek/rtw89/coex.h:8:
   In file included from drivers/net/wireless/realtek/rtw89/core.h:12:
   In file included from include/linux/iopoll.h:14:
   In file included from include/linux/io.h:14:
   In file included from arch/um/include/asm/io.h:24:
   include/asm-generic/io.h:574:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     574 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
         |                                                   ^
   In file included from drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c:5:
   In file included from drivers/net/wireless/realtek/rtw89/coex.h:8:
   In file included from drivers/net/wireless/realtek/rtw89/core.h:12:
   In file included from include/linux/iopoll.h:14:
   In file included from include/linux/io.h:14:
   In file included from arch/um/include/asm/io.h:24:
   include/asm-generic/io.h:585:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     585 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:595:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     595 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:605:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     605 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:693:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     693 |         readsb(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:701:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     701 |         readsw(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:709:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     709 |         readsl(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:718:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     718 |         writesb(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:727:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     727 |         writesw(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:736:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     736 |         writesl(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   In file included from drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c:5:
   In file included from drivers/net/wireless/realtek/rtw89/coex.h:8:
   In file included from drivers/net/wireless/realtek/rtw89/core.h:14:
   In file included from include/net/mac80211.h:18:
   In file included from include/linux/if_ether.h:19:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:8:
   In file included from include/linux/cacheflush.h:5:
   In file included from arch/um/include/asm/cacheflush.h:4:
   In file included from arch/um/include/asm/tlbflush.h:9:
   In file included from include/linux/mm.h:2213:
   include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     518 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
>> drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c:2249:11: warning: variable 'offset' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    2249 |         else if (dgain <= 0x155)
         |                  ^~~~~~~~~~~~~~
   drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c:2252:9: note: uninitialized use occurs here
    2252 |         return offset;
         |                ^~~~~~
   drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c:2249:7: note: remove the 'if' if its condition is always true
    2249 |         else if (dgain <= 0x155)
         |              ^~~~~~~~~~~~~~~~~~~
    2250 |                 offset = -12;
   drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c:2235:11: note: initialize the variable 'offset' to silence this warning
    2235 |         s8 offset;
         |                  ^
         |                   = '\0'

14 warnings generated.

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for GET_FREE_REGION Depends on [n]: SPARSEMEM [=n]
Selected by [m]:
- RESOURCE_KUNIT_TEST [=m] && RUNTIME_TESTING_MENU [=y] && KUNIT [=m]

vim +2249 drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c

e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2232  
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2233  static s8 _dpk_dgain_mapping(struct rtw89_dev *rtwdev, u16 dgain)
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2234  {
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2235  	s8 offset;
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2236  
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2237  	if (dgain >= 0x783)
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2238  		offset = 0x6;
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2239  	else if (dgain <= 0x782 && dgain >= 0x551)
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2240  		offset = 0x3;
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2241  	else if (dgain <= 0x550 && dgain >= 0x3c4)
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2242  		offset = 0x0;
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2243  	else if (dgain <= 0x3c3 && dgain >= 0x2aa)
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2244  		offset = -3;
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2245  	else if (dgain <= 0x2a9 && dgain >= 0x1e3)
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2246  		offset = -6;
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2247  	else if (dgain <= 0x1e2 && dgain >= 0x156)
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2248  		offset = -9;
e3ec7017f6a20d Ping-Ke Shih 2021-10-11 @2249  	else if (dgain <= 0x155)
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2250  		offset = -12;
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2251  
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2252  	return offset;
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2253  }
e3ec7017f6a20d Ping-Ke Shih 2021-10-11  2254  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki