[PATCH] staging: ks7010: clean up code

From: Ernestas Kulik
Date: Fri Mar 03 2017 - 16:07:42 EST


This fixes type warnings generated by sparse, replaces instances of
ntohs() with be16_to_cpu() and removes unused fields in structs.

Signed-off-by: Ernestas Kulik <ernestas.kulik@xxxxxxxxx>
---
drivers/staging/ks7010/ks7010_sdio.c | 12 ++--
drivers/staging/ks7010/ks_hostif.c | 30 +++++----
drivers/staging/ks7010/ks_hostif.h | 124 +++++++++++++++++------------------
drivers/staging/ks7010/ks_wlan.h | 2 +-
4 files changed, 85 insertions(+), 83 deletions(-)

diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c
index 6f9f746a3a61..8e644ff8eca8 100644
--- a/drivers/staging/ks7010/ks7010_sdio.c
+++ b/drivers/staging/ks7010/ks7010_sdio.c
@@ -297,7 +297,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 ||
+ HIF_REQ_MAX < le16_to_cpu(hdr->event)) {
DPRINTK(1, "unknown event=%04X\n", hdr->event);
return 0;
}
@@ -361,13 +362,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 ||
+ HIF_REQ_MAX < le16_to_cpu(hdr->event)) {
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);
@@ -406,7 +408,7 @@ static void ks_wlan_hw_rx(void *dev, uint16_t size)
struct rx_device_buffer *rx_buffer;
struct hostif_hdr *hdr;
unsigned char read_status;
- unsigned short event = 0;
+ __le16 event = 0;

DPRINTK(4, "\n");

@@ -459,7 +461,7 @@ static void ks_wlan_hw_rx(void *dev, uint16_t size)
DPRINTK(4, "READ_STATUS=%02X\n", read_status);

if (atomic_read(&priv->psstatus.confirm_wait)) {
- if (IS_HIF_CONF(event)) {
+ if (IS_HIF_CONF(le16_to_cpu(event))) {
DPRINTK(4, "IS_HIF_CONF true !!\n");
atomic_dec(&priv->psstatus.confirm_wait);
}
diff --git a/drivers/staging/ks7010/ks_hostif.c b/drivers/staging/ks7010/ks_hostif.c
index da7c42ef05f5..4ad4a0c72ca8 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -339,7 +339,7 @@ void hostif_data_indication(struct ks_wlan_private *priv)
get_WORD(priv); /* Reserve Area */

eth_hdr = (struct ether_hdr *)(priv->rxp);
- eth_proto = ntohs(eth_hdr->h_proto);
+ eth_proto = be16_to_cpu((__force __be16)eth_hdr->h_proto);
DPRINTK(3, "ether protocol = %04X\n", eth_proto);

/* source address check */
@@ -1200,7 +1200,7 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)

/* for WPA */
eth_hdr = (struct ether_hdr *)&pp->data[0];
- eth_proto = ntohs(eth_hdr->h_proto);
+ eth_proto = be16_to_cpu((__force __be16)eth_hdr->h_proto);

/* for MIC FAILURE REPORT check */
if (eth_proto == ETHER_PROTOCOL_TYPE_EAP
@@ -1208,7 +1208,7 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)
aa1x_hdr = (struct ieee802_1x_hdr *)(eth_hdr + 1);
if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY) {
eap_key = (struct wpa_eapol_key *)(aa1x_hdr + 1);
- keyinfo = ntohs(eap_key->key_info);
+ keyinfo = be16_to_cpu((__force __be16)eap_key->key_info);
}
}

@@ -1867,7 +1867,7 @@ void hostif_receive(struct ks_wlan_private *priv, unsigned char *p,
static
void hostif_sme_set_wep(struct ks_wlan_private *priv, int type)
{
- uint32_t val;
+ __le32 val;

switch (type) {
case SME_WEP_INDEX_REQUEST:
@@ -1916,13 +1916,13 @@ void hostif_sme_set_wep(struct ks_wlan_private *priv, int type)
}

struct wpa_suite_t {
- unsigned short size;
+ __le16 size;
unsigned char suite[4][CIPHER_ID_LEN];
} __packed;

struct rsn_mode_t {
- uint32_t rsn_mode;
- uint16_t rsn_capability;
+ __le32 rsn_mode;
+ __le16 rsn_capability;
} __packed;

static
@@ -1930,7 +1930,7 @@ void hostif_sme_set_rsn(struct ks_wlan_private *priv, int type)
{
struct wpa_suite_t wpa_suite;
struct rsn_mode_t rsn_mode;
- uint32_t val;
+ __le32 val;

memset(&wpa_suite, 0, sizeof(wpa_suite));

@@ -1982,7 +1982,8 @@ void hostif_sme_set_rsn(struct ks_wlan_private *priv, int type)

hostif_mib_set_request(priv, DOT11_RSN_CONFIG_UNICAST_CIPHER,
sizeof(wpa_suite.size) +
- CIPHER_ID_LEN * wpa_suite.size,
+ (CIPHER_ID_LEN *
+ le16_to_cpu(wpa_suite.size)),
MIB_VALUE_TYPE_OSTRING, &wpa_suite);
break;
case SME_RSN_MCAST_REQUEST:
@@ -2074,7 +2075,8 @@ void hostif_sme_set_rsn(struct ks_wlan_private *priv, int type)

hostif_mib_set_request(priv, DOT11_RSN_CONFIG_AUTH_SUITE,
sizeof(wpa_suite.size) +
- KEY_MGMT_ID_LEN * wpa_suite.size,
+ (KEY_MGMT_ID_LEN *
+ le16_to_cpu(wpa_suite.size)),
MIB_VALUE_TYPE_OSTRING, &wpa_suite);
break;
case SME_RSN_ENABLED_REQUEST:
@@ -2215,7 +2217,7 @@ void hostif_sme_multicast_set(struct ks_wlan_private *priv)
int mc_count;
struct netdev_hw_addr *ha;
char set_address[NIC_MAX_MCAST_LIST * ETH_ALEN];
- unsigned long filter_type;
+ __le32 filter_type;
int i = 0;

DPRINTK(3, "\n");
@@ -2324,7 +2326,7 @@ void hostif_sme_sleep_set(struct ks_wlan_private *priv)
static
void hostif_sme_set_key(struct ks_wlan_private *priv, int type)
{
- uint32_t val;
+ __le32 val;

switch (type) {
case SME_SET_FLAG:
@@ -2383,7 +2385,7 @@ static
void hostif_sme_set_pmksa(struct ks_wlan_private *priv)
{
struct pmk_cache_t {
- uint16_t size;
+ __le16 size;
struct {
uint8_t bssid[ETH_ALEN];
uint8_t pmkid[IW_PMKID_LEN];
@@ -2414,7 +2416,7 @@ void hostif_sme_set_pmksa(struct ks_wlan_private *priv)
static
void hostif_sme_execute(struct ks_wlan_private *priv, int event)
{
- uint32_t val;
+ __le32 val;

DPRINTK(3, "event=%d\n", event);
switch (event) {
diff --git a/drivers/staging/ks7010/ks_hostif.h b/drivers/staging/ks7010/ks_hostif.h
index 30c49b699d62..072d6e1d1ddf 100644
--- a/drivers/staging/ks7010/ks_hostif.h
+++ b/drivers/staging/ks7010/ks_hostif.h
@@ -62,13 +62,13 @@
*/

struct hostif_hdr {
- uint16_t size;
- uint16_t event;
+ __le16 size;
+ __le16 event;
} __packed;

struct hostif_data_request_t {
struct hostif_hdr header;
- uint16_t auth_type;
+ __le16 auth_type;
#define TYPE_DATA 0x0000
#define TYPE_AUTH 0x0001
uint16_t reserved;
@@ -143,12 +143,12 @@ struct channel_list_t {

struct hostif_mib_get_request_t {
struct hostif_hdr header;
- uint32_t mib_attribute;
+ __le32 mib_attribute;
} __packed;

struct hostif_mib_value_t {
- uint16_t size;
- uint16_t type;
+ __le16 size;
+ __le16 type;
#define MIB_VALUE_TYPE_NULL 0
#define MIB_VALUE_TYPE_INT 1
#define MIB_VALUE_TYPE_BOOL 2
@@ -170,7 +170,7 @@ struct hostif_mib_get_confirm_t {

struct hostif_mib_set_request_t {
struct hostif_hdr header;
- uint32_t mib_attribute;
+ __le32 mib_attribute;
struct hostif_mib_value_t mib_value;
} __packed;

@@ -182,13 +182,13 @@ struct hostif_mib_set_confirm_t {

struct hostif_power_mngmt_request_t {
struct hostif_hdr header;
- uint32_t mode;
+ __le32 mode;
#define POWER_ACTIVE 1
#define POWER_SAVE 2
- uint32_t wake_up;
+ __le32 wake_up;
#define SLEEP_FALSE 0
#define SLEEP_TRUE 1 /* not used */
- uint32_t receiveDTIMs;
+ __le32 receiveDTIMs;
#define DTIM_FALSE 0
#define DTIM_TRUE 1
} __packed;
@@ -213,7 +213,7 @@ struct hostif_power_mngmt_confirm_t {

struct hostif_start_request_t {
struct hostif_hdr header;
- uint16_t mode;
+ __le16 mode;
#define MODE_PSEUDO_ADHOC 0
#define MODE_INFRASTRUCTURE 1
#define MODE_AP 2 /* not used */
@@ -283,8 +283,7 @@ struct ap_info_t {
uint8_t sq; /* +07 */
uint8_t noise; /* +08 */
uint8_t pad0; /* +09 */
- uint16_t beacon_period; /* +10 */
- uint16_t capability; /* +12 */
+ __le16 capability; /* +10 */
#define BSS_CAP_ESS (1<<0)
#define BSS_CAP_IBSS (1<<1)
#define BSS_CAP_CF_POLABLE (1<<2)
@@ -295,13 +294,13 @@ struct ap_info_t {
#define BSS_CAP_CHANNEL_AGILITY (1<<7)
#define BSS_CAP_SHORT_SLOT_TIME (1<<10)
#define BSS_CAP_DSSS_OFDM (1<<13)
- uint8_t frame_type; /* +14 */
- uint8_t ch_info; /* +15 */
+ uint8_t frame_type; /* +12 */
+ uint8_t ch_info; /* +13 */
#define FRAME_TYPE_BEACON 0x80
#define FRAME_TYPE_PROBE_RESP 0x50
- uint16_t body_size; /* +16 */
- uint8_t body[1024]; /* +18 */
- /* +1032 */
+ uint16_t body_size; /* +14 */
+ uint8_t body[1024]; /* +16 */
+ /* +1030 */
} __packed;

struct link_ap_info_t {
@@ -310,24 +309,23 @@ struct link_ap_info_t {
uint8_t sq; /* +07 */
uint8_t noise; /* +08 */
uint8_t pad0; /* +09 */
- uint16_t beacon_period; /* +10 */
- uint16_t capability; /* +12 */
- struct rate_set8_t rate_set; /* +14 */
- struct FhParms_t fh_parameter; /* +24 */
- struct DsParms_t ds_parameter; /* +29 */
- struct CfParms_t cf_parameter; /* +30 */
- struct IbssParms_t ibss_parameter; /* +36 */
- struct ErpParams_t erp_parameter; /* +38 */
+ __le16 capability; /* +10 */
+ struct rate_set8_t rate_set; /* +12 */
+ struct FhParms_t fh_parameter; /* +22 */
+ struct DsParms_t ds_parameter; /* +27 */
+ struct CfParms_t cf_parameter; /* +28 */
+ struct IbssParms_t ibss_parameter; /* +34 */
+ struct ErpParams_t erp_parameter; /* +36 */
uint8_t pad1; /* +39 */
- struct rate_set8_t ext_rate_set; /* +40 */
- uint8_t DTIM_period; /* +50 */
- uint8_t rsn_mode; /* +51 */
+ struct rate_set8_t ext_rate_set; /* +38 */
+ uint8_t DTIM_period; /* +48 */
+ uint8_t rsn_mode; /* +49 */
#define RSN_MODE_NONE 0
#define RSN_MODE_WPA 1
#define RSN_MODE_WPA2 2
struct {
- uint8_t size; /* +52 */
- uint8_t body[128]; /* +53 */
+ uint8_t size; /* +50 */
+ uint8_t body[128]; /* +51 */
} __packed rsn;
} __packed;

@@ -350,19 +348,19 @@ struct hostif_stop_confirm_t {

struct hostif_ps_adhoc_set_request_t {
struct hostif_hdr header;
- uint16_t phy_type;
+ __le16 phy_type;
#define D_11B_ONLY_MODE 0
#define D_11G_ONLY_MODE 1
#define D_11BG_COMPATIBLE_MODE 2
#define D_11A_ONLY_MODE 3
- uint16_t cts_mode;
+ __le16 cts_mode;
#define CTS_MODE_FALSE 0
#define CTS_MODE_TRUE 1
- uint16_t channel;
+ __le16 channel;
struct rate_set16_t rate_set;
- uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
+ __le16 capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
* bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
- uint16_t scan_type;
+ __le16 scan_type;
} __packed;

struct hostif_ps_adhoc_set_confirm_t {
@@ -372,34 +370,34 @@ struct hostif_ps_adhoc_set_confirm_t {

struct hostif_infrastructure_set_request_t {
struct hostif_hdr header;
- uint16_t phy_type;
- uint16_t cts_mode;
+ __le16 phy_type;
+ __le16 cts_mode;
struct rate_set16_t rate_set;
struct ssid_t ssid;
- uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
+ __le16 capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
* bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
- uint16_t beacon_lost_count;
- uint16_t auth_type;
+ __le16 beacon_lost_count;
+ __le16 auth_type;
#define AUTH_TYPE_OPEN_SYSTEM 0
#define AUTH_TYPE_SHARED_KEY 1
struct channel_list_t channel_list;
- uint16_t scan_type;
+ __le16 scan_type;
} __packed;

struct hostif_infrastructure_set2_request_t {
struct hostif_hdr header;
- uint16_t phy_type;
- uint16_t cts_mode;
+ __le16 phy_type;
+ __le16 cts_mode;
struct rate_set16_t rate_set;
struct ssid_t ssid;
- uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
+ __le16 capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
* bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
- uint16_t beacon_lost_count;
- uint16_t auth_type;
+ __le16 beacon_lost_count;
+ __le16 auth_type;
#define AUTH_TYPE_OPEN_SYSTEM 0
#define AUTH_TYPE_SHARED_KEY 1
struct channel_list_t channel_list;
- uint16_t scan_type;
+ __le16 scan_type;
uint8_t bssid[ETH_ALEN];
} __packed;

@@ -410,26 +408,26 @@ struct hostif_infrastructure_set_confirm_t {

struct hostif_adhoc_set_request_t {
struct hostif_hdr header;
- uint16_t phy_type;
- uint16_t cts_mode;
- uint16_t channel;
+ __le16 phy_type;
+ __le16 cts_mode;
+ __le16 channel;
struct rate_set16_t rate_set;
struct ssid_t ssid;
- uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
+ __le16 capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
* bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
- uint16_t scan_type;
+ __le16 scan_type;
} __packed;

struct hostif_adhoc_set2_request_t {
struct hostif_hdr header;
- uint16_t phy_type;
- uint16_t cts_mode;
+ __le16 phy_type;
+ __le16 cts_mode;
uint16_t reserved;
struct rate_set16_t rate_set;
struct ssid_t ssid;
- uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
+ __le16 capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
* bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
- uint16_t scan_type;
+ __le16 scan_type;
struct channel_list_t channel_list;
uint8_t bssid[ETH_ALEN];
} __packed;
@@ -480,8 +478,8 @@ struct hostif_bss_scan_request_t {
#define ACTIVE_SCAN 0
#define PASSIVE_SCAN 1
uint8_t pad[3];
- uint32_t ch_time_min;
- uint32_t ch_time_max;
+ __le32 ch_time_min;
+ __le32 ch_time_max;
struct channel_list_t channel_list;
struct ssid_t ssid;
} __packed;
@@ -494,10 +492,10 @@ struct hostif_bss_scan_confirm_t {

struct hostif_phy_information_request_t {
struct hostif_hdr header;
- uint16_t type;
+ __le16 type;
#define NORMAL_TYPE 0
#define TIME_TYPE 1
- uint16_t time; /* unit 100ms */
+ __le16 time; /* unit 100ms */
} __packed;

struct hostif_phy_information_confirm_t {
@@ -526,8 +524,8 @@ struct hostif_sleep_confirm_t {

struct hostif_mic_failure_request_t {
struct hostif_hdr header;
- uint16_t failure_count;
- uint16_t timer;
+ __le16 failure_count;
+ __le16 timer;
} __packed;

struct hostif_mic_failure_confirm_t {
diff --git a/drivers/staging/ks7010/ks_wlan.h b/drivers/staging/ks7010/ks_wlan.h
index 9ab80e1f123e..a4655a04005c 100644
--- a/drivers/staging/ks7010/ks_wlan.h
+++ b/drivers/staging/ks7010/ks_wlan.h
@@ -243,7 +243,7 @@ struct local_ap_t {
u8 body[16];
u8 rate_pad;
} rate_set;
- u16 capability;
+ __le16 capability;
u8 channel;
u8 noise;
struct rsn_ie_t wpa_ie;
--
2.12.0