Skip to contentSkip to conversation

staging/ks7010: Fix type assignment for struct hostif_hdr

PATCH In review Cezary Gapinski 2 participants 5 messages Apr 29, 2017 – May 1, 2017 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging/ks7010: Fix type assignment for struct hostif_hdr

Sparse spits out a warnings about __le16 and unsigned short assignment. Change the type of size and event members of struct hostif_hdr to __le16 and correct conversion to the proper cpu type.

---
 drivers/staging/ks7010/ks7010_sdio.c | 10 ++++++----
 drivers/staging/ks7010/ks_hostif.h   |  4 ++--
 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/staging/ks7010/ks7010_sdio.c +6 -4
index ec11799..e3a134d 100644
@@ -269,7 +269,8 @@ static int write_to_device(struct ks_wlan_private *priv, unsigned char *buffer,
 	hdr = (struct hostif_hdr *)buffer;
 
 	DPRINTK(4, "size=%d\n", hdr->size);
-	if (hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event) {
+	if (le16_to_cpu(hdr->event) < HIF_DATA_REQ ||
+	    le16_to_cpu(hdr->event) > HIF_REQ_MAX) {
 		DPRINTK(1, "unknown event=%04X\n", hdr->event);
 		return 0;
 	}
@@ -327,13 +328,14 @@ int ks_wlan_hw_tx(struct ks_wlan_private *priv, void *p, unsigned long size,
 
 	hdr = (struct hostif_hdr *)p;
 
-	if (hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event) {
+	if (le16_to_cpu(hdr->event) < HIF_DATA_REQ ||
+	    le16_to_cpu(hdr->event) > HIF_REQ_MAX) {
 		DPRINTK(1, "unknown event=%04X\n", hdr->event);
 		return 0;
 	}
 
 	/* add event to hostt buffer */
-	priv->hostt.buff[priv->hostt.qtail] = hdr->event;
+	priv->hostt.buff[priv->hostt.qtail] = le16_to_cpu(hdr->event);
 	priv->hostt.qtail = (priv->hostt.qtail + 1) % SME_EVENT_BUFF_SIZE;
 
 	DPRINTK(4, "event=%04X\n", hdr->event);
@@ -403,7 +405,7 @@ static void ks_wlan_hw_rx(struct ks_wlan_private *priv, uint16_t size)
 
 	hdr = (struct hostif_hdr *)&rx_buffer->data[0];
 	rx_buffer->size = le16_to_cpu(hdr->size) + sizeof(hdr->size);
-	event = hdr->event;
+	event = le16_to_cpu(hdr->event);
 	inc_rxqtail(priv);
 
 	ret = ks7010_sdio_writeb(priv, READ_STATUS, REG_STATUS_IDLE);
drivers/staging/ks7010/ks_hostif.h +2 -2
index d773432..7e4d1aa 100644
@@ -62,8 +62,8 @@
  */
 
 struct hostif_hdr {
-	u16 size;
-	u16 event;
+	__le16 size;
+	__le16 event;
 } __packed;
 
 struct hostif_data_request_t {
Signature · 1 line
2.7.4
#1 lore raw
Quoted 3 lines · Cezary Gapinski

Sparse spits out a warnings about __le16 and unsigned short assignment. Change the type of size and event members of struct hostif_hdr to __le16 and correct conversion to the proper cpu type.

I believe that this patch is correct. I am of the opinion though that endian changes to this driver require prior testing on hardware. There are some anomalies that I have not figured out yet (for example the eap header appears to be in network byte order).

I may, however, very well be wrong. It may be perfectly safe to merge this as is.

Good luck,
Tobin.

Quoted 64 lines
---
 drivers/staging/ks7010/ks7010_sdio.c | 10 ++++++----
 drivers/staging/ks7010/ks_hostif.h   |  4 ++--
 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/staging/ks7010/ks7010_sdio.c +6 -4
index ec11799..e3a134d 100644
@@ -269,7 +269,8 @@ static int write_to_device(struct ks_wlan_private *priv, unsigned char *buffer,
 	hdr = (struct hostif_hdr *)buffer;
 
 	DPRINTK(4, "size=%d\n", hdr->size);
-	if (hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event) {
+	if (le16_to_cpu(hdr->event) < HIF_DATA_REQ ||
+	    le16_to_cpu(hdr->event) > HIF_REQ_MAX) {
 		DPRINTK(1, "unknown event=%04X\n", hdr->event);
 		return 0;
 	}
@@ -327,13 +328,14 @@ int ks_wlan_hw_tx(struct ks_wlan_private *priv, void *p, unsigned long size,
 
 	hdr = (struct hostif_hdr *)p;
 
-	if (hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event) {
+	if (le16_to_cpu(hdr->event) < HIF_DATA_REQ ||
+	    le16_to_cpu(hdr->event) > HIF_REQ_MAX) {
 		DPRINTK(1, "unknown event=%04X\n", hdr->event);
 		return 0;
 	}
 
 	/* add event to hostt buffer */
-	priv->hostt.buff[priv->hostt.qtail] = hdr->event;
+	priv->hostt.buff[priv->hostt.qtail] = le16_to_cpu(hdr->event);
 	priv->hostt.qtail = (priv->hostt.qtail + 1) % SME_EVENT_BUFF_SIZE;
 
 	DPRINTK(4, "event=%04X\n", hdr->event);
@@ -403,7 +405,7 @@ static void ks_wlan_hw_rx(struct ks_wlan_private *priv, uint16_t size)
 
 	hdr = (struct hostif_hdr *)&rx_buffer->data[0];
 	rx_buffer->size = le16_to_cpu(hdr->size) + sizeof(hdr->size);
-	event = hdr->event;
+	event = le16_to_cpu(hdr->event);
 	inc_rxqtail(priv);
 
 	ret = ks7010_sdio_writeb(priv, READ_STATUS, REG_STATUS_IDLE);
drivers/staging/ks7010/ks_hostif.h +2 -2
index d773432..7e4d1aa 100644
@@ -62,8 +62,8 @@
  */
 
 struct hostif_hdr {
-	u16 size;
-	u16 event;
+	__le16 size;
+	__le16 event;
 } __packed;
 
 struct hostif_data_request_t {
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#2 lore raw
In reply to Cezary Gapinski
Quoted 5 lines · Cezary Gapinski

Sparse spits out a warnings about __le16 and unsigned short assignment. Change the type of size and event members of struct hostif_hdr to __le16 and correct conversion to the proper cpu type.

After discussion on kernelnewbies mailing list and thinking about this for a couple of days I am now of the opinion that this patch is merge-able. I am probably not fully qualified to say so but no one else appears to be super active on this driver. If I am wrong, I'll be here to fix it up :)

Good work Cezsary, apologies for the wish-washy replies. I'm learning also ;)

Good luck,
Tobin.

Quoted 63 lines
---
 drivers/staging/ks7010/ks7010_sdio.c | 10 ++++++----
 drivers/staging/ks7010/ks_hostif.h   |  4 ++--
 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/staging/ks7010/ks7010_sdio.c +6 -4
index ec11799..e3a134d 100644
@@ -269,7 +269,8 @@ static int write_to_device(struct ks_wlan_private *priv, unsigned char *buffer,
 	hdr = (struct hostif_hdr *)buffer;
 
 	DPRINTK(4, "size=%d\n", hdr->size);
-	if (hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event) {
+	if (le16_to_cpu(hdr->event) < HIF_DATA_REQ ||
+	    le16_to_cpu(hdr->event) > HIF_REQ_MAX) {
 		DPRINTK(1, "unknown event=%04X\n", hdr->event);
 		return 0;
 	}
@@ -327,13 +328,14 @@ int ks_wlan_hw_tx(struct ks_wlan_private *priv, void *p, unsigned long size,
 
 	hdr = (struct hostif_hdr *)p;
 
-	if (hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event) {
+	if (le16_to_cpu(hdr->event) < HIF_DATA_REQ ||
+	    le16_to_cpu(hdr->event) > HIF_REQ_MAX) {
 		DPRINTK(1, "unknown event=%04X\n", hdr->event);
 		return 0;
 	}
 
 	/* add event to hostt buffer */
-	priv->hostt.buff[priv->hostt.qtail] = hdr->event;
+	priv->hostt.buff[priv->hostt.qtail] = le16_to_cpu(hdr->event);
 	priv->hostt.qtail = (priv->hostt.qtail + 1) % SME_EVENT_BUFF_SIZE;
 
 	DPRINTK(4, "event=%04X\n", hdr->event);
@@ -403,7 +405,7 @@ static void ks_wlan_hw_rx(struct ks_wlan_private *priv, uint16_t size)
 
 	hdr = (struct hostif_hdr *)&rx_buffer->data[0];
 	rx_buffer->size = le16_to_cpu(hdr->size) + sizeof(hdr->size);
-	event = hdr->event;
+	event = le16_to_cpu(hdr->event);
 	inc_rxqtail(priv);
 
 	ret = ks7010_sdio_writeb(priv, READ_STATUS, REG_STATUS_IDLE);
drivers/staging/ks7010/ks_hostif.h +2 -2
index d773432..7e4d1aa 100644
@@ -62,8 +62,8 @@
  */
 
 struct hostif_hdr {
-	u16 size;
-	u16 event;
+	__le16 size;
+	__le16 event;
 } __packed;
 
 struct hostif_data_request_t {
Signature · 1 line
2.7.4
author
#3 lore raw
Quoted 13 lines · On Mon, 1 May 2017 19:59:44 +1000 "Tobin C. Harding" <[email protected]> wrote:
Quoted 5 lines · Cezary Gapinski

Sparse spits out a warnings about __le16 and unsigned short assignment. Change the type of size and event members of struct hostif_hdr to __le16 and correct conversion to the proper cpu type.

After discussion on kernelnewbies mailing list and thinking about this for a couple of days I am now of the opinion that this patch is merge-able. I am probably not fully qualified to say so but no one else appears to be super active on this driver. If I am wrong, I'll be here to fix it up :)

Quoted 7 lines

Good work Cezsary, apologies for the wish-washy replies. I'm learning also ;)

Good luck,
Tobin.

Hi Tobin,

nice to know that you also thinking about this fixes. I think that is just a first step because I noticed much more warning with big/little-endian issues and perhaps no one else want to touch this. I'm also here to help if it is something will be incorrect ;)."

Sorry for my previous messages. Sometimes I forget about crtl+s will sending my e-mails, so if you received other messages just ignore it.

Quoted 66 lines
Quoted 66 lines
---
 drivers/staging/ks7010/ks7010_sdio.c | 10 ++++++----
 drivers/staging/ks7010/ks_hostif.h   |  4 ++--
 2 files changed, 8 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/ks7010/ks7010_sdio.c index ec11799..e3a134d 100644

drivers/staging/ks7010/ks7010_sdio.c +0 -0
@@ -269,7 +269,8 @@ static int write_to_device(struct

ks_wlan_private *priv, unsigned char *buffer, hdr = (struct hostif_hdr *)buffer;

drivers/staging/ks7010/ks7010_sdio.c +0 -1
 	DPRINTK(4, "size=%d\n", hdr->size);
-	if (hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event)

{

drivers/staging/ks7010/ks7010_sdio.c +5 -2
+	if (le16_to_cpu(hdr->event) < HIF_DATA_REQ ||
+	    le16_to_cpu(hdr->event) > HIF_REQ_MAX) {
 		DPRINTK(1, "unknown event=%04X\n", hdr->event);
 		return 0;
 	}
@@ -327,13 +328,14 @@ int ks_wlan_hw_tx(struct ks_wlan_private
 *priv, void *p, unsigned long size, 
 	hdr = (struct hostif_hdr *)p;
 
-	if (hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event)
 {
+	if (le16_to_cpu(hdr->event) < HIF_DATA_REQ ||
+	    le16_to_cpu(hdr->event) > HIF_REQ_MAX) {
 		DPRINTK(1, "unknown event=%04X\n", hdr->event);
 		return 0;
 	}
 
 	/* add event to hostt buffer */
-	priv->hostt.buff[priv->hostt.qtail] = hdr->event;
+	priv->hostt.buff[priv->hostt.qtail] =

le16_to_cpu(hdr->event); priv->hostt.qtail = (priv->hostt.qtail +
1) % SME_EVENT_BUFF_SIZE;

drivers/staging/ks7010/ks7010_sdio.c +1 -1
 	DPRINTK(4, "event=%04X\n", hdr->event);
@@ -403,7 +405,7 @@ static void ks_wlan_hw_rx(struct
 ks_wlan_private *priv, uint16_t size) 
 	hdr = (struct hostif_hdr *)&rx_buffer->data[0];
 	rx_buffer->size = le16_to_cpu(hdr->size) +
 sizeof(hdr->size);
-	event = hdr->event;
+	event = le16_to_cpu(hdr->event);
 	inc_rxqtail(priv);
 

ret = ks7010_sdio_writeb(priv, READ_STATUS,
REG_STATUS_IDLE); diff --git a/drivers/staging/ks7010/ks_hostif.h b/drivers/staging/ks7010/ks_hostif.h index d773432..7e4d1aa 100644

drivers/staging/ks7010/ks_hostif.h +2 -2
@@ -62,8 +62,8 @@
  */
 
 struct hostif_hdr {
-	u16 size;
-	u16 event;
+	__le16 size;
+	__le16 event;
 } __packed;
 
 struct hostif_data_request_t {
Signature · 1 line
2.7.4
#4 lore raw
Quoted 21 lines · gapalinux
Quoted 18 lines · On Mon, 1 May 2017 19:59:44 +1000 "Tobin C. Harding" <[email protected]> wrote:
Quoted 5 lines · Cezary Gapinski

Sparse spits out a warnings about __le16 and unsigned short assignment. Change the type of size and event members of struct hostif_hdr to __le16 and correct conversion to the proper cpu type.

After discussion on kernelnewbies mailing list and thinking about this for a couple of days I am now of the opinion that this patch is merge-able. I am probably not fully qualified to say so but no one else appears to be super active on this driver. If I am wrong, I'll be here to fix it up :)

Good work Cezsary, apologies for the wish-washy replies. I'm learning also ;)

Quoted 8 lines
Quoted 2 lines

Good luck,
Tobin.

Hi Tobin,

nice to know that you also thinking about this fixes. I think that is just a first step because I noticed much more warning with big/little-endian issues and perhaps no one else want to touch this.

I did up a patch set yesterday that fixes most of the Sparse warnings. It was simply a matter of changing all struct members in ks_hostif.h to be __leXX and adding a few cpu_to_leXX()/leXX_to_cpu() calls. Exactly as you did. I'm going to wait for your patch, and another that is in flight on ks7010, to be merged before I submit it. There will still be a few Sparse warnings that are a little more tricky, so there is still some fun to be had.

Quoted 1 line

I'm also here to help if it is something will be incorrect ;)."

Cool

Quoted 2 lines

Sorry for my previous messages. Sometimes I forget about crtl+s will sending my e-mails, so if you received other messages just ignore it.

Didn't receive any extra messages :)

Cheers,
Tobin.