2019-11-21 21:55:59

by Larry Finger

[permalink] [raw]
Subject: [PATCH 4/9] rtlwifi: Remove dependence on special bit manipulation macros for common driver

The special macros are used in several places in the base driver.
These are replaced by standard bit manipulation macros or code.

Signed-off-by: Larry Finger <[email protected]>
---
drivers/net/wireless/realtek/rtlwifi/base.h | 4 ++--
drivers/net/wireless/realtek/rtlwifi/ps.c | 20 ++++++++++----------
2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.h b/drivers/net/wireless/realtek/rtlwifi/base.h
index e4a7e074ae3f..fa92e29fffda 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.h
+++ b/drivers/net/wireless/realtek/rtlwifi/base.h
@@ -61,9 +61,9 @@ enum ap_peer {
CP_MACADDR((u8 *)(_hdr)+FRAME_OFFSET_ADDRESS3, (u8 *)(_val))

#define SET_TX_DESC_SPE_RPT(__pdesc, __val) \
- SET_BITS_TO_LE_4BYTE((__pdesc) + 8, 19, 1, __val)
+ le32p_replace_bits((__le32 *)(__pdesc + 8), __val, BIT(19))
#define SET_TX_DESC_SW_DEFINE(__pdesc, __val) \
- SET_BITS_TO_LE_4BYTE((__pdesc) + 24, 0, 12, __val)
+ le32p_replace_bits((__le32 *)(__pdesc + 24), __val, GENMASK(11, 0))

int rtl_init_core(struct ieee80211_hw *hw);
void rtl_deinit_core(struct ieee80211_hw *hw);
diff --git a/drivers/net/wireless/realtek/rtlwifi/ps.c b/drivers/net/wireless/realtek/rtlwifi/ps.c
index e5e1ec5a41dc..bc0ac96ee615 100644
--- a/drivers/net/wireless/realtek/rtlwifi/ps.c
+++ b/drivers/net/wireless/realtek/rtlwifi/ps.c
@@ -737,7 +737,7 @@ static void rtl_p2p_noa_ie(struct ieee80211_hw *hw, void *data,
find_p2p_ie = true;
/*to find noa ie*/
while (ie + 1 < end) {
- noa_len = READEF2BYTE((__le16 *)&ie[1]);
+ noa_len = le16_to_cpu(*((__le16 *)&ie[1]));
if (ie + 3 + ie[1] > end)
return;

@@ -766,16 +766,16 @@ static void rtl_p2p_noa_ie(struct ieee80211_hw *hw, void *data,
index = 5;
for (i = 0; i < noa_num; i++) {
p2pinfo->noa_count_type[i] =
- READEF1BYTE(ie+index);
+ *(u8 *)(ie + index);
index += 1;
p2pinfo->noa_duration[i] =
- READEF4BYTE((__le32 *)ie+index);
+ le32_to_cpu(*(__le32 *)ie + index);
index += 4;
p2pinfo->noa_interval[i] =
- READEF4BYTE((__le32 *)ie+index);
+ le32_to_cpu(*(__le32 *)ie + index);
index += 4;
p2pinfo->noa_start_time[i] =
- READEF4BYTE((__le32 *)ie+index);
+ le32_to_cpu(*(__le32 *)ie + index);
index += 4;
}

@@ -832,7 +832,7 @@ static void rtl_p2p_action_ie(struct ieee80211_hw *hw, void *data,
RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD, "action frame find P2P IE.\n");
/*to find noa ie*/
while (ie + 1 < end) {
- noa_len = READEF2BYTE((__le16 *)&ie[1]);
+ noa_len = le16_to_cpu(*(__le16 *)&ie[1]);
if (ie + 3 + ie[1] > end)
return;

@@ -861,16 +861,16 @@ static void rtl_p2p_action_ie(struct ieee80211_hw *hw, void *data,
index = 5;
for (i = 0; i < noa_num; i++) {
p2pinfo->noa_count_type[i] =
- READEF1BYTE(ie+index);
+ *(u8 *)(ie + index);
index += 1;
p2pinfo->noa_duration[i] =
- READEF4BYTE((__le32 *)ie+index);
+ le32_to_cpu(*(__le32 *)ie + index);
index += 4;
p2pinfo->noa_interval[i] =
- READEF4BYTE((__le32 *)ie+index);
+ le32_to_cpu(*(__le32 *)ie + index);
index += 4;
p2pinfo->noa_start_time[i] =
- READEF4BYTE((__le32 *)ie+index);
+ le32_to_cpu(*(__le32 *)ie + index);
index += 4;
}

--
2.24.0


2019-11-25 03:12:28

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 4/9] rtlwifi: Remove dependence on special bit manipulation macros for common driver

Hi Larry,

I love your patch! Perhaps something to improve:

[auto build test WARNING on wireless-drivers-next/master]
[also build test WARNING on v5.4-rc8 next-20191122]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Larry-Finger/rtlwifi-Complete-removal-of-local-bit-manipulation-macros/20191124-123220
base: https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers-next.git master
reproduce:
# apt-get install sparse
# sparse version: v0.6.1-36-g9305d48-dirty
make ARCH=x86_64 allmodconfig
make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <[email protected]>


sparse warnings: (new ones prefixed by >>)

>> drivers/net/wireless/realtek/rtlwifi/ps.c:772:42: sparse: sparse: restricted __le32 degrades to integer
>> drivers/net/wireless/realtek/rtlwifi/ps.c:772:42: sparse: sparse: cast to restricted __le32
drivers/net/wireless/realtek/rtlwifi/ps.c:775:42: sparse: sparse: restricted __le32 degrades to integer
drivers/net/wireless/realtek/rtlwifi/ps.c:775:42: sparse: sparse: cast to restricted __le32
drivers/net/wireless/realtek/rtlwifi/ps.c:778:42: sparse: sparse: restricted __le32 degrades to integer
drivers/net/wireless/realtek/rtlwifi/ps.c:778:42: sparse: sparse: cast to restricted __le32
drivers/net/wireless/realtek/rtlwifi/ps.c:867:42: sparse: sparse: restricted __le32 degrades to integer
drivers/net/wireless/realtek/rtlwifi/ps.c:867:42: sparse: sparse: cast to restricted __le32
drivers/net/wireless/realtek/rtlwifi/ps.c:870:42: sparse: sparse: restricted __le32 degrades to integer
drivers/net/wireless/realtek/rtlwifi/ps.c:870:42: sparse: sparse: cast to restricted __le32
drivers/net/wireless/realtek/rtlwifi/ps.c:873:42: sparse: sparse: restricted __le32 degrades to integer
drivers/net/wireless/realtek/rtlwifi/ps.c:873:42: sparse: sparse: cast to restricted __le32

vim +772 drivers/net/wireless/realtek/rtlwifi/ps.c

705
706 static void rtl_p2p_noa_ie(struct ieee80211_hw *hw, void *data,
707 unsigned int len)
708 {
709 struct rtl_priv *rtlpriv = rtl_priv(hw);
710 struct ieee80211_mgmt *mgmt = data;
711 struct rtl_p2p_ps_info *p2pinfo = &(rtlpriv->psc.p2p_ps_info);
712 u8 *pos, *end, *ie;
713 u16 noa_len;
714 static u8 p2p_oui_ie_type[4] = {0x50, 0x6f, 0x9a, 0x09};
715 u8 noa_num, index , i, noa_index = 0;
716 bool find_p2p_ie = false , find_p2p_ps_ie = false;
717
718 pos = (u8 *)mgmt->u.beacon.variable;
719 end = data + len;
720 ie = NULL;
721
722 while (pos + 1 < end) {
723 if (pos + 2 + pos[1] > end)
724 return;
725
726 if (pos[0] == 221 && pos[1] > 4) {
727 if (memcmp(&pos[2], p2p_oui_ie_type, 4) == 0) {
728 ie = pos + 2+4;
729 break;
730 }
731 }
732 pos += 2 + pos[1];
733 }
734
735 if (ie == NULL)
736 return;
737 find_p2p_ie = true;
738 /*to find noa ie*/
739 while (ie + 1 < end) {
740 noa_len = le16_to_cpu(*((__le16 *)&ie[1]));
741 if (ie + 3 + ie[1] > end)
742 return;
743
744 if (ie[0] == 12) {
745 find_p2p_ps_ie = true;
746 if ((noa_len - 2) % 13 != 0) {
747 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
748 "P2P notice of absence: invalid length.%d\n",
749 noa_len);
750 return;
751 } else {
752 noa_num = (noa_len - 2) / 13;
753 if (noa_num > P2P_MAX_NOA_NUM)
754 noa_num = P2P_MAX_NOA_NUM;
755
756 }
757 noa_index = ie[3];
758 if (rtlpriv->psc.p2p_ps_info.p2p_ps_mode ==
759 P2P_PS_NONE || noa_index != p2pinfo->noa_index) {
760 RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD,
761 "update NOA ie.\n");
762 p2pinfo->noa_index = noa_index;
763 p2pinfo->opp_ps = (ie[4] >> 7);
764 p2pinfo->ctwindow = ie[4] & 0x7F;
765 p2pinfo->noa_num = noa_num;
766 index = 5;
767 for (i = 0; i < noa_num; i++) {
768 p2pinfo->noa_count_type[i] =
769 *(u8 *)(ie + index);
770 index += 1;
771 p2pinfo->noa_duration[i] =
> 772 le32_to_cpu(*(__le32 *)ie + index);
773 index += 4;
774 p2pinfo->noa_interval[i] =
775 le32_to_cpu(*(__le32 *)ie + index);
776 index += 4;
777 p2pinfo->noa_start_time[i] =
778 le32_to_cpu(*(__le32 *)ie + index);
779 index += 4;
780 }
781
782 if (p2pinfo->opp_ps == 1) {
783 p2pinfo->p2p_ps_mode = P2P_PS_CTWINDOW;
784 /* Driver should wait LPS entering
785 * CTWindow
786 */
787 if (rtlpriv->psc.fw_current_inpsmode)
788 rtl_p2p_ps_cmd(hw,
789 P2P_PS_ENABLE);
790 } else if (p2pinfo->noa_num > 0) {
791 p2pinfo->p2p_ps_mode = P2P_PS_NOA;
792 rtl_p2p_ps_cmd(hw, P2P_PS_ENABLE);
793 } else if (p2pinfo->p2p_ps_mode > P2P_PS_NONE) {
794 rtl_p2p_ps_cmd(hw, P2P_PS_DISABLE);
795 }
796 }
797 break;
798 }
799 ie += 3 + noa_len;
800 }
801
802 if (find_p2p_ie == true) {
803 if ((p2pinfo->p2p_ps_mode > P2P_PS_NONE) &&
804 (find_p2p_ps_ie == false))
805 rtl_p2p_ps_cmd(hw, P2P_PS_DISABLE);
806 }
807 }
808

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/[email protected] Intel Corporation