wifi: rtw89: correct improper data types found by Coverity
Ping-Ke Shih
maintainercover wifi: rtw89: correct improper data types found by Coverity
First patch is to be intended to cast u64 in arithmetic to avoid Coverity confusing. The others are to use 'int' instead of 'u32' as type of error code, which are suddenly not to follow coding convention.
Ping-Ke Shih (6):
wifi: rtw89: wow: cast nd_config->delay to u64 in tsf arithmetic
wifi: rtw89: pci: use 'int' as return type of error code in
poll_{tx,rx}dma_ch_idle()
wifi: rtw89: 8851b: use 'int' as return type of error code
pwr_{on,off}_func()
wifi: rtw89: 8852b: use 'int' as return type of error code
pwr_{on,off}_func()
wifi: rtw89: 8852bt: use 'int' as return type of error code
pwr_{on,off}_func()
wifi: rtw89: 8852c: use 'int' as return type of error code
pwr_{on,off}_func()drivers/net/wireless/realtek/rtw89/fw.c | 2 +- drivers/net/wireless/realtek/rtw89/pci.c | 6 ++++-- drivers/net/wireless/realtek/rtw89/rtw8851b.c | 4 ++-- drivers/net/wireless/realtek/rtw89/rtw8852b.c | 4 ++-- drivers/net/wireless/realtek/rtw89/rtw8852bt.c | 4 ++-- drivers/net/wireless/realtek/rtw89/rtw8852c.c | 4 ++-- 6 files changed, 13 insertions(+), 11 deletions(-)
Signature · 1 line
2.25.1
Ping-Ke Shih
maintainerPATCH 1/6 wifi: rtw89: wow: cast nd_config->delay to u64 in tsf arithmetic
The type of tsf arithmetic is
u64 += u16 * int;
When (u16 * int) is larger than 0x7FFFFFFF, the value casting to u64 with sign-extension will become all 1 in upper 32 bits part.
To meet the case, u16 value should be larger than 20491 (0x7FFFFFFF / 104800). Fortunately the meaning of 20491 is delay time of WoWLAN net detection in unit of second, so 20491 seconds (5.7 hours) might not a real case we can meet.
Addresses-Coverity-ID: 1620910 ("Unintended sign extension")
--- drivers/net/wireless/realtek/rtw89/fw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw89/fw.c +1 -1
@@ -4963,7 +4963,7 @@ int rtw89_fw_h2c_scan_offload_ax(struct rtw89_dev *rtwdev, scan_mode =RTW89_SCAN_IMMEDIATE ; }else { scan_mode =RTW89_SCAN_DELAY ; - tsf += option->delay *RTW89_SCAN_DELAY_TSF_UNIT ; + tsf += (u64 )option->delay *RTW89_SCAN_DELAY_TSF_UNIT ; } }
Signature · 1 line
2.25.1
Ping-Ke Shih
maintainerRe: [PATCH 1/6] wifi: rtw89: wow: cast nd_config->delay to u64 in tsf arithmetic
Quoted 6 lines · Ping-Ke Shih
The type of tsf arithmetic is
u64 += u16 * int;When (u16 * int) is larger than
0x7FFFFFFF, the value casting to u64 with sign-extension will become all 1 in upper 32 bits part.
Quoted 8 lines
To meet the case, u16 value should be larger than 20491 (
0x7FFFFFFF/ 104800). Fortunately the meaning of 20491 is delay time of WoWLAN net detection in unit of second, so 20491 seconds (5.7 hours) might not a real case we can meet.Addresses-Coverity-ID: 1620910 ("Unintended sign extension")
Signed-off-by Ping-Ke Shih <[email protected]>
6 patch(es) applied to rtw-next branch of rtw.git, thanks.
5af57c4f9937 wifi: rtw89: wow: cast nd_config->delay to u64 in tsf arithmetic 778e2478d195 wifi: rtw89: pci: use 'int' as return type of error code in poll_{tx,rx}dma_ch_idle() 66595e319886 wifi: rtw89: 8851b: use 'int' as return type of error code pwr_{on,off}_func() 50e9febff35f wifi: rtw89: 8852b: use 'int' as return type of error code pwr_{on,off}_func() c72c54fd96d0 wifi: rtw89: 8852bt: use 'int' as return type of error code pwr_{on,off}_func() 74432751ff63 wifi: rtw89: 8852c: use 'int' as return type of error code pwr_{on,off}_func()
Ping-Ke Shih
maintainerPATCH 2/6 wifi: rtw89: pci: use 'int' as return type of error code in poll_{tx,rx}dma_ch_idle()
In reply to Ping-Ke ShihThe return type of error code of read_poll_timeout() and rtw89_pci_poll_{tx,rx}dma_ch_idle_ax() and must be 'int'. Correct them accordingly.
Addresses-Coverity-ID: 1622341 ("Overflowed constant")
Addresses-Coverity-ID: 1627296 ("Overflowed constant")
--- drivers/net/wireless/realtek/rtw89/pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw89/pci.c +4 -2
@@ -2671,9 +2671,10 @@ static void rtw89_pci_clr_idx_all_ax(struct rtw89_dev *rtwdev)static int rtw89_pci_poll_txdma_ch_idle_ax (struct rtw89_dev *rtwdev) {const struct rtw89_pci_info *info = rtwdev->pci_info; -u32 ret, check, dma_busy;u32 dma_busy1 = info->dma_busy1.addr;u32 dma_busy2 = info->dma_busy2_reg; +u32 check, dma_busy; +int ret; check = info->dma_busy1.mask;
@@ -2698,8 +2699,9 @@ static int rtw89_pci_poll_txdma_ch_idle_ax(struct rtw89_dev *rtwdev)static int rtw89_pci_poll_rxdma_ch_idle_ax (struct rtw89_dev *rtwdev) {const struct rtw89_pci_info *info = rtwdev->pci_info; -u32 ret, check, dma_busy;u32 dma_busy3 = info->dma_busy3_reg; +u32 check, dma_busy; +int ret; check =B_AX_RXQ_BUSY |B_AX_RPQ_BUSY ;
Signature · 1 line
2.25.1
Ping-Ke Shih
maintainerPATCH 3/6 wifi: rtw89: 8851b: use 'int' as return type of error code pwr_{on,off}_func()
In reply to Ping-Ke ShihThe return type of error code of rtw8851b_pwr_{on,off}_func() and its callee is 'int'. Correct it.
Addresses-Coverity-ID: 1624679 ("Overflowed constant")
Addresses-Coverity-ID: 1630970 ("Overflowed constant")
--- drivers/net/wireless/realtek/rtw89/rtw8851b.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw89/rtw8851b.c +2 -2
@@ -282,7 +282,7 @@ static int rtw8851b_pwr_on_func(struct rtw89_dev *rtwdev) {u32 val32;u8 val8; -u32 ret; +int ret;rtw89_write32_clr (rtwdev,R_AX_SYS_PW_CTRL ,B_AX_AFSM_WLSUS_EN |B_AX_AFSM_PCIE_SUS_EN );
@@ -401,7 +401,7 @@ static void rtw8851b_patch_swr_pfm2pwm(struct rtw89_dev *rtwdev)static int rtw8851b_pwr_off_func (struct rtw89_dev *rtwdev) {u32 val32; -u32 ret; +int ret; ret =rtw89_mac_write_xtal_si (rtwdev,XTAL_SI_ANAPAR_WL ,XTAL_SI_RFC2RF ,XTAL_SI_RFC2RF );
Signature · 1 line
2.25.1
Ping-Ke Shih
maintainerPATCH 4/6 wifi: rtw89: 8852b: use 'int' as return type of error code pwr_{on,off}_func()
In reply to Ping-Ke ShihThe return type of error code of rtw8852b_pwr_{on,off}_func() and its callee is 'int'. Correct it.
Addresses-Coverity-ID: 1622433 ("Overflowed constant")
Addresses-Coverity-ID: 1630710 ("Overflowed constant")
--- drivers/net/wireless/realtek/rtw89/rtw8852b.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw89/rtw8852b.c +2 -2
@@ -254,7 +254,7 @@ static void rtw8852b_pwr_sps_ana(struct rtw89_dev *rtwdev)static int rtw8852b_pwr_on_func (struct rtw89_dev *rtwdev) {u32 val32; -u32 ret; +int ret;rtw8852b_pwr_sps_ana (rtwdev);
@@ -383,7 +383,7 @@ static int rtw8852b_pwr_on_func(struct rtw89_dev *rtwdev)static int rtw8852b_pwr_off_func (struct rtw89_dev *rtwdev) {u32 val32; -u32 ret; +int ret;rtw8852b_pwr_sps_ana (rtwdev);
Signature · 1 line
2.25.1
Ping-Ke Shih
maintainerPATCH 5/6 wifi: rtw89: 8852bt: use 'int' as return type of error code pwr_{on,off}_func()
In reply to Ping-Ke ShihThe return type of error code of rtw8852bt_pwr_{on,off}_func() and its callee is 'int'. Correct it.
Addresses-Coverity-ID: 1630962 ("Overflowed constant")
Addresses-Coverity-ID: 1632126 ("Overflowed constant")
--- drivers/net/wireless/realtek/rtw89/rtw8852bt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw89/rtw8852bt.c +2 -2
@@ -244,7 +244,7 @@ static const u8 rtw89_btc_8852bt_bt_rssi_thres[BTC_BT_RSSI_THMAX] = {50, 40, 30,static int rtw8852bt_pwr_on_func (struct rtw89_dev *rtwdev) {u32 val32; -u32 ret; +int ret;rtw89_write32_set (rtwdev,R_AX_LDO_AON_CTRL0 ,B_AX_PD_REGU_L ); rtw89_write32_clr(rtwdev, R_AX_SYS_PW_CTRL, B_AX_AFSM_WLSUS_EN |
@@ -357,7 +357,7 @@ static int rtw8852bt_pwr_on_func(struct rtw89_dev *rtwdev)static int rtw8852bt_pwr_off_func (struct rtw89_dev *rtwdev) {u32 val32; -u32 ret; +int ret; ret =rtw89_mac_write_xtal_si (rtwdev,XTAL_SI_ANAPAR_WL ,XTAL_SI_RFC2RF ,XTAL_SI_RFC2RF );
Signature · 1 line
2.25.1
Ping-Ke Shih
maintainerPATCH 6/6 wifi: rtw89: 8852c: use 'int' as return type of error code pwr_{on,off}_func()
In reply to Ping-Ke ShihThe return type of error code of rtw8852c_pwr_{on,off}_func() and its callee is 'int'. Correct it.
Addresses-Coverity-ID: 1626056 ("Overflowed constant")
Addresses-Coverity-ID: 1627945 ("Overflowed constant")
--- drivers/net/wireless/realtek/rtw89/rtw8852c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw89/rtw8852c.c +2 -2
@@ -203,7 +203,7 @@ static void rtw8852c_ctrl_tx_path_tmac(struct rtw89_dev *rtwdev, u8 tx_path,static int rtw8852c_pwr_on_func (struct rtw89_dev *rtwdev) {u32 val32; -u32 ret; +int ret; val32 =rtw89_read32_mask (rtwdev,R_AX_SYS_STATUS1 ,B_AX_PAD_HCI_SEL_V2_MASK );if (val32 ==MAC_AX_HCI_SEL_PCIE_USB )
@@ -324,7 +324,7 @@ static int rtw8852c_pwr_on_func(struct rtw89_dev *rtwdev)static int rtw8852c_pwr_off_func (struct rtw89_dev *rtwdev) {u32 val32; -u32 ret; +int ret; ret =rtw89_mac_write_xtal_si (rtwdev,XTAL_SI_ANAPAR_WL ,XTAL_SI_RFC2RF ,XTAL_SI_RFC2RF );
Signature · 1 line
2.25.1