lwfinger / rtw88

A backport of the Realtek Wifi 5 drivers from the wireless-next repo.
649 stars 183 forks source link

Fix compiler warnings #220

Closed chrisBosse closed 4 months ago

chrisBosse commented 4 months ago

I suspect latest gcc version implements stricter checking.

My system is a Debian Linux Mint 21:

$ inxi -Sxxx
System:
  Host: Evolve02 Kernel: 5.15.0-116-generic x86_64 bits: 64 compiler: gcc v: 11.4.0
    Console: pty pts/2 DM: LightDM 1.30.0 Distro: Linux Mint 21 Vanessa base: Ubuntu 22.04 jammy
$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Errors:

$ make -j4
make -C /lib/modules/5.4.0-189-generic/build M=/home/chris/github/rtw88 modules
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-189-generic'
  CC [M]  /home/chris/github/rtw88/main.o
  CC [M]  /home/chris/github/rtw88/mac80211.o
  CC [M]  /home/chris/github/rtw88/util.o
  CC [M]  /home/chris/github/rtw88/debug.o
/home/chris/github/rtw88/main.c: In function ‘rtw_watch_dog_work’:
/home/chris/github/rtw88/main.c:261:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  261 |  int received_beacons = rtwdev->dm_info.cur_pkt_count.num_bcn_pkt;
      |  ^~~
  CC [M]  /home/chris/github/rtw88/tx.o
  CC [M]  /home/chris/github/rtw88/rx.o
  CC [M]  /home/chris/github/rtw88/mac.o
  CC [M]  /home/chris/github/rtw88/phy.o
  CC [M]  /home/chris/github/rtw88/coex.o
  CC [M]  /home/chris/github/rtw88/efuse.o
  CC [M]  /home/chris/github/rtw88/fw.o
  CC [M]  /home/chris/github/rtw88/ps.o
  CC [M]  /home/chris/github/rtw88/sec.o
  CC [M]  /home/chris/github/rtw88/wow.o
  CC [M]  /home/chris/github/rtw88/bf.o
  CC [M]  /home/chris/github/rtw88/regd.o
  CC [M]  /home/chris/github/rtw88/sar.o
  CC [M]  /home/chris/github/rtw88/rtw8822b.o
  CC [M]  /home/chris/github/rtw88/rtw8822b_table.o
  CC [M]  /home/chris/github/rtw88/rtw8822be.o
  CC [M]  /home/chris/github/rtw88/rtw8822bu.o
  CC [M]  /home/chris/github/rtw88/rtw8822bs.o
  CC [M]  /home/chris/github/rtw88/rtw8822c.o
  CC [M]  /home/chris/github/rtw88/rtw8822c_table.o
  CC [M]  /home/chris/github/rtw88/rtw8822ce.o
  CC [M]  /home/chris/github/rtw88/rtw8822cu.o
  CC [M]  /home/chris/github/rtw88/rtw8723x.o
  CC [M]  /home/chris/github/rtw88/rtw8703b.o
  CC [M]  /home/chris/github/rtw88/rtw8703b_tables.o
In file included from /home/chris/github/rtw88/rtw8723x.c:13:
/home/chris/github/rtw88/rtw8723x.h: In function ‘rtw8723x_iqk_path_adda_on’:
/home/chris/github/rtw88/rtw8723x.h:514:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  514 |  for (int i = 0; i < RTW8723X_IQK_ADDA_REG_NUM; i++)
      |  ^~~
/home/chris/github/rtw88/rtw8723x.h:514:2: note: use option ‘-std=c99’, ‘-std=gnu99’, ‘-std=c11’ or ‘-std=gnu11’ to compile your code
/home/chris/github/rtw88/rtw8723x.c: In function ‘__rtw8723x_debug_txpwr_limit’:
/home/chris/github/rtw88/rtw8723x.c:110:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  110 |  for (int i = 0; i < tx_path_count; i++)
      |  ^~~
/home/chris/github/rtw88/rtw8723x.c:123:11: error: redefinition of ‘i’
  123 |  for (int i = 0; i < tx_path_count; i++)
      |           ^
/home/chris/github/rtw88/rtw8723x.c:110:11: note: previous definition of ‘i’ was here
  110 |  for (int i = 0; i < tx_path_count; i++)
      |           ^
/home/chris/github/rtw88/rtw8723x.c:123:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  123 |  for (int i = 0; i < tx_path_count; i++)
      |  ^~~
/home/chris/github/rtw88/rtw8723x.c:133:11: error: redefinition of ‘i’
  133 |  for (int i = 0; i < tx_path_count; i++)
      |           ^
/home/chris/github/rtw88/rtw8723x.c:123:11: note: previous definition of ‘i’ was here
  123 |  for (int i = 0; i < tx_path_count; i++)
      |           ^
/home/chris/github/rtw88/rtw8723x.c:133:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  133 |  for (int i = 0; i < tx_path_count; i++)
      |  ^~~
/home/chris/github/rtw88/rtw8723x.c:145:11: error: redefinition of ‘i’
  145 |  for (int i = 0; i < tx_path_count; i++)
      |           ^
/home/chris/github/rtw88/rtw8723x.c:133:11: note: previous definition of ‘i’ was here
  133 |  for (int i = 0; i < tx_path_count; i++)
      |           ^
/home/chris/github/rtw88/rtw8723x.c:145:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  145 |  for (int i = 0; i < tx_path_count; i++)
      |  ^~~
/home/chris/github/rtw88/rtw8723x.c:156:11: error: redefinition of ‘i’
  156 |  for (int i = 0; i < tx_path_count; i++)
      |           ^
/home/chris/github/rtw88/rtw8723x.c:145:11: note: previous definition of ‘i’ was here
  145 |  for (int i = 0; i < tx_path_count; i++)
      |           ^
/home/chris/github/rtw88/rtw8723x.c:156:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  156 |  for (int i = 0; i < tx_path_count; i++)
      |  ^~~
/home/chris/github/rtw88/rtw8723x.c:167:11: error: redefinition of ‘i’
  167 |  for (int i = 0; i < tx_path_count; i++)
      |           ^
/home/chris/github/rtw88/rtw8723x.c:156:11: note: previous definition of ‘i’ was here
  156 |  for (int i = 0; i < tx_path_count; i++)
      |           ^
/home/chris/github/rtw88/rtw8723x.c:167:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  167 |  for (int i = 0; i < tx_path_count; i++)
      |  ^~~
make[2]: *** [scripts/Makefile.build:270: /home/chris/github/rtw88/rtw8723x.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /home/chris/github/rtw88/rtw8703b.h:7,
                 from /home/chris/github/rtw88/rtw8703b.c:13:
/home/chris/github/rtw88/rtw8723x.h: In function ‘rtw8723x_iqk_path_adda_on’:
/home/chris/github/rtw88/rtw8723x.h:514:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  514 |  for (int i = 0; i < RTW8723X_IQK_ADDA_REG_NUM; i++)
      |  ^~~
/home/chris/github/rtw88/rtw8723x.h:514:2: note: use option ‘-std=c99’, ‘-std=gnu99’, ‘-std=c11’ or ‘-std=gnu11’ to compile your code
/home/chris/github/rtw88/rtw8703b.c: In function ‘rtw8703b_read_efuse’:
/home/chris/github/rtw88/rtw8703b.c:582:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  582 |  for (int i = 0; i < ARRAY_SIZE(rtw8703b_txpwr_idx_table); i++)
      |  ^~~
/home/chris/github/rtw88/rtw8703b.c:588:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  588 |   for (int i = 0; i < ARRAY_SIZE(rtw8703b_txpwr_idx_table); i++)
      |   ^~~
/home/chris/github/rtw88/rtw8703b.c: In function ‘rtw8703b_iqk_config_mac’:
/home/chris/github/rtw88/rtw8703b.c:1103:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
 1103 |  for (int i = 1; i < RTW8723X_IQK_MAC8_REG_NUM; i++)
      |  ^~~
/home/chris/github/rtw88/rtw8703b.c: In function ‘rtw8703b_pwrtrack_set_cck_pwr’:
/home/chris/github/rtw88/rtw8703b.c:1674:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
 1674 |  for (int i = 0; i < ARRAY_SIZE(rtw8703b_cck_pwr_regs); i++)
      |  ^~~
make[2]: *** [scripts/Makefile.build:270: /home/chris/github/rtw88/rtw8703b.o] Error 1
make[1]: *** [Makefile:1778: /home/chris/github/rtw88] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-189-generic'
make: *** [Makefile:166: all] Error 2
a5a5aa555oo commented 4 months ago

Linux kernel switched from C89 to C11/GNU11 since 5.18 [1],
and gcc parameter "-Wdeclaration-after-statement" was dropped since 6.5 [2].

Would it be better to tell gcc to use C11/GNU11 standard and not to warn about the declarations after statement?

diff --git a/Makefile b/Makefile
index e059897..fdcb71f 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ ifeq ("","$(wildcard MOK.der)")
 NO_SKIP_SIGN := y
 endif

-EXTRA_CFLAGS += -O2
+EXTRA_CFLAGS += -O2 -std=gnu11 -Wno-declaration-after-statement
 ifeq ($(CONFIG_PCI), y)
 EXTRA_CFLAGS += -DCONFIG_RTW88_8822BE=1
 EXTRA_CFLAGS += -DCONFIG_RTW88_8821CE=1

[1]. https://github.com/torvalds/linux/commit/e8c07082a810fbb9db303a2b66b66b8d7e588b53 [2]. https://github.com/torvalds/linux/commit/b5ec6fd286dfa466f64cb0e56ed768092d0342ae

dubhater commented 4 months ago

I would rather change the CFLAGS than the code.

chrisBosse commented 4 months ago

Confirmed both @a5a5aa555oo 's flag additions are necessary and sufficient to eliminate compiler warnings.

@dubhater , I am new here. I am grateful for the driver. I defer to experience.

Shall I close this PR?

dubhater commented 4 months ago

@chrisBosse You could replace your commit with what @a5a5aa555oo suggested? @a5a5aa555oo Or will you open a pull request?

a5a5aa555oo commented 4 months ago

@chrisBosse Could you fix this issue when you have time? thank you very much!~

chrisBosse commented 4 months ago

Done.

Best to squash these commits, or I can open a new, clean pull request.

dubhater commented 4 months ago

Merged, thank you!