All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jerome Pouiller <Jerome.Pouiller@silabs.com>
To: devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Kalle Valo" <kvalo@codeaurora.org>,
	"David S . Miller" <davem@davemloft.net>,
	"Jérôme Pouiller" <jerome.pouiller@silabs.com>
Subject: [PATCH 13/17] staging: wfx: fix endianness of the field 'len'
Date: Mon, 11 May 2020 17:49:26 +0200	[thread overview]
Message-ID: <20200511154930.190212-14-Jerome.Pouiller@silabs.com> (raw)
In-Reply-To: <20200511154930.190212-1-Jerome.Pouiller@silabs.com>

From: Jérôme Pouiller <jerome.pouiller@silabs.com>

The struct hif_msg is received from the hardware. So, it declared as
little endian. However, it is also accessed from many places in the
driver. Sparse complains about that:

    drivers/staging/wfx/bh.c:88:32: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/bh.c:88:32: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/bh.c:93:32: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/bh.c:93:32: warning: cast to restricted __le16
    drivers/staging/wfx/bh.c:93:32: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/bh.c:121:25: warning: incorrect type in argument 2 (different base types)
    drivers/staging/wfx/bh.c:121:25:    expected unsigned int len
    drivers/staging/wfx/bh.c:121:25:    got restricted __le16 [usertype] len
    drivers/staging/wfx/hif_rx.c:27:22: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/hif_rx.c:347:39: warning: incorrect type in argument 7 (different base types)
    drivers/staging/wfx/hif_rx.c:347:39:    expected unsigned int [usertype] len
    drivers/staging/wfx/hif_rx.c:347:39:    got restricted __le16 const [usertype] len
    drivers/staging/wfx/hif_rx.c:365:39: warning: incorrect type in argument 7 (different base types)
    drivers/staging/wfx/hif_rx.c:365:39:    expected unsigned int [usertype] len
    drivers/staging/wfx/hif_rx.c:365:39:    got restricted __le16 const [usertype] len
    drivers/staging/wfx/./traces.h:195:1: warning: incorrect type in assignment (different base types)
    drivers/staging/wfx/./traces.h:195:1:    expected int msg_len
    drivers/staging/wfx/./traces.h:195:1:    got restricted __le16 const [usertype] len
    drivers/staging/wfx/./traces.h:195:1: warning: incorrect type in assignment (different base types)
    drivers/staging/wfx/./traces.h:195:1:    expected int msg_len
    drivers/staging/wfx/./traces.h:195:1:    got restricted __le16 const [usertype] len
    drivers/staging/wfx/debug.c:319:20: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/secure_link.c:85:27: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/secure_link.c:85:27: warning: restricted __le16 degrades to integer

In order to make Sparse happy and to keep access from the driver easy,
this patch declare 'len' with native endianness.

On reception of hardware data, this patch takes care to do byte-swap and
keep Sparse happy.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
---
 drivers/staging/wfx/bh.c              | 7 ++++---
 drivers/staging/wfx/data_tx.c         | 2 +-
 drivers/staging/wfx/hif_api_general.h | 8 ++++++--
 drivers/staging/wfx/hif_tx.c          | 2 +-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/wfx/bh.c b/drivers/staging/wfx/bh.c
index 55724e4295c4..0355b1a1c4bb 100644
--- a/drivers/staging/wfx/bh.c
+++ b/drivers/staging/wfx/bh.c
@@ -74,6 +74,7 @@ static int rx_helper(struct wfx_dev *wdev, size_t read_len, int *is_cnf)
 	_trace_piggyback(piggyback, false);
 
 	hif = (struct hif_msg *)skb->data;
+	le16_to_cpus((__le16 *)&hif->len);
 	WARN(hif->encrypted & 0x1, "unsupported encryption type");
 	if (hif->encrypted == 0x2) {
 		if (wfx_sl_decode(wdev, (void *)hif)) {
@@ -84,12 +85,11 @@ static int rx_helper(struct wfx_dev *wdev, size_t read_len, int *is_cnf)
 			// piggyback is probably correct.
 			return piggyback;
 		}
-		le16_to_cpus(&hif->len);
+		le16_to_cpus((__le16 *)&hif->len);
 		computed_len = round_up(hif->len - sizeof(hif->len), 16)
 			       + sizeof(struct hif_sl_msg)
 			       + sizeof(struct hif_sl_tag);
 	} else {
-		le16_to_cpus(&hif->len);
 		computed_len = round_up(hif->len, 2);
 	}
 	if (computed_len != read_len) {
@@ -172,7 +172,7 @@ static void tx_helper(struct wfx_dev *wdev, struct hif_msg *hif)
 	int ret;
 	void *data;
 	bool is_encrypted = false;
-	size_t len = le16_to_cpu(hif->len);
+	size_t len = hif->len;
 
 	WARN(len < sizeof(*hif), "try to send corrupted data");
 
@@ -199,6 +199,7 @@ static void tx_helper(struct wfx_dev *wdev, struct hif_msg *hif)
 	WARN(len > wdev->hw_caps.size_inp_ch_buf,
 	     "%s: request exceed WFx capability: %zu > %d\n", __func__,
 	     len, wdev->hw_caps.size_inp_ch_buf);
+	cpu_to_le16s(((struct hif_msg *)data)->len);
 	len = wdev->hwbus_ops->align_size(wdev->hwbus_priv, len);
 	ret = wfx_data_write(wdev, data, len);
 	if (ret)
diff --git a/drivers/staging/wfx/data_tx.c b/drivers/staging/wfx/data_tx.c
index 014fa36c8f78..84656d1a6278 100644
--- a/drivers/staging/wfx/data_tx.c
+++ b/drivers/staging/wfx/data_tx.c
@@ -384,7 +384,7 @@ static int wfx_tx_inner(struct wfx_vif *wvif, struct ieee80211_sta *sta,
 	skb_push(skb, wmsg_len);
 	memset(skb->data, 0, wmsg_len);
 	hif_msg = (struct hif_msg *)skb->data;
-	hif_msg->len = cpu_to_le16(skb->len);
+	hif_msg->len = skb->len;
 	hif_msg->id = HIF_REQ_ID_TX;
 	hif_msg->interface = wvif->id;
 	if (skb->len > wvif->wdev->hw_caps.size_inp_ch_buf) {
diff --git a/drivers/staging/wfx/hif_api_general.h b/drivers/staging/wfx/hif_api_general.h
index 995752b9f168..a359ae76511a 100644
--- a/drivers/staging/wfx/hif_api_general.h
+++ b/drivers/staging/wfx/hif_api_general.h
@@ -23,7 +23,10 @@
 #define HIF_COUNTER_MAX           7
 
 struct hif_msg {
-	__le16 len;
+	// len is in fact little endian. However, it is widely used in the
+	// driver, so we declare it in native byte order and we reorder just
+	// before/after send/receive it (see bh.c).
+	u16    len;
 	u8     id;
 	u8     reserved:1;
 	u8     interface:2;
@@ -277,7 +280,8 @@ struct hif_sl_msg_hdr {
 
 struct hif_sl_msg {
 	struct hif_sl_msg_hdr hdr;
-	__le16 len;
+	// Same note than struct hif_msg
+	u16    len;
 	u8     payload[];
 } __packed;
 
diff --git a/drivers/staging/wfx/hif_tx.c b/drivers/staging/wfx/hif_tx.c
index 490a9de54faf..6c6618197b91 100644
--- a/drivers/staging/wfx/hif_tx.c
+++ b/drivers/staging/wfx/hif_tx.c
@@ -33,7 +33,7 @@ static void wfx_fill_header(struct hif_msg *hif, int if_id,
 	WARN(size > 0xFFF, "requested buffer is too large: %zu bytes", size);
 	WARN(if_id > 0x3, "invalid interface ID %d", if_id);
 
-	hif->len = cpu_to_le16(size + 4);
+	hif->len = size + 4;
 	hif->id = cmd;
 	hif->interface = if_id;
 }
-- 
2.26.2


WARNING: multiple messages have this Message-ID (diff)
From: Jerome Pouiller <Jerome.Pouiller@silabs.com>
To: devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"David S . Miller" <davem@davemloft.net>,
	Kalle Valo <kvalo@codeaurora.org>
Subject: [PATCH 13/17] staging: wfx: fix endianness of the field 'len'
Date: Mon, 11 May 2020 17:49:26 +0200	[thread overview]
Message-ID: <20200511154930.190212-14-Jerome.Pouiller@silabs.com> (raw)
In-Reply-To: <20200511154930.190212-1-Jerome.Pouiller@silabs.com>

From: Jérôme Pouiller <jerome.pouiller@silabs.com>

The struct hif_msg is received from the hardware. So, it declared as
little endian. However, it is also accessed from many places in the
driver. Sparse complains about that:

    drivers/staging/wfx/bh.c:88:32: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/bh.c:88:32: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/bh.c:93:32: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/bh.c:93:32: warning: cast to restricted __le16
    drivers/staging/wfx/bh.c:93:32: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/bh.c:121:25: warning: incorrect type in argument 2 (different base types)
    drivers/staging/wfx/bh.c:121:25:    expected unsigned int len
    drivers/staging/wfx/bh.c:121:25:    got restricted __le16 [usertype] len
    drivers/staging/wfx/hif_rx.c:27:22: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/hif_rx.c:347:39: warning: incorrect type in argument 7 (different base types)
    drivers/staging/wfx/hif_rx.c:347:39:    expected unsigned int [usertype] len
    drivers/staging/wfx/hif_rx.c:347:39:    got restricted __le16 const [usertype] len
    drivers/staging/wfx/hif_rx.c:365:39: warning: incorrect type in argument 7 (different base types)
    drivers/staging/wfx/hif_rx.c:365:39:    expected unsigned int [usertype] len
    drivers/staging/wfx/hif_rx.c:365:39:    got restricted __le16 const [usertype] len
    drivers/staging/wfx/./traces.h:195:1: warning: incorrect type in assignment (different base types)
    drivers/staging/wfx/./traces.h:195:1:    expected int msg_len
    drivers/staging/wfx/./traces.h:195:1:    got restricted __le16 const [usertype] len
    drivers/staging/wfx/./traces.h:195:1: warning: incorrect type in assignment (different base types)
    drivers/staging/wfx/./traces.h:195:1:    expected int msg_len
    drivers/staging/wfx/./traces.h:195:1:    got restricted __le16 const [usertype] len
    drivers/staging/wfx/debug.c:319:20: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/secure_link.c:85:27: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/secure_link.c:85:27: warning: restricted __le16 degrades to integer

In order to make Sparse happy and to keep access from the driver easy,
this patch declare 'len' with native endianness.

On reception of hardware data, this patch takes care to do byte-swap and
keep Sparse happy.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
---
 drivers/staging/wfx/bh.c              | 7 ++++---
 drivers/staging/wfx/data_tx.c         | 2 +-
 drivers/staging/wfx/hif_api_general.h | 8 ++++++--
 drivers/staging/wfx/hif_tx.c          | 2 +-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/wfx/bh.c b/drivers/staging/wfx/bh.c
index 55724e4295c4..0355b1a1c4bb 100644
--- a/drivers/staging/wfx/bh.c
+++ b/drivers/staging/wfx/bh.c
@@ -74,6 +74,7 @@ static int rx_helper(struct wfx_dev *wdev, size_t read_len, int *is_cnf)
 	_trace_piggyback(piggyback, false);
 
 	hif = (struct hif_msg *)skb->data;
+	le16_to_cpus((__le16 *)&hif->len);
 	WARN(hif->encrypted & 0x1, "unsupported encryption type");
 	if (hif->encrypted == 0x2) {
 		if (wfx_sl_decode(wdev, (void *)hif)) {
@@ -84,12 +85,11 @@ static int rx_helper(struct wfx_dev *wdev, size_t read_len, int *is_cnf)
 			// piggyback is probably correct.
 			return piggyback;
 		}
-		le16_to_cpus(&hif->len);
+		le16_to_cpus((__le16 *)&hif->len);
 		computed_len = round_up(hif->len - sizeof(hif->len), 16)
 			       + sizeof(struct hif_sl_msg)
 			       + sizeof(struct hif_sl_tag);
 	} else {
-		le16_to_cpus(&hif->len);
 		computed_len = round_up(hif->len, 2);
 	}
 	if (computed_len != read_len) {
@@ -172,7 +172,7 @@ static void tx_helper(struct wfx_dev *wdev, struct hif_msg *hif)
 	int ret;
 	void *data;
 	bool is_encrypted = false;
-	size_t len = le16_to_cpu(hif->len);
+	size_t len = hif->len;
 
 	WARN(len < sizeof(*hif), "try to send corrupted data");
 
@@ -199,6 +199,7 @@ static void tx_helper(struct wfx_dev *wdev, struct hif_msg *hif)
 	WARN(len > wdev->hw_caps.size_inp_ch_buf,
 	     "%s: request exceed WFx capability: %zu > %d\n", __func__,
 	     len, wdev->hw_caps.size_inp_ch_buf);
+	cpu_to_le16s(((struct hif_msg *)data)->len);
 	len = wdev->hwbus_ops->align_size(wdev->hwbus_priv, len);
 	ret = wfx_data_write(wdev, data, len);
 	if (ret)
diff --git a/drivers/staging/wfx/data_tx.c b/drivers/staging/wfx/data_tx.c
index 014fa36c8f78..84656d1a6278 100644
--- a/drivers/staging/wfx/data_tx.c
+++ b/drivers/staging/wfx/data_tx.c
@@ -384,7 +384,7 @@ static int wfx_tx_inner(struct wfx_vif *wvif, struct ieee80211_sta *sta,
 	skb_push(skb, wmsg_len);
 	memset(skb->data, 0, wmsg_len);
 	hif_msg = (struct hif_msg *)skb->data;
-	hif_msg->len = cpu_to_le16(skb->len);
+	hif_msg->len = skb->len;
 	hif_msg->id = HIF_REQ_ID_TX;
 	hif_msg->interface = wvif->id;
 	if (skb->len > wvif->wdev->hw_caps.size_inp_ch_buf) {
diff --git a/drivers/staging/wfx/hif_api_general.h b/drivers/staging/wfx/hif_api_general.h
index 995752b9f168..a359ae76511a 100644
--- a/drivers/staging/wfx/hif_api_general.h
+++ b/drivers/staging/wfx/hif_api_general.h
@@ -23,7 +23,10 @@
 #define HIF_COUNTER_MAX           7
 
 struct hif_msg {
-	__le16 len;
+	// len is in fact little endian. However, it is widely used in the
+	// driver, so we declare it in native byte order and we reorder just
+	// before/after send/receive it (see bh.c).
+	u16    len;
 	u8     id;
 	u8     reserved:1;
 	u8     interface:2;
@@ -277,7 +280,8 @@ struct hif_sl_msg_hdr {
 
 struct hif_sl_msg {
 	struct hif_sl_msg_hdr hdr;
-	__le16 len;
+	// Same note than struct hif_msg
+	u16    len;
 	u8     payload[];
 } __packed;
 
diff --git a/drivers/staging/wfx/hif_tx.c b/drivers/staging/wfx/hif_tx.c
index 490a9de54faf..6c6618197b91 100644
--- a/drivers/staging/wfx/hif_tx.c
+++ b/drivers/staging/wfx/hif_tx.c
@@ -33,7 +33,7 @@ static void wfx_fill_header(struct hif_msg *hif, int if_id,
 	WARN(size > 0xFFF, "requested buffer is too large: %zu bytes", size);
 	WARN(if_id > 0x3, "invalid interface ID %d", if_id);
 
-	hif->len = cpu_to_le16(size + 4);
+	hif->len = size + 4;
 	hif->id = cmd;
 	hif->interface = if_id;
 }
-- 
2.26.2

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  parent reply	other threads:[~2020-05-11 15:50 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-11 15:49 [PATCH 00/17] staging: wfx: fix support for big-endian hosts Jerome Pouiller
2020-05-11 15:49 ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 01/17] staging: wfx: fix use of cpu_to_le32 instead of le32_to_cpu Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 02/17] staging: wfx: take advantage of le32_to_cpup() Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 03/17] staging: wfx: fix cast operator Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 04/17] staging: wfx: fix wrong bytes order Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 05/17] staging: wfx: fix output of rx_stats on big endian hosts Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 06/17] staging: wfx: fix endianness of fields media_delay and tx_queue_delay Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 07/17] staging: wfx: fix endianness of hif_req_read_mib fields Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 08/17] staging: wfx: fix access to le32 attribute 'ps_mode_error' Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 09/17] staging: wfx: fix access to le32 attribute 'event_id' Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 10/17] staging: wfx: fix access to le32 attribute 'indication_type' Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 11/17] staging: wfx: declare the field 'packet_id' with native byte order Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 12/17] staging: wfx: fix endianness of the struct hif_ind_startup Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` Jerome Pouiller [this message]
2020-05-11 15:49   ` [PATCH 13/17] staging: wfx: fix endianness of the field 'len' Jerome Pouiller
2020-05-11 21:59   ` kbuild test robot
2020-05-11 21:59     ` kbuild test robot
2020-05-11 21:59     ` kbuild test robot
2020-05-12  7:43   ` Geert Uytterhoeven
2020-05-12  7:43     ` Geert Uytterhoeven
2020-05-12  9:25     ` Jérôme Pouiller
2020-05-12  9:25       ` Jérôme Pouiller
2020-05-11 15:49 ` [PATCH 14/17] staging: wfx: fix endianness of the field 'status' Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 15/17] staging: wfx: fix endianness of the field 'num_tx_confs' Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 16/17] staging: wfx: fix endianness of the field 'channel_number' Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller
2020-05-11 15:49 ` [PATCH 17/17] staging: wfx: update TODO Jerome Pouiller
2020-05-11 15:49   ` Jerome Pouiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200511154930.190212-14-Jerome.Pouiller@silabs.com \
    --to=jerome.pouiller@silabs.com \
    --cc=davem@davemloft.net \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.