diff mbox series

[v2,16/17] staging: wfx: fix endianness of the field 'channel_number'

Message ID 20200512150414.267198-17-Jerome.Pouiller@silabs.com
State Superseded
Headers show
Series [v2,01/17] staging: wfx: fix use of cpu_to_le32 instead of le32_to_cpu | expand

Commit Message

Jérôme Pouiller May 12, 2020, 3:04 p.m. UTC
From: Jérôme Pouiller <jerome.pouiller@silabs.com>

The field 'channel_number' from the structs hif_ind_rx and hif_req_start
is a __le32. Sparse complains this field is not always correctly
accessed:

    drivers/staging/wfx/data_rx.c:95:55: warning: incorrect type in argument 1 (different base types)
    drivers/staging/wfx/data_rx.c:95:55:    expected int chan
    drivers/staging/wfx/data_rx.c:95:55:    got restricted __le16 const [usertype] channel_number

However, the value of channel_number cannot be greater than 14 (this
device only support 2.4Ghz band). So, we only have to access to the
least significant byte. It is finally easier to declare it as an array
of bytes and only access to the first one.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
---
 drivers/staging/wfx/hif_api_cmd.h | 15 +++++++++------
 drivers/staging/wfx/hif_tx.c      |  4 ++--
 2 files changed, 11 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/drivers/staging/wfx/hif_api_cmd.h b/drivers/staging/wfx/hif_api_cmd.h
index 8c48477e8797..21cde19cff75 100644
--- a/drivers/staging/wfx/hif_api_cmd.h
+++ b/drivers/staging/wfx/hif_api_cmd.h
@@ -321,7 +321,8 @@  struct hif_rx_flags {
 
 struct hif_ind_rx {
 	__le32 status;
-	__le16 channel_number;
+	u8     channel_number;
+	u8     reserved;
 	u8     rxed_rate;
 	u8     rcpi_rssi;
 	struct hif_rx_flags rx_flags;
@@ -356,7 +357,8 @@  struct hif_req_join {
 	u8     infrastructure_bss_mode:1;
 	u8     reserved1:7;
 	u8     band;
-	__le16 channel_number;
+	u8     channel_number;
+	u8     reserved;
 	u8     bssid[ETH_ALEN];
 	__le16 atim_window;
 	u8     short_preamble:1;
@@ -421,13 +423,14 @@  struct hif_ind_set_pm_mode_cmpl {
 struct hif_req_start {
 	u8     mode;
 	u8     band;
-	__le16 channel_number;
-	__le32 reserved1;
+	u8     channel_number;
+	u8     reserved1;
+	__le32 reserved2;
 	__le32 beacon_interval;
 	u8     dtim_period;
 	u8     short_preamble:1;
-	u8     reserved2:7;
-	u8     reserved3;
+	u8     reserved3:7;
+	u8     reserved4;
 	u8     ssid_length;
 	u8     ssid[HIF_API_SSID_SIZE];
 	__le32 basic_rate_set;
diff --git a/drivers/staging/wfx/hif_tx.c b/drivers/staging/wfx/hif_tx.c
index bb776ee6689c..7f459719e7b4 100644
--- a/drivers/staging/wfx/hif_tx.c
+++ b/drivers/staging/wfx/hif_tx.c
@@ -309,7 +309,7 @@  int hif_join(struct wfx_vif *wvif, const struct ieee80211_bss_conf *conf,
 		body->probe_for_join = 0;
 	else
 		body->probe_for_join = 1;
-	body->channel_number = cpu_to_le16(channel->hw_value);
+	body->channel_number = channel->hw_value;
 	body->beacon_interval = cpu_to_le32(conf->beacon_int);
 	body->basic_rate_set =
 		cpu_to_le32(wfx_rate_mask_to_hw(wvif->wdev, conf->basic_rates));
@@ -435,7 +435,7 @@  int hif_start(struct wfx_vif *wvif, const struct ieee80211_bss_conf *conf,
 	WARN_ON(!conf->beacon_int);
 	body->dtim_period = conf->dtim_period;
 	body->short_preamble = conf->use_short_preamble;
-	body->channel_number = cpu_to_le16(channel->hw_value);
+	body->channel_number = channel->hw_value;
 	body->beacon_interval = cpu_to_le32(conf->beacon_int);
 	body->basic_rate_set =
 		cpu_to_le32(wfx_rate_mask_to_hw(wvif->wdev, conf->basic_rates));