diff mbox series

[next] wifi: rtw89: 8852a: remove redundant else statement

Message ID 20241030131416.3091954-1-colin.i.king@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Ping-Ke Shih
Headers show
Series [next] wifi: rtw89: 8852a: remove redundant else statement | expand

Commit Message

Colin Ian King Oct. 30, 2024, 1:14 p.m. UTC
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.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c | 2 --
 1 file changed, 2 deletions(-)

Comments

Jeff Johnson Oct. 30, 2024, 8:55 p.m. UTC | #1
On 10/30/2024 6:14 AM, Colin Ian King wrote:
> 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.
> 
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> ---
>  drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c b/drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c
> index 9db8713ac99b..f3568c4d0af6 100644
> --- a/drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c
> +++ b/drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c
> @@ -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?

>  		offset = -12;
> -	else
> -		offset = 0x0;
>  
>  	return offset;
>  }
Ping-Ke Shih Oct. 31, 2024, 2:22 a.m. UTC | #2
Jeff Johnson <quic_jjohnson@quicinc.com> wrote:
> On 10/30/2024 6:14 AM, Colin Ian King wrote:
> > 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.
> >
> > Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> > ---
> >  drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c | 2 --
> >  1 file changed, 2 deletions(-)
> >
> > diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c b/drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c
> > index 9db8713ac99b..f3568c4d0af6 100644
> > --- a/drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c
> > +++ b/drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c
> > @@ -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. 

> 
> >               offset = -12;
> > -     else
> > -             offset = 0x0;
> >
> >       return offset;
> >  }
>
kernel test robot Nov. 1, 2024, 6:22 p.m. UTC | #3
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/202411020209.qamp5h6r-lkp@intel.com/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/202411020209.qamp5h6r-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/202411020209.qamp5h6r-lkp@intel.com/

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
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c b/drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c
index 9db8713ac99b..f3568c4d0af6 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8852a_rfk.c
@@ -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;
 }