RE: drivers/net/wireless/realtek/rtw89/coex.c:1448:17: warning: writing 8 bytes into a region of size 0

From: Ping-Ke Shih
Date: Wed Nov 01 2023 - 20:47:15 EST




> -----Original Message-----
> From: kernel test robot <lkp@xxxxxxxxx>
> Sent: Monday, October 30, 2023 7:48 PM
> To: Ping-Ke Shih <pkshih@xxxxxxxxxxx>
> Cc: oe-kbuild-all@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; Kalle Valo <kvalo@xxxxxxxxxx>
> Subject: drivers/net/wireless/realtek/rtw89/coex.c:1448:17: warning: writing 8 bytes into a region of size
> 0

drivers/net/wireless/realtek/rtw89/coex.c: In function '_append_tdma':
>> drivers/net/wireless/realtek/rtw89/coex.c:1448:17: warning: writing 8 bytes into a region of size 0 [-Wstringop-overflow=]
1448 | memcpy(v, &dm->tdma, sizeof(*v));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> e3ec7017f6a20d Ping-Ke Shih 2021-10-11 1442
> e3ec7017f6a20d Ping-Ke Shih 2021-10-11 1443 tlv = (struct rtw89_btc_btf_tlv *)&btc->policy[len];
> e3ec7017f6a20d Ping-Ke Shih 2021-10-11 1444 tlv->type = CXPOLICY_TDMA;
> ce986f3dc4fc69 Ching-Te Ku 2022-07-25 1445 if (chip->chip_id == RTL8852A) {
> ce986f3dc4fc69 Ching-Te Ku 2022-07-25 1446 v = (struct rtw89_btc_fbtc_tdma *)&tlv->val[0];
> e3ec7017f6a20d Ping-Ke Shih 2021-10-11 1447 tlv->len = sizeof(*v);
> e3ec7017f6a20d Ping-Ke Shih 2021-10-11 @1448 memcpy(v, &dm->tdma, sizeof(*v));

This statement is to append a struct named rtw89_btc_fbtc_tdma to value field of
a TLV struct, but compiler warns dst of memcpy() because of tlv->val[]. Maybe,
this is a false alarm?

Anyway, for this case, a simple assignment "*v = dm->tdma;" would be easier to
understand what it wants and also avoid compiler warnings. Then, I sent a
patch [1] for this.

[1] https://lore.kernel.org/linux-wireless/20231102003716.25815-1-pkshih@xxxxxxxxxxx/T/#u