All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] Fix Sparse endian warnings in r8712u
@ 2017-02-11  3:30 Larry Finger
  2017-02-11  3:30 ` [PATCH 1/7] staging: rtl8712: Fix some Sparse endian messages Larry Finger
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Larry Finger @ 2017-02-11  3:30 UTC (permalink / raw)
  To: gregkh; +Cc: devel, netdev, Larry Finger

Now that endian checking is an automatic part of Sparse, it is advisable
to fix these warnings under controlled conditions, which include testing
on big-endian hardware. This set of patches fix all the issues.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>


Larry Finger (7):
  staging: r8712u: Fix some Sparse endian messages
  staging: r8712u: Fix endian settings for structs describing network
    packets
  staging: r8712u: Fix macros used to read/write the TX/RX descriptors
  staging: r8712u: Fix Sparse warning in rtl871x_xmit.c
  staging: r8712u: Fix Sparse endian warning in rtl871x_recv.c
  staging: r8712u: Fix Sparse warnings in rtl871x_ioctl_linux.c
  staging: r8712u: Fix Sparse warnings in rtl871x_mlme.c

 drivers/staging/rtl8712/ieee80211.h           |  84 ++++++++++----------
 drivers/staging/rtl8712/rtl8712_xmit.c        |   6 +-
 drivers/staging/rtl8712/rtl871x_ioctl_linux.c |   4 +-
 drivers/staging/rtl8712/rtl871x_mlme.c        |   9 +--
 drivers/staging/rtl8712/rtl871x_recv.c        |   5 +-
 drivers/staging/rtl8712/rtl871x_xmit.c        |   7 +-
 drivers/staging/rtl8712/wifi.h                | 109 ++++++++++++--------------
 7 files changed, 110 insertions(+), 114 deletions(-)

-- 
2.10.2

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/7] staging: rtl8712: Fix some Sparse endian messages
  2017-02-11  3:30 [PATCH 0/7] Fix Sparse endian warnings in r8712u Larry Finger
@ 2017-02-11  3:30 ` Larry Finger
  2017-02-13 11:32   ` David Laight
  2017-02-11  3:30 ` [PATCH 2/7] staging: rtl8712u: Fix endian settings for structs describing network packets Larry Finger
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Larry Finger @ 2017-02-11  3:30 UTC (permalink / raw)
  To: gregkh; +Cc: devel, netdev, Larry Finger

Sparse reports the following:

  CHECK   drivers/staging/rtl8712/rtl8712_xmit.c
drivers/staging/rtl8712/rtl8712_xmit.c:564:42: warning: cast from restricted __le32
drivers/staging/rtl8712/rtl8712_xmit.c:569:42: warning: cast from restricted __le32
drivers/staging/rtl8712/rtl8712_xmit.c:571:42: warning: cast from restricted __le32

Each of these cases is transferring a quantity that is little-endian. There
is no need for conversion.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---
 drivers/staging/rtl8712/rtl8712_xmit.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl8712_xmit.c b/drivers/staging/rtl8712/rtl8712_xmit.c
index 4231a0a..7fe6265 100644
--- a/drivers/staging/rtl8712/rtl8712_xmit.c
+++ b/drivers/staging/rtl8712/rtl8712_xmit.c
@@ -561,14 +561,14 @@ static void update_txdesc(struct xmit_frame *pxmitframe, uint *pmem, int sz)
 
 			ptxdesc_mp = &txdesc_mp;
 			/* offset 8 */
-			ptxdesc->txdw2 = cpu_to_le32(ptxdesc_mp->txdw2);
+			ptxdesc->txdw2 = ptxdesc_mp->txdw2;
 			if (bmcst)
 				ptxdesc->txdw2 |= cpu_to_le32(BMC);
 			ptxdesc->txdw2 |= cpu_to_le32(BK);
 			/* offset 16 */
-			ptxdesc->txdw4 = cpu_to_le32(ptxdesc_mp->txdw4);
+			ptxdesc->txdw4 = ptxdesc_mp->txdw4;
 			/* offset 20 */
-			ptxdesc->txdw5 = cpu_to_le32(ptxdesc_mp->txdw5);
+			ptxdesc->txdw5 = ptxdesc_mp->txdw5;
 			pattrib->pctrl = 0;/* reset to zero; */
 		}
 	} else if (pxmitframe->frame_tag == MGNT_FRAMETAG) {
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/7] staging: rtl8712u: Fix endian settings for structs describing network packets
  2017-02-11  3:30 [PATCH 0/7] Fix Sparse endian warnings in r8712u Larry Finger
  2017-02-11  3:30 ` [PATCH 1/7] staging: rtl8712: Fix some Sparse endian messages Larry Finger
@ 2017-02-11  3:30 ` Larry Finger
  2017-02-11  3:30 ` [PATCH 3/7] staging: r8712u: Fix macros used to read/write the TX/RX descriptors Larry Finger
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Larry Finger @ 2017-02-11  3:30 UTC (permalink / raw)
  To: gregkh; +Cc: devel, netdev, Larry Finger

The headers describing a number of network packets do not have the
correct endian settings for several types of data.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---
 drivers/staging/rtl8712/ieee80211.h | 84 ++++++++++++++++++-------------------
 1 file changed, 42 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/rtl8712/ieee80211.h b/drivers/staging/rtl8712/ieee80211.h
index 67ab580..68fd65e 100644
--- a/drivers/staging/rtl8712/ieee80211.h
+++ b/drivers/staging/rtl8712/ieee80211.h
@@ -138,51 +138,51 @@ struct ieee_ibss_seq {
 };
 
 struct ieee80211_hdr {
-	u16 frame_ctl;
-	u16 duration_id;
+	__le16 frame_ctl;
+	__le16 duration_id;
 	u8 addr1[ETH_ALEN];
 	u8 addr2[ETH_ALEN];
 	u8 addr3[ETH_ALEN];
-	u16 seq_ctl;
+	__le16 seq_ctl;
 	u8 addr4[ETH_ALEN];
-} __packed;
+}  __packed __aligned(2);
 
 struct ieee80211_hdr_3addr {
-	u16 frame_ctl;
-	u16 duration_id;
+	__le16 frame_ctl;
+	__le16 duration_id;
 	u8 addr1[ETH_ALEN];
 	u8 addr2[ETH_ALEN];
 	u8 addr3[ETH_ALEN];
-	u16 seq_ctl;
-} __packed;
+	__le16 seq_ctl;
+}  __packed __aligned(2);
 
 struct	ieee80211_hdr_qos {
-	u16 frame_ctl;
-	u16 duration_id;
+	__le16 frame_ctl;
+	__le16 duration_id;
 	u8 addr1[ETH_ALEN];
 	u8 addr2[ETH_ALEN];
 	u8 addr3[ETH_ALEN];
-	u16 seq_ctl;
+	__le16 seq_ctl;
 	u8 addr4[ETH_ALEN];
-	u16	qc;
-}  __packed;
+	__le16	qc;
+}   __packed __aligned(2);
 
 struct  ieee80211_hdr_3addr_qos {
-	u16 frame_ctl;
-	u16 duration_id;
+	__le16 frame_ctl;
+	__le16 duration_id;
 	u8  addr1[ETH_ALEN];
 	u8  addr2[ETH_ALEN];
 	u8  addr3[ETH_ALEN];
-	u16 seq_ctl;
-	u16 qc;
+	__le16 seq_ctl;
+	__le16 qc;
 }  __packed;
 
 struct eapol {
 	u8 snap[6];
-	u16 ethertype;
+	__be16 ethertype;
 	u8 version;
 	u8 type;
-	u16 length;
+	__le16 length;
 } __packed;
 
 enum eap_type {
@@ -514,13 +514,13 @@ struct ieee80211_security {
  */
 
 struct ieee80211_header_data {
-	u16 frame_ctl;
-	u16 duration_id;
+	__le16 frame_ctl;
+	__le16 duration_id;
 	u8 addr1[6];
 	u8 addr2[6];
 	u8 addr3[6];
-	u16 seq_ctrl;
-};
+	__le16 seq_ctrl;
+} __packed __aligned(2);
 
 #define BEACON_PROBE_SSID_ID_POSITION 12
 
@@ -552,18 +552,18 @@ struct ieee80211_info_element {
 /*
  * These are the data types that can make up management packets
  *
-	u16 auth_algorithm;
-	u16 auth_sequence;
-	u16 beacon_interval;
-	u16 capability;
+	__le16 auth_algorithm;
+	__le16 auth_sequence;
+	__le16 beacon_interval;
+	__le16 capability;
 	u8 current_ap[ETH_ALEN];
-	u16 listen_interval;
+	__le16 listen_interval;
 	struct {
 		u16 association_id:14, reserved:2;
 	} __packed;
-	u32 time_stamp[2];
-	u16 reason;
-	u16 status;
+	__le32 time_stamp[2];
+	__le16 reason;
+	__le16 status;
 */
 
 #define IEEE80211_DEFAULT_TX_ESSID "Penguin"
@@ -571,16 +571,16 @@ struct ieee80211_info_element {
 
 struct ieee80211_authentication {
 	struct ieee80211_header_data header;
-	u16 algorithm;
-	u16 transaction;
-	u16 status;
+	__le16 algorithm;
+	__le16 transaction;
+	__le16 status;
 } __packed;
 
 struct ieee80211_probe_response {
 	struct ieee80211_header_data header;
-	u32 time_stamp[2];
-	u16 beacon_interval;
-	u16 capability;
+	__le32 time_stamp[2];
+	__le16 beacon_interval;
+	__le16 capability;
 	struct ieee80211_info_element info_element;
 } __packed;
 
@@ -590,16 +590,16 @@ struct ieee80211_probe_request {
 
 struct ieee80211_assoc_request_frame {
 	struct ieee80211_hdr_3addr header;
-	u16 capability;
-	u16 listen_interval;
+	__le16 capability;
+	__le16 listen_interval;
 	struct ieee80211_info_element_hdr info_element;
 } __packed;
 
 struct ieee80211_assoc_response_frame {
 	struct ieee80211_hdr_3addr header;
-	u16 capability;
-	u16 status;
-	u16 aid;
+	__le16 capability;
+	__le16 status;
+	__le16 aid;
 } __packed;
 
 struct ieee80211_txb {
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/7] staging: r8712u: Fix macros used to read/write the TX/RX descriptors
  2017-02-11  3:30 [PATCH 0/7] Fix Sparse endian warnings in r8712u Larry Finger
  2017-02-11  3:30 ` [PATCH 1/7] staging: rtl8712: Fix some Sparse endian messages Larry Finger
  2017-02-11  3:30 ` [PATCH 2/7] staging: rtl8712u: Fix endian settings for structs describing network packets Larry Finger
@ 2017-02-11  3:30 ` Larry Finger
  2017-02-11  3:30 ` [PATCH 4/7] staging: r8712u: Fix Sparse warning in rtl871x_xmit.c Larry Finger
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Larry Finger @ 2017-02-11  3:30 UTC (permalink / raw)
  To: gregkh; +Cc: devel, netdev, Larry Finger

Although the driver works on big-endian hardware, Sparse generates a lot
of warnings. Many of these are the result of incorrect coding of these
macros.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---
 drivers/staging/rtl8712/wifi.h | 109 ++++++++++++++++++++---------------------
 1 file changed, 52 insertions(+), 57 deletions(-)

diff --git a/drivers/staging/rtl8712/wifi.h b/drivers/staging/rtl8712/wifi.h
index 7ebf247..74dfc9b 100644
--- a/drivers/staging/rtl8712/wifi.h
+++ b/drivers/staging/rtl8712/wifi.h
@@ -151,92 +151,88 @@ enum WIFI_REG_DOMAIN {
 #define _ORDER_		BIT(15)
 
 #define SetToDs(pbuf) ({ \
-	*(unsigned short *)(pbuf) |= cpu_to_le16(_TO_DS_); \
+	*(__le16 *)(pbuf) |= cpu_to_le16(_TO_DS_); \
 })
 
-#define GetToDs(pbuf)	(((*(unsigned short *)(pbuf)) & \
-			le16_to_cpu(_TO_DS_)) != 0)
+#define GetToDs(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_TO_DS_)) != 0)
 
 #define ClearToDs(pbuf)	({ \
-	*(unsigned short *)(pbuf) &= (~cpu_to_le16(_TO_DS_)); \
+	*(__le16 *)(pbuf) &= (~cpu_to_le16(_TO_DS_)); \
 })
 
 #define SetFrDs(pbuf) ({ \
-	*(unsigned short *)(pbuf) |= cpu_to_le16(_FROM_DS_); \
+	*(__le16 *)(pbuf) |= cpu_to_le16(_FROM_DS_); \
 })
 
-#define GetFrDs(pbuf)	(((*(unsigned short *)(pbuf)) & \
-			le16_to_cpu(_FROM_DS_)) != 0)
+#define GetFrDs(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_FROM_DS_)) != 0)
 
 #define ClearFrDs(pbuf)	({ \
-	*(unsigned short *)(pbuf) &= (~cpu_to_le16(_FROM_DS_)); \
+	*(__le16 *)(pbuf) &= (~cpu_to_le16(_FROM_DS_)); \
 })
 
 #define get_tofr_ds(pframe)	((GetToDs(pframe) << 1) | GetFrDs(pframe))
 
 
 #define SetMFrag(pbuf) ({ \
-	*(unsigned short *)(pbuf) |= cpu_to_le16(_MORE_FRAG_); \
+	*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_FRAG_); \
 })
 
-#define GetMFrag(pbuf)	(((*(unsigned short *)(pbuf)) & \
-			le16_to_cpu(_MORE_FRAG_)) != 0)
+#define GetMFrag(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_MORE_FRAG_)) != 0)
 
 #define ClearMFrag(pbuf) ({ \
-	*(unsigned short *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_)); \
+	*(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_)); \
 })
 
 #define SetRetry(pbuf) ({ \
-	*(unsigned short *)(pbuf) |= cpu_to_le16(_RETRY_); \
+	*(__le16 *)(pbuf) |= cpu_to_le16(_RETRY_); \
 })
 
-#define GetRetry(pbuf)	(((*(unsigned short *)(pbuf)) & \
-			le16_to_cpu(_RETRY_)) != 0)
+#define GetRetry(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_RETRY_)) != 0)
 
 #define ClearRetry(pbuf) ({ \
-	*(unsigned short *)(pbuf) &= (~cpu_to_le16(_RETRY_)); \
+	*(__le16 *)(pbuf) &= (~cpu_to_le16(_RETRY_)); \
 })
 
 #define SetPwrMgt(pbuf) ({ \
-	*(unsigned short *)(pbuf) |= cpu_to_le16(_PWRMGT_); \
+	*(__le16 *)(pbuf) |= cpu_to_le16(_PWRMGT_); \
 })
 
-#define GetPwrMgt(pbuf)	(((*(unsigned short *)(pbuf)) & \
-			le16_to_cpu(_PWRMGT_)) != 0)
+#define GetPwrMgt(pbuf)	(((*(__le16 *)(pbuf)) & \
+			cpu_to_le16(_PWRMGT_)) != 0)
 
 #define ClearPwrMgt(pbuf) ({ \
-	*(unsigned short *)(pbuf) &= (~cpu_to_le16(_PWRMGT_)); \
+	*(__le16 *)(pbuf) &= (~cpu_to_le16(_PWRMGT_)); \
 })
 
 #define SetMData(pbuf) ({ \
-	*(unsigned short *)(pbuf) |= cpu_to_le16(_MORE_DATA_); \
+	*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_DATA_); \
 })
 
-#define GetMData(pbuf)	(((*(unsigned short *)(pbuf)) & \
-			le16_to_cpu(_MORE_DATA_)) != 0)
+#define GetMData(pbuf)	(((*(__le16 *)(pbuf)) & \
+			cpu_to_le16(_MORE_DATA_)) != 0)
 
 #define ClearMData(pbuf) ({ \
-	*(unsigned short *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_)); \
+	*(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_)); \
 })
 
 #define SetPrivacy(pbuf) ({ \
-	*(unsigned short *)(pbuf) |= cpu_to_le16(_PRIVACY_); \
+	*(__le16 *)(pbuf) |= cpu_to_le16(_PRIVACY_); \
 })
 
-#define GetPrivacy(pbuf)	(((*(unsigned short *)(pbuf)) & \
-				le16_to_cpu(_PRIVACY_)) != 0)
+#define GetPrivacy(pbuf)	(((*(__le16 *)(pbuf)) & \
+				cpu_to_le16(_PRIVACY_)) != 0)
 
-#define GetOrder(pbuf)	(((*(unsigned short *)(pbuf)) & \
-			le16_to_cpu(_ORDER_)) != 0)
+#define GetOrder(pbuf)	(((*(__le16 *)(pbuf)) & \
+			cpu_to_le16(_ORDER_)) != 0)
 
 #define GetFrameType(pbuf)	(le16_to_cpu(*(__le16 *)(pbuf)) & \
 				(BIT(3) | BIT(2)))
 
 #define SetFrameType(pbuf, type)	\
 	do {	\
-		*(unsigned short *)(pbuf) &= cpu_to_le16(~(BIT(3) | \
+		*(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(3) | \
 		BIT(2))); \
-		*(unsigned short *)(pbuf) |= cpu_to_le16(type); \
+		*(__le16 *)(pbuf) |= cpu_to_le16(type); \
 	} while (0)
 
 #define GetFrameSubType(pbuf)	(le16_to_cpu(*(__le16 *)(pbuf)) & \
@@ -245,44 +241,43 @@ enum WIFI_REG_DOMAIN {
 
 #define SetFrameSubType(pbuf, type) \
 	do {    \
-		*(unsigned short *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) | \
+		*(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) | \
 		BIT(5) | BIT(4) | BIT(3) | BIT(2))); \
-		*(unsigned short *)(pbuf) |= cpu_to_le16(type); \
+		*(__le16 *)(pbuf) |= cpu_to_le16(type); \
 	} while (0)
 
-#define GetSequence(pbuf)	(cpu_to_le16(*(unsigned short *)\
+#define GetSequence(pbuf)	(le16_to_cpu(*(__le16 *)\
 				((addr_t)(pbuf) + 22)) >> 4)
 
-#define GetFragNum(pbuf)	(cpu_to_le16(*(unsigned short *)((addr_t)\
+#define GetFragNum(pbuf)	(le16_to_cpu(*(__le16 *)((addr_t)\
 				(pbuf) + 22)) & 0x0f)
 
 #define SetSeqNum(pbuf, num) ({ \
-	*(unsigned short *)((addr_t)(pbuf) + 22) = \
-	((*(unsigned short *)((addr_t)(pbuf) + 22)) & \
-	le16_to_cpu((unsigned short)0x000f)) | \
-	le16_to_cpu((unsigned short)(0xfff0 & (num << 4))); \
+	*(__le16 *)((addr_t)(pbuf) + 22) = \
+	cpu_to_le16((le16_to_cpu(*(__le16 *)((addr_t)(pbuf) + 22)) & \
+	0x000f) | (0xfff0 & (num << 4))); \
 })
 
 #define SetDuration(pbuf, dur) ({ \
-	*(unsigned short *)((addr_t)(pbuf) + 2) |= \
+	*(__le16 *)((addr_t)(pbuf) + 2) |= \
 	cpu_to_le16(0xffff & (dur)); \
 })
 
 #define SetPriority(pbuf, tid) ({ \
-	*(unsigned short *)(pbuf) |= cpu_to_le16(tid & 0xf); \
+	*(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf); \
 })
 
-#define GetPriority(pbuf)	((le16_to_cpu(*(unsigned short *)(pbuf))) & 0xf)
+#define GetPriority(pbuf)	((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
 
 #define SetAckpolicy(pbuf, ack) ({ \
-	*(unsigned short *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \
+	*(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \
 })
 
-#define GetAckpolicy(pbuf) (((le16_to_cpu(*(unsigned short *)pbuf)) >> 5) & 0x3)
+#define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
 
-#define GetAMsdu(pbuf) (((le16_to_cpu(*(unsigned short *)pbuf)) >> 7) & 0x1)
+#define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
 
-#define GetAid(pbuf)	(cpu_to_le16(*(unsigned short *)((addr_t)(pbuf) + 2)) \
+#define GetAid(pbuf)	(cpu_to_le16(*(__le16 *)((addr_t)(pbuf) + 2)) \
 			& 0x3fff)
 
 #define GetAddr1Ptr(pbuf)	((unsigned char *)((addr_t)(pbuf) + 4))
@@ -476,10 +471,10 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
 
 #define SetOrderBit(pbuf) ({ \
-	*(unsigned short *)(pbuf) |= cpu_to_le16(_ORDER_); \
+	*(__le16 *)(pbuf) |= cpu_to_le16(_ORDER_); \
 })
 
-#define GetOrderBit(pbuf)	(((*(unsigned short *)(pbuf)) & \
+#define GetOrderBit(pbuf)	(((*(__le16 *)(pbuf)) & \
 				le16_to_cpu(_ORDER_)) != 0)
 
 
@@ -490,12 +485,12 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
  * described in 802.11n draft section 7.2.1.7.1
  */
 struct ieee80211_bar {
-	unsigned short frame_control;
-	unsigned short duration;
+	__le16 frame_control;
+	__le16 duration;
 	unsigned char ra[6];
 	unsigned char ta[6];
-	unsigned short control;
-	unsigned short start_seq_num;
+	__le16 control;
+	__le16 start_seq_num;
 } __packed;
 
 /* 802.11 BAR control masks */
@@ -511,11 +506,11 @@ struct ieee80211_bar {
  */
 
 struct ieee80211_ht_cap {
-	unsigned short	cap_info;
+	__le16	cap_info;
 	unsigned char	ampdu_params_info;
 	unsigned char	supp_mcs_set[16];
-	unsigned short	extended_ht_cap_info;
-	unsigned int		tx_BF_cap_info;
+	__le16	extended_ht_cap_info;
+	__le32	tx_BF_cap_info;
 	unsigned char	       antenna_selection_info;
 } __packed;
 
@@ -528,8 +523,8 @@ struct ieee80211_ht_cap {
 struct ieee80211_ht_addt_info {
 	unsigned char	control_chan;
 	unsigned char		ht_param;
-	unsigned short	operation_mode;
-	unsigned short	stbc_param;
+	__le16	operation_mode;
+	__le16	stbc_param;
 	unsigned char		basic_set[16];
 } __packed;
 
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/7] staging: r8712u: Fix Sparse warning in rtl871x_xmit.c
  2017-02-11  3:30 [PATCH 0/7] Fix Sparse endian warnings in r8712u Larry Finger
                   ` (2 preceding siblings ...)
  2017-02-11  3:30 ` [PATCH 3/7] staging: r8712u: Fix macros used to read/write the TX/RX descriptors Larry Finger
@ 2017-02-11  3:30 ` Larry Finger
  2017-02-11  3:30 ` [PATCH 5/7] staging: r8712u: Fix Sparse endian warning in rtl871x_recv.c Larry Finger
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Larry Finger @ 2017-02-11  3:30 UTC (permalink / raw)
  To: gregkh; +Cc: devel, netdev, Larry Finger

Sparse reports the following:
  CHECK   drivers/staging/rtl8712/rtl871x_xmit.c
drivers/staging/rtl8712/rtl871x_xmit.c:350:44: warning: restricted __le32 degrades to integer
drivers/staging/rtl8712/rtl871x_xmit.c:491:23: warning: incorrect type in initializer (different base types)
drivers/staging/rtl8712/rtl871x_xmit.c:491:23:    expected unsigned short [usertype] *fctrl
drivers/staging/rtl8712/rtl871x_xmit.c:491:23:    got restricted __le16 *<noident>
drivers/staging/rtl8712/rtl871x_xmit.c:580:36: warning: incorrect type in assignment (different base types)
drivers/staging/rtl8712/rtl871x_xmit.c:580:36:    expected unsigned short [unsigned] [short] [usertype] <noident>
drivers/staging/rtl8712/rtl871x_xmit.c:580:36:    got restricted __be16 [usertype] <noident>

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---
 drivers/staging/rtl8712/rtl871x_xmit.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl871x_xmit.c b/drivers/staging/rtl8712/rtl871x_xmit.c
index 4ab82ba..de88819 100644
--- a/drivers/staging/rtl8712/rtl871x_xmit.c
+++ b/drivers/staging/rtl8712/rtl871x_xmit.c
@@ -347,7 +347,8 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
 	 * some settings above.
 	 */
 	if (check_fwstate(pmlmepriv, WIFI_MP_STATE))
-		pattrib->priority = (txdesc.txdw1 >> QSEL_SHT) & 0x1f;
+		pattrib->priority =
+		    (le32_to_cpu(txdesc.txdw1) >> QSEL_SHT) & 0x1f;
 	return _SUCCESS;
 }
 
@@ -488,7 +489,7 @@ static sint make_wlanhdr(struct _adapter *padapter, u8 *hdr,
 	struct ieee80211_hdr *pwlanhdr = (struct ieee80211_hdr *)hdr;
 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 	struct qos_priv *pqospriv = &pmlmepriv->qospriv;
-	u16 *fctrl = &pwlanhdr->frame_ctl;
+	__le16 *fctrl = &pwlanhdr->frame_ctl;
 
 	memset(hdr, 0, WLANHDR_OFFSET);
 	SetFrameSubType(fctrl, pattrib->subtype);
@@ -577,7 +578,7 @@ static sint r8712_put_snap(u8 *data, u16 h_proto)
 	snap->oui[0] = oui[0];
 	snap->oui[1] = oui[1];
 	snap->oui[2] = oui[2];
-	*(u16 *)(data + SNAP_SIZE) = htons(h_proto);
+	*(__be16 *)(data + SNAP_SIZE) = htons(h_proto);
 	return SNAP_SIZE + sizeof(u16);
 }
 
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/7] staging: r8712u: Fix Sparse endian warning in rtl871x_recv.c
  2017-02-11  3:30 [PATCH 0/7] Fix Sparse endian warnings in r8712u Larry Finger
                   ` (3 preceding siblings ...)
  2017-02-11  3:30 ` [PATCH 4/7] staging: r8712u: Fix Sparse warning in rtl871x_xmit.c Larry Finger
@ 2017-02-11  3:30 ` Larry Finger
  2017-02-13 11:29   ` David Laight
  2017-02-11  3:30 ` [PATCH 6/7] staging: r8712u: Fix Sparse warnings in rtl871x_ioctl_linux.c Larry Finger
  2017-02-11  3:30 ` [PATCH 7/7] staging: r8712u: Fix Sparse warnings in rtl871x_mlme.c Larry Finger
  6 siblings, 1 reply; 12+ messages in thread
From: Larry Finger @ 2017-02-11  3:30 UTC (permalink / raw)
  To: gregkh; +Cc: devel, netdev, Larry Finger

Sparse reports the following:
  CHECK   drivers/staging/rtl8712/rtl871x_recv.c
drivers/staging/rtl8712/rtl871x_recv.c:657:21: warning: incorrect type in assignment (different base types)
drivers/staging/rtl8712/rtl871x_recv.c:657:21:    expected unsigned short [unsigned] [assigned] [usertype] len
drivers/staging/rtl8712/rtl871x_recv.c:657:21:    got restricted __be16 [usertype] <noident>

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---
 drivers/staging/rtl8712/rtl871x_recv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl871x_recv.c b/drivers/staging/rtl8712/rtl871x_recv.c
index 147b75b..2ef31a4 100644
--- a/drivers/staging/rtl8712/rtl871x_recv.c
+++ b/drivers/staging/rtl8712/rtl871x_recv.c
@@ -654,8 +654,9 @@ sint r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe)
 	memcpy(ptr, pattrib->dst, ETH_ALEN);
 	memcpy(ptr + ETH_ALEN, pattrib->src, ETH_ALEN);
 	if (!bsnaphdr) {
-		len = htons(len);
-		memcpy(ptr + 12, &len, 2);
+		__be16 be_tmp = htons(len);
+
+		memcpy(ptr + 12, &be_tmp, 2);
 	}
 	return _SUCCESS;
 }
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/7] staging: r8712u: Fix Sparse warnings in rtl871x_ioctl_linux.c
  2017-02-11  3:30 [PATCH 0/7] Fix Sparse endian warnings in r8712u Larry Finger
                   ` (4 preceding siblings ...)
  2017-02-11  3:30 ` [PATCH 5/7] staging: r8712u: Fix Sparse endian warning in rtl871x_recv.c Larry Finger
@ 2017-02-11  3:30 ` Larry Finger
  2017-02-13 11:27   ` David Laight
  2017-02-11  3:30 ` [PATCH 7/7] staging: r8712u: Fix Sparse warnings in rtl871x_mlme.c Larry Finger
  6 siblings, 1 reply; 12+ messages in thread
From: Larry Finger @ 2017-02-11  3:30 UTC (permalink / raw)
  To: gregkh; +Cc: devel, netdev, Larry Finger

Sparse reports the following:
  CHECK   drivers/staging/rtl8712/rtl871x_ioctl_linux.c
drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1422:46: warning: restricted __le16 degrades to integer
drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1424:46: warning: restricted __le16 degrades to integer

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---
 drivers/staging/rtl8712/rtl871x_ioctl_linux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index 0dc18d6..f4167f1 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -1419,9 +1419,9 @@ static int r8711_wx_get_rate(struct net_device *dev,
 			ht_cap = true;
 			pht_capie = (struct ieee80211_ht_cap *)(p + 2);
 			memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2);
-			bw_40MHz = (pht_capie->cap_info &
+			bw_40MHz = (le16_to_cpu(pht_capie->cap_info) &
 				    IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0;
-			short_GI = (pht_capie->cap_info &
+			short_GI = (le16_to_cpu(pht_capie->cap_info) &
 				    (IEEE80211_HT_CAP_SGI_20 |
 				    IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
 		}
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 7/7] staging: r8712u: Fix Sparse warnings in rtl871x_mlme.c
  2017-02-11  3:30 [PATCH 0/7] Fix Sparse endian warnings in r8712u Larry Finger
                   ` (5 preceding siblings ...)
  2017-02-11  3:30 ` [PATCH 6/7] staging: r8712u: Fix Sparse warnings in rtl871x_ioctl_linux.c Larry Finger
@ 2017-02-11  3:30 ` Larry Finger
  6 siblings, 0 replies; 12+ messages in thread
From: Larry Finger @ 2017-02-11  3:30 UTC (permalink / raw)
  To: gregkh; +Cc: devel, netdev, Larry Finger

Sparse reports the following:
  CHECK   drivers/staging/rtl8712/rtl871x_mlme.c
drivers/staging/rtl8712/rtl871x_mlme.c:1653:46: warning: incorrect type in assignment (different base types)
drivers/staging/rtl8712/rtl871x_mlme.c:1653:46:    expected unsigned int [unsigned] [usertype] DSConfig
drivers/staging/rtl8712/rtl871x_mlme.c:1653:46:    got restricted __le32 [usertype] <noident>
drivers/staging/rtl8712/rtl871x_mlme.c:1656:56: warning: incorrect type in assignment (different base types)
drivers/staging/rtl8712/rtl871x_mlme.c:1656:56:    expected unsigned int [unsigned] [usertype] ATIMWindow
drivers/staging/rtl8712/rtl871x_mlme.c:1656:56:    got restricted __le32 [usertype] <noident>
drivers/staging/rtl8712/rtl871x_mlme.c:1712:35: warning: incorrect type in assignment (different base types)
drivers/staging/rtl8712/rtl871x_mlme.c:1712:35:    expected restricted __le16 [addressable] [usertype] cap_info
drivers/staging/rtl8712/rtl871x_mlme.c:1712:35:    got int

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---
 drivers/staging/rtl8712/rtl871x_mlme.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c
index fd8d96d..bf1ac22 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.c
+++ b/drivers/staging/rtl8712/rtl871x_mlme.c
@@ -1650,10 +1650,9 @@ void r8712_update_registrypriv_dev_network(struct _adapter *adapter)
 		/* TODO */
 		break;
 	}
-	pdev_network->Configuration.DSConfig = cpu_to_le32(
-					       pregistrypriv->channel);
+	pdev_network->Configuration.DSConfig = pregistrypriv->channel;
 	if (cur_network->network.InfrastructureMode == Ndis802_11IBSS)
-		pdev_network->Configuration.ATIMWindow = cpu_to_le32(3);
+		pdev_network->Configuration.ATIMWindow = 3;
 	pdev_network->InfrastructureMode = cur_network->network.InfrastructureMode;
 	/* 1. Supported rates
 	 * 2. IE
@@ -1709,12 +1708,12 @@ unsigned int r8712_restructure_ht_ie(struct _adapter *padapter, u8 *in_ie,
 		}
 		out_len = *pout_len;
 		memset(&ht_capie, 0, sizeof(struct ieee80211_ht_cap));
-		ht_capie.cap_info = IEEE80211_HT_CAP_SUP_WIDTH |
+		ht_capie.cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH |
 				    IEEE80211_HT_CAP_SGI_20 |
 				    IEEE80211_HT_CAP_SGI_40 |
 				    IEEE80211_HT_CAP_TX_STBC |
 				    IEEE80211_HT_CAP_MAX_AMSDU |
-				    IEEE80211_HT_CAP_DSSSCCK40;
+				    IEEE80211_HT_CAP_DSSSCCK40);
 		ht_capie.ampdu_params_info = (IEEE80211_HT_CAP_AMPDU_FACTOR &
 				0x03) | (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00);
 		r8712_set_ie(out_ie + out_len, _HT_CAPABILITY_IE_,
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* RE: [PATCH 6/7] staging: r8712u: Fix Sparse warnings in rtl871x_ioctl_linux.c
  2017-02-11  3:30 ` [PATCH 6/7] staging: r8712u: Fix Sparse warnings in rtl871x_ioctl_linux.c Larry Finger
@ 2017-02-13 11:27   ` David Laight
  2017-02-13 15:54     ` Larry Finger
  0 siblings, 1 reply; 12+ messages in thread
From: David Laight @ 2017-02-13 11:27 UTC (permalink / raw)
  To: 'Larry Finger', gregkh; +Cc: netdev, devel

From: Larry Finger
> Sent: 11 February 2017 03:30
> Sparse reports the following:
>   CHECK   drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1422:46: warning: restricted __le16 degrades to integer
> drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1424:46: warning: restricted __le16 degrades to integer
> 
> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
> ---
>  drivers/staging/rtl8712/rtl871x_ioctl_linux.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> index 0dc18d6..f4167f1 100644
> --- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> +++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> @@ -1419,9 +1419,9 @@ static int r8711_wx_get_rate(struct net_device *dev,
>  			ht_cap = true;
>  			pht_capie = (struct ieee80211_ht_cap *)(p + 2);
>  			memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2);
> -			bw_40MHz = (pht_capie->cap_info &
> +			bw_40MHz = (le16_to_cpu(pht_capie->cap_info) &
>  				    IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0;
> -			short_GI = (pht_capie->cap_info &
> +			short_GI = (le16_to_cpu(pht_capie->cap_info) &
>  				    (IEEE80211_HT_CAP_SGI_20 |
>  				    IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;

You've added a byteswap on le systems - so the title is wrong.
You need to sort out whether the byteswap is needed or not.

Also it is best to byteswap the constant.

	David

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH 5/7] staging: r8712u: Fix Sparse endian warning in rtl871x_recv.c
  2017-02-11  3:30 ` [PATCH 5/7] staging: r8712u: Fix Sparse endian warning in rtl871x_recv.c Larry Finger
@ 2017-02-13 11:29   ` David Laight
  0 siblings, 0 replies; 12+ messages in thread
From: David Laight @ 2017-02-13 11:29 UTC (permalink / raw)
  To: 'Larry Finger', gregkh; +Cc: netdev, devel

From: Larry Finger
> Sent: 11 February 2017 03:30
> Sparse reports the following:
>   CHECK   drivers/staging/rtl8712/rtl871x_recv.c
> drivers/staging/rtl8712/rtl871x_recv.c:657:21: warning: incorrect type in assignment (different base
> types)
> drivers/staging/rtl8712/rtl871x_recv.c:657:21:    expected unsigned short [unsigned] [assigned]
> [usertype] len
> drivers/staging/rtl8712/rtl871x_recv.c:657:21:    got restricted __be16 [usertype] <noident>
> 
> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
> ---
>  drivers/staging/rtl8712/rtl871x_recv.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8712/rtl871x_recv.c b/drivers/staging/rtl8712/rtl871x_recv.c
> index 147b75b..2ef31a4 100644
> --- a/drivers/staging/rtl8712/rtl871x_recv.c
> +++ b/drivers/staging/rtl8712/rtl871x_recv.c
> @@ -654,8 +654,9 @@ sint r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe)
>  	memcpy(ptr, pattrib->dst, ETH_ALEN);
>  	memcpy(ptr + ETH_ALEN, pattrib->src, ETH_ALEN);
>  	if (!bsnaphdr) {
> -		len = htons(len);
> -		memcpy(ptr + 12, &len, 2);
> +		__be16 be_tmp = htons(len);
> +
> +		memcpy(ptr + 12, &be_tmp, 2);

Just do:
	ptr[12] = len << 8;
	ptr[13] = len;

	David

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH 1/7] staging: rtl8712: Fix some Sparse endian messages
  2017-02-11  3:30 ` [PATCH 1/7] staging: rtl8712: Fix some Sparse endian messages Larry Finger
@ 2017-02-13 11:32   ` David Laight
  0 siblings, 0 replies; 12+ messages in thread
From: David Laight @ 2017-02-13 11:32 UTC (permalink / raw)
  To: 'Larry Finger', gregkh; +Cc: netdev, devel

From: Larry Finger
> Sent: 11 February 2017 03:30
> Sparse reports the following:
> 
>   CHECK   drivers/staging/rtl8712/rtl8712_xmit.c
> drivers/staging/rtl8712/rtl8712_xmit.c:564:42: warning: cast from restricted __le32
...

I think you ought to do separate patches for the changes that are only annotations
and those that actually change the code.

The latter need a proper patch description.

	David.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 6/7] staging: r8712u: Fix Sparse warnings in rtl871x_ioctl_linux.c
  2017-02-13 11:27   ` David Laight
@ 2017-02-13 15:54     ` Larry Finger
  0 siblings, 0 replies; 12+ messages in thread
From: Larry Finger @ 2017-02-13 15:54 UTC (permalink / raw)
  To: David Laight, gregkh; +Cc: devel, netdev

On 02/13/2017 05:27 AM, David Laight wrote:
> From: Larry Finger
>> Sent: 11 February 2017 03:30
>> Sparse reports the following:
>>   CHECK   drivers/staging/rtl8712/rtl871x_ioctl_linux.c
>> drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1422:46: warning: restricted __le16 degrades to integer
>> drivers/staging/rtl8712/rtl871x_ioctl_linux.c:1424:46: warning: restricted __le16 degrades to integer
>>
>> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
>> ---
>>  drivers/staging/rtl8712/rtl871x_ioctl_linux.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
>> b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
>> index 0dc18d6..f4167f1 100644
>> --- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
>> +++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
>> @@ -1419,9 +1419,9 @@ static int r8711_wx_get_rate(struct net_device *dev,
>>  			ht_cap = true;
>>  			pht_capie = (struct ieee80211_ht_cap *)(p + 2);
>>  			memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2);
>> -			bw_40MHz = (pht_capie->cap_info &
>> +			bw_40MHz = (le16_to_cpu(pht_capie->cap_info) &
>>  				    IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0;
>> -			short_GI = (pht_capie->cap_info &
>> +			short_GI = (le16_to_cpu(pht_capie->cap_info) &
>>  				    (IEEE80211_HT_CAP_SGI_20 |
>>  				    IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
>
> You've added a byteswap on le systems - so the title is wrong.
> You need to sort out whether the byteswap is needed or not.
>
> Also it is best to byteswap the constant.

Yes, I could byteswap the constant rather than the variable, but I prefer to 
have both be in cpu order. That way there will be no confusion when that 
quantity is used later. In this case, both results are boolean and it would not 
make a difference.

I do not understand the comment about the title being wrong. All multi-byte 
quantities in struct ieee80211_ht_cap are little endian. For the code to work on 
BE hardware, a byteswap is necessary. On LE hardware, le16_to_cpu() is defined 
as ((__force __u16)(__le16)(x)), which does not result in a byteswap.

Larry

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-02-13 15:54 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-11  3:30 [PATCH 0/7] Fix Sparse endian warnings in r8712u Larry Finger
2017-02-11  3:30 ` [PATCH 1/7] staging: rtl8712: Fix some Sparse endian messages Larry Finger
2017-02-13 11:32   ` David Laight
2017-02-11  3:30 ` [PATCH 2/7] staging: rtl8712u: Fix endian settings for structs describing network packets Larry Finger
2017-02-11  3:30 ` [PATCH 3/7] staging: r8712u: Fix macros used to read/write the TX/RX descriptors Larry Finger
2017-02-11  3:30 ` [PATCH 4/7] staging: r8712u: Fix Sparse warning in rtl871x_xmit.c Larry Finger
2017-02-11  3:30 ` [PATCH 5/7] staging: r8712u: Fix Sparse endian warning in rtl871x_recv.c Larry Finger
2017-02-13 11:29   ` David Laight
2017-02-11  3:30 ` [PATCH 6/7] staging: r8712u: Fix Sparse warnings in rtl871x_ioctl_linux.c Larry Finger
2017-02-13 11:27   ` David Laight
2017-02-13 15:54     ` Larry Finger
2017-02-11  3:30 ` [PATCH 7/7] staging: r8712u: Fix Sparse warnings in rtl871x_mlme.c Larry Finger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.