cilynx / rtl88x2bu

rtl88x2bu driver updated for current kernels.
http://www.wolfteck.com/2018/02/22/wsky_1200mbps_wireless_usb_wifi_adapter/
GNU General Public License v2.0
1.61k stars 316 forks source link

How to fix `-Werror=array-bounds` on 5.18.0rc1 #199

Closed MaxG87 closed 2 years ago

MaxG87 commented 2 years ago

With commit b06a17583f6f810f620f95382b171cc5ce9848ee in the Linux kernel, a build error upon possibly violated error bounds is enabled. This breaks the build of the driver:

rtl88x2bu/core/rtw_mi.c: In function ‘rtw_mi_p2p_chk_state’:
rtl88x2bu/core/rtw_mi.c:1249:24: error: array subscript ‘enum P2P_STATE[0]’ is partly outside array bounds of ‘u8[1]’ {aka ‘unsigned char[1]’} [-Werror=array-bounds]
 1249 |         enum P2P_STATE state = *(enum P2P_STATE *)data;
      |                        ^~~~~
rtl88x2bu/core/rtw_mi.c:1255:12: note: while referencing ‘in_data’
 1255 |         u8 in_data = p2p_state;
      |            ^~~~~~~
rtl88x2bu/core/rtw_mi.c: In function ‘rtw_mi_buddy_p2p_chk_state’:
rtl88x2bu/core/rtw_mi.c:1249:24: error: array subscript ‘enum P2P_STATE[0]’ is partly outside array bounds of ‘u8[1]’ {aka ‘unsigned char[1]’} [-Werror=array-bounds]
 1249 |         enum P2P_STATE state = *(enum P2P_STATE *)data;
      |                        ^~~~~
rtl88x2bu/core/rtw_mi.c:1261:12: note: while referencing ‘in_data’
 1261 |         u8 in_data  = p2p_state;
      |            ^~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [scripts/Makefile.build:289: rtl88x2bu/core/rtw_mi.o] Fehler 1
make[2]: *** Es wird auf noch nicht beendete Prozesse gewartet....
make[1]: *** [Makefile:1830: rtl88x2bu] Fehler 2
make: *** [Makefile:2390: modules] Fehler 2

I am over-asked about how to fix this. It looks like this is a false warning.

I could just suppress this in the Makefile. After all, the code did not become invalid all of a sudden. However, I very much would prefer to resolve the issue, e.g. by adding bounds checks or assertions. I just have no idea how so, my C is to rusty for that.

I would be very glad if someone could point out a proper solution. Otherwise I will default to suppress the error upon the release of 5.18.

MaxG87 commented 2 years ago

Fixed by disabling the check in 9957138ac30529a06bfcbc36eb51006a948b0967.