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 12/17] staging: wfx: fix endianness of the struct hif_ind_startup
Date: Mon, 11 May 2020 17:49:25 +0200	[thread overview]
Message-ID: <20200511154930.190212-13-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_ind_startup is received from the hardware. So it is
declared as little endian. However, it is also stored in the main driver
structure and used on different places in the driver. Sparse complains
about that:

    drivers/staging/wfx/data_tx.c:388:43: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/bh.c:199:9: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/bh.c:221:62: warning: restricted __le16 degrades to integer

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

On reception of this struct, 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/hif_api_general.h | 11 +++++++----
 drivers/staging/wfx/hif_rx.c          |  8 ++++----
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/wfx/hif_api_general.h b/drivers/staging/wfx/hif_api_general.h
index f0135d27120c..995752b9f168 100644
--- a/drivers/staging/wfx/hif_api_general.h
+++ b/drivers/staging/wfx/hif_api_general.h
@@ -136,12 +136,15 @@ struct hif_otp_phy_info {
 } __packed;
 
 struct hif_ind_startup {
+	// As the others, this struct is interpreted as little endian by the
+	// device. However, this struct is also used by the driver. We prefer to
+	// declare it in native order and doing byte swap on reception.
 	__le32 status;
-	__le16 hardware_id;
+	u16    hardware_id;
 	u8     opn[14];
 	u8     uid[8];
-	__le16 num_inp_ch_bufs;
-	__le16 size_inp_ch_buf;
+	u16    num_inp_ch_bufs;
+	u16    size_inp_ch_buf;
 	u8     num_links_ap;
 	u8     num_interfaces;
 	u8     mac_addr[2][ETH_ALEN];
@@ -155,7 +158,7 @@ struct hif_ind_startup {
 	u8     disabled_channel_list[2];
 	struct hif_otp_regul_sel_mode_info regul_sel_mode_info;
 	struct hif_otp_phy_info otp_phy_info;
-	__le32 supported_rate_mask;
+	u32    supported_rate_mask;
 	u8     firmware_label[128];
 } __packed;
 
diff --git a/drivers/staging/wfx/hif_rx.c b/drivers/staging/wfx/hif_rx.c
index fca9df620ad9..9b4f0c4ba745 100644
--- a/drivers/staging/wfx/hif_rx.c
+++ b/drivers/staging/wfx/hif_rx.c
@@ -100,10 +100,10 @@ static int hif_startup_indication(struct wfx_dev *wdev,
 		return -EINVAL;
 	}
 	memcpy(&wdev->hw_caps, body, sizeof(struct hif_ind_startup));
-	le32_to_cpus(&wdev->hw_caps.status);
-	le16_to_cpus(&wdev->hw_caps.hardware_id);
-	le16_to_cpus(&wdev->hw_caps.num_inp_ch_bufs);
-	le16_to_cpus(&wdev->hw_caps.size_inp_ch_buf);
+	le16_to_cpus((__le16 *)&wdev->hw_caps.hardware_id);
+	le16_to_cpus((__le16 *)&wdev->hw_caps.num_inp_ch_bufs);
+	le16_to_cpus((__le16 *)&wdev->hw_caps.size_inp_ch_buf);
+	le32_to_cpus((__le32 *)&wdev->hw_caps.supported_rate_mask);
 
 	complete(&wdev->firmware_ready);
 	return 0;
-- 
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 12/17] staging: wfx: fix endianness of the struct hif_ind_startup
Date: Mon, 11 May 2020 17:49:25 +0200	[thread overview]
Message-ID: <20200511154930.190212-13-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_ind_startup is received from the hardware. So it is
declared as little endian. However, it is also stored in the main driver
structure and used on different places in the driver. Sparse complains
about that:

    drivers/staging/wfx/data_tx.c:388:43: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/bh.c:199:9: warning: restricted __le16 degrades to integer
    drivers/staging/wfx/bh.c:221:62: warning: restricted __le16 degrades to integer

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

On reception of this struct, 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/hif_api_general.h | 11 +++++++----
 drivers/staging/wfx/hif_rx.c          |  8 ++++----
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/wfx/hif_api_general.h b/drivers/staging/wfx/hif_api_general.h
index f0135d27120c..995752b9f168 100644
--- a/drivers/staging/wfx/hif_api_general.h
+++ b/drivers/staging/wfx/hif_api_general.h
@@ -136,12 +136,15 @@ struct hif_otp_phy_info {
 } __packed;
 
 struct hif_ind_startup {
+	// As the others, this struct is interpreted as little endian by the
+	// device. However, this struct is also used by the driver. We prefer to
+	// declare it in native order and doing byte swap on reception.
 	__le32 status;
-	__le16 hardware_id;
+	u16    hardware_id;
 	u8     opn[14];
 	u8     uid[8];
-	__le16 num_inp_ch_bufs;
-	__le16 size_inp_ch_buf;
+	u16    num_inp_ch_bufs;
+	u16    size_inp_ch_buf;
 	u8     num_links_ap;
 	u8     num_interfaces;
 	u8     mac_addr[2][ETH_ALEN];
@@ -155,7 +158,7 @@ struct hif_ind_startup {
 	u8     disabled_channel_list[2];
 	struct hif_otp_regul_sel_mode_info regul_sel_mode_info;
 	struct hif_otp_phy_info otp_phy_info;
-	__le32 supported_rate_mask;
+	u32    supported_rate_mask;
 	u8     firmware_label[128];
 } __packed;
 
diff --git a/drivers/staging/wfx/hif_rx.c b/drivers/staging/wfx/hif_rx.c
index fca9df620ad9..9b4f0c4ba745 100644
--- a/drivers/staging/wfx/hif_rx.c
+++ b/drivers/staging/wfx/hif_rx.c
@@ -100,10 +100,10 @@ static int hif_startup_indication(struct wfx_dev *wdev,
 		return -EINVAL;
 	}
 	memcpy(&wdev->hw_caps, body, sizeof(struct hif_ind_startup));
-	le32_to_cpus(&wdev->hw_caps.status);
-	le16_to_cpus(&wdev->hw_caps.hardware_id);
-	le16_to_cpus(&wdev->hw_caps.num_inp_ch_bufs);
-	le16_to_cpus(&wdev->hw_caps.size_inp_ch_buf);
+	le16_to_cpus((__le16 *)&wdev->hw_caps.hardware_id);
+	le16_to_cpus((__le16 *)&wdev->hw_caps.num_inp_ch_bufs);
+	le16_to_cpus((__le16 *)&wdev->hw_caps.size_inp_ch_buf);
+	le32_to_cpus((__le32 *)&wdev->hw_caps.supported_rate_mask);
 
 	complete(&wdev->firmware_ready);
 	return 0;
-- 
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:51 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 ` Jerome Pouiller [this message]
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 ` [PATCH 13/17] staging: wfx: fix endianness of the field 'len' Jerome Pouiller
2020-05-11 15:49   ` 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-13-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.