2018-06-26 06:07:12

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 00/12] staging: wilc1000: address TODO item to remove host_if_work()

The current patch series contains changes to address TODO item [1].

[1]. Move handling for each individual members of 'union message_body' out
into a separate 'struct work_struct' and completely remove the multiplexer
that is currently part of host_if_work(), allowing movement of the
implementation of each message handler into the callsite of the function
that currently queues the 'host_if_msg'.


Ajay Singh (12):
staging: wilc1000: remove host_if_work() to handle TODO list issue
staging: wilc1000: remove unused marco related to HIF commands
staging: wilc1000: move the allocation of cmd out of
wilc_enqueue_cmd()
staging: wilc1000: added 'work_comp' completion as part of host_if_msg
staging: wilc1000: remove 'hif_thread_comp' completions
staging: wilc1000: rename wilc_enqueue_cmd() to wilc_enqueue_work()
staging: wilc1000: handle freeing of key data in wep add key
staging: wilc1000: handle freeing of key data in wilc_add_ptk()
staging: wilc1000: handle freeing of 'key' & 'seq' data in
wilc_add_rx_gtk()
staging: wilc1000: avoid use of static variable 'inactive_time'
staging: wilc1000: avoid use of static variable 'rssi'
staging: wilc1000: updated TODO file

drivers/staging/wilc1000/TODO | 5 -
drivers/staging/wilc1000/host_interface.c | 1548 +++++++++++----------
drivers/staging/wilc1000/host_interface.h | 7 +-
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 2 +-
4 files changed, 799 insertions(+), 763 deletions(-)

--
2.7.4


2018-06-26 06:07:36

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 07/12] staging: wilc1000: handle freeing of key data in wep add key

Modified the code to free the allocated memory, used to store the key in
wilc_add_wep_key_bss_sta() and wilc_add_wep_key_bss_ap().
After work completion notification is received, free the
memory allocated to avoid missing of free in work function.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 7 -------
1 file changed, 7 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 6d27a9d..2cc9689 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -1551,8 +1551,6 @@ static void handle_key(struct work_struct *work)
memcpy(&key_buf[2], hif_key->attr.wep.key,
hif_key->attr.wep.key_len);

- kfree(hif_key->attr.wep.key);
-
wid_list[2].id = (u16)WID_WEP_KEY_VALUE;
wid_list[2].type = WID_STR;
wid_list[2].size = hif_key->attr.wep.key_len + 2;
@@ -1573,7 +1571,6 @@ static void handle_key(struct work_struct *work)
memcpy(key_buf + 1, &hif_key->attr.wep.key_len, 1);
memcpy(key_buf + 2, hif_key->attr.wep.key,
hif_key->attr.wep.key_len);
- kfree(hif_key->attr.wep.key);

wid.id = (u16)WID_ADD_WEP_KEY;
wid.type = WID_STR;
@@ -2629,8 +2626,6 @@ int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
goto free_key;

wait_for_completion(&msg->work_comp);
- kfree(msg);
- return 0;

free_key:
kfree(msg->body.key_info.attr.wep.key);
@@ -2674,8 +2669,6 @@ int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
goto free_key;

wait_for_completion(&msg->work_comp);
- kfree(msg);
- return 0;

free_key:
kfree(msg->body.key_info.attr.wep.key);
--
2.7.4

2018-06-26 06:07:40

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 08/12] staging: wilc1000: handle freeing of key data in wilc_add_ptk()

Handle freeing of memory allocated to store the 'key' in wilc_add_ptk()
function. Once work completion notification is received, free the
memory allocated to avoid missing of free in work function sepecially
for error scenario.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 2cc9689..2062f4e 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -1724,7 +1724,6 @@ static void handle_key(struct work_struct *work)

out_wpa_ptk:
complete(&msg->work_comp);
- kfree(hif_key->attr.wpa.key);
break;

case PMKSA:
@@ -2735,8 +2734,6 @@ int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
}

wait_for_completion(&msg->work_comp);
- kfree(msg);
- return 0;

free_key:
kfree(msg->body.key_info.attr.wpa.key);
--
2.7.4

2018-06-26 07:49:02

by Claudiu Beznea

[permalink] [raw]
Subject: Re: [PATCH 00/12] staging: wilc1000: address TODO item to remove host_if_work()

For this series:

Reviewed-by: Claudiu Beznea <[email protected]>

On 26.06.2018 09:07, Ajay Singh wrote:
> The current patch series contains changes to address TODO item [1].
>
> [1]. Move handling for each individual members of 'union message_body' out
> into a separate 'struct work_struct' and completely remove the multiplexer
> that is currently part of host_if_work(), allowing movement of the
> implementation of each message handler into the callsite of the function
> that currently queues the 'host_if_msg'.
>
>
> Ajay Singh (12):
> staging: wilc1000: remove host_if_work() to handle TODO list issue
> staging: wilc1000: remove unused marco related to HIF commands
> staging: wilc1000: move the allocation of cmd out of
> wilc_enqueue_cmd()
> staging: wilc1000: added 'work_comp' completion as part of host_if_msg
> staging: wilc1000: remove 'hif_thread_comp' completions
> staging: wilc1000: rename wilc_enqueue_cmd() to wilc_enqueue_work()
> staging: wilc1000: handle freeing of key data in wep add key
> staging: wilc1000: handle freeing of key data in wilc_add_ptk()
> staging: wilc1000: handle freeing of 'key' & 'seq' data in
> wilc_add_rx_gtk()
> staging: wilc1000: avoid use of static variable 'inactive_time'
> staging: wilc1000: avoid use of static variable 'rssi'
> staging: wilc1000: updated TODO file
>
> drivers/staging/wilc1000/TODO | 5 -
> drivers/staging/wilc1000/host_interface.c | 1548 +++++++++++----------
> drivers/staging/wilc1000/host_interface.h | 7 +-
> drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 2 +-
> 4 files changed, 799 insertions(+), 763 deletions(-)
>

2018-06-26 06:07:19

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 02/12] staging: wilc1000: remove unused marco related to HIF commands

After removing the multiplexing of hif commands in hif_if_work()
macros prefix with 'HOST_IF_MSG_' are not required. Also 'id' field in
host_if_msg is not required anymore.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 36 -------------------------------
1 file changed, 36 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 4f6008e..998e0ab 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -1,41 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include "wilc_wfi_netdevice.h"

-#define HOST_IF_MSG_SCAN 0
-#define HOST_IF_MSG_CONNECT 1
-#define HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO 2
-#define HOST_IF_MSG_KEY 3
-#define HOST_IF_MSG_RCVD_NTWRK_INFO 4
-#define HOST_IF_MSG_RCVD_SCAN_COMPLETE 5
-#define HOST_IF_MSG_CFG_PARAMS 6
-#define HOST_IF_MSG_SET_CHANNEL 7
-#define HOST_IF_MSG_DISCONNECT 8
-#define HOST_IF_MSG_GET_RSSI 9
-#define HOST_IF_MSG_ADD_BEACON 11
-#define HOST_IF_MSG_DEL_BEACON 12
-#define HOST_IF_MSG_ADD_STATION 13
-#define HOST_IF_MSG_DEL_STATION 14
-#define HOST_IF_MSG_EDIT_STATION 15
-#define HOST_IF_MSG_SCAN_TIMER_FIRED 16
-#define HOST_IF_MSG_CONNECT_TIMER_FIRED 17
-#define HOST_IF_MSG_POWER_MGMT 18
-#define HOST_IF_MSG_GET_INACTIVETIME 19
-#define HOST_IF_MSG_REMAIN_ON_CHAN 20
-#define HOST_IF_MSG_REGISTER_FRAME 21
-#define HOST_IF_MSG_LISTEN_TIMER_FIRED 22
-#define HOST_IF_MSG_SET_WFIDRV_HANDLER 24
-#define HOST_IF_MSG_GET_MAC_ADDRESS 26
-#define HOST_IF_MSG_SET_OPERATION_MODE 27
-#define HOST_IF_MSG_SET_IPADDRESS 28
-#define HOST_IF_MSG_GET_IPADDRESS 29
-#define HOST_IF_MSG_GET_STATISTICS 31
-#define HOST_IF_MSG_SET_MULTICAST_FILTER 32
-#define HOST_IF_MSG_DEL_BA_SESSION 34
-#define HOST_IF_MSG_DEL_ALL_STA 36
-#define HOST_IF_MSG_SET_TX_POWER 38
-#define HOST_IF_MSG_GET_TX_POWER 39
-#define HOST_IF_MSG_EXIT 100
-
#define HOST_IF_SCAN_TIMEOUT 4000
#define HOST_IF_CONNECT_TIMEOUT 9500

@@ -180,7 +145,6 @@ union message_body {
};

struct host_if_msg {
- u16 id;
union message_body body;
struct wilc_vif *vif;
struct work_struct work;
--
2.7.4

2018-06-26 06:07:33

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 06/12] staging: wilc1000: rename wilc_enqueue_cmd() to wilc_enqueue_work()

Rename wilc_enqueue_cmd() to wilc_enqueue_work() because its used to
enqueue the work queue. Also removed the function header comment for
wilc_enqueue_cmd() as its not correct.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 90 +++++++++++++++----------------
1 file changed, 42 insertions(+), 48 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 17c20b9..6d27a9d 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -227,13 +227,7 @@ wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
return msg;
}

-/*!
- * @author syounan
- * @date 1 Sep 2010
- * @note copied from FLO glue implementatuion
- * @version 1.0
- */
-static int wilc_enqueue_cmd(struct host_if_msg *msg)
+static int wilc_enqueue_work(struct host_if_msg *msg)
{
INIT_WORK(&msg->work, msg->fn);
if (!hif_workqueue || !queue_work(hif_workqueue, &msg->work))
@@ -903,7 +897,7 @@ static void handle_connect(struct work_struct *work)
struct host_if_drv *hif_drv = vif->hif_drv;

if (msg->vif->hif_drv->usr_scan_req.scan_result) {
- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
goto error;

@@ -2353,7 +2347,7 @@ static void listen_timer_cb(struct timer_list *t)

msg->body.remain_on_ch.id = vif->hif_drv->remain_on_ch.id;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
kfree(msg);
@@ -2521,7 +2515,7 @@ static void timer_scan_cb(struct timer_list *t)
if (IS_ERR(msg))
return;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
kfree(msg);
}
@@ -2538,7 +2532,7 @@ static void timer_connect_cb(struct timer_list *t)
if (IS_ERR(msg))
return;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
kfree(msg);
}
@@ -2563,7 +2557,7 @@ int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
msg->body.key_info.action = REMOVEKEY;
msg->body.key_info.attr.wep.index = index;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
netdev_err(vif->ndev, "Request to remove WEP key\n");
else
@@ -2593,7 +2587,7 @@ int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
msg->body.key_info.action = DEFAULTKEY;
msg->body.key_info.attr.wep.index = index;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
netdev_err(vif->ndev, "Default key index\n");
else
@@ -2630,7 +2624,7 @@ int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
msg->body.key_info.attr.wep.key_len = len;
msg->body.key_info.attr.wep.index = index;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
goto free_key;

@@ -2675,7 +2669,7 @@ int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
msg->body.key_info.attr.wep.mode = mode;
msg->body.key_info.attr.wep.auth_type = auth_type;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
goto free_key;

@@ -2741,7 +2735,7 @@ int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
msg->body.key_info.attr.wpa.mac_addr = mac_addr;
msg->body.key_info.attr.wpa.mode = cipher_mode;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "PTK Key\n");
goto free_key;
@@ -2821,7 +2815,7 @@ int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
msg->body.key_info.attr.wpa.key_len = key_len;
msg->body.key_info.attr.wpa.seq_len = key_rsc_len;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "RX GTK\n");
goto free_key;
@@ -2863,7 +2857,7 @@ int wilc_set_pmkid_info(struct wilc_vif *vif,
&pmkid->pmkidlist[i].pmkid, PMKID_LEN);
}

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "PMKID Info\n");
kfree(msg);
@@ -2883,7 +2877,7 @@ int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)

msg->body.get_mac_info.mac_addr = mac_addr;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
netdev_err(vif->ndev, "Failed to send get mac address\n");
else
@@ -2953,7 +2947,7 @@ int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ssid,
if (hif_drv->hif_state < HOST_IF_CONNECTING)
hif_drv->hif_state = HOST_IF_CONNECTING;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "send message: Set join request\n");
goto free_ies;
@@ -2994,7 +2988,7 @@ int wilc_disconnect(struct wilc_vif *vif, u16 reason_code)
if (IS_ERR(msg))
return PTR_ERR(msg);

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
netdev_err(vif->ndev, "Failed to send message: disconnect\n");
else
@@ -3040,7 +3034,7 @@ int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)

msg->body.channel_info.set_ch = channel;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc mq send fail\n");
kfree(msg);
@@ -3063,7 +3057,7 @@ int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
msg->body.drv.mode = mode;
msg->body.drv.name = ifc_id;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc mq send fail\n");
kfree(msg);
@@ -3082,7 +3076,7 @@ int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode)
return PTR_ERR(msg);

msg->body.mode.mode = mode;
- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc mq send fail\n");
kfree(msg);
@@ -3109,7 +3103,7 @@ s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac,

memcpy(msg->body.mac_info.mac, mac, ETH_ALEN);

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
netdev_err(vif->ndev, "Failed to send get host ch param\n");
else
@@ -3135,7 +3129,7 @@ int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
if (IS_ERR(msg))
return PTR_ERR(msg);

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "Failed to send get host ch param\n");
} else {
@@ -3160,7 +3154,7 @@ wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats, bool is_sync)

msg->body.data = (char *)stats;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "Failed to send get host channel\n");
kfree(msg);
@@ -3222,7 +3216,7 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
goto free_freq_list;
}

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "Error in sending message queue\n");
goto free_ies;
@@ -3262,7 +3256,7 @@ int wilc_hif_set_cfg(struct wilc_vif *vif,
return PTR_ERR(msg);

msg->body.cfg_info = *cfg_param;
- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
kfree(msg);

@@ -3387,7 +3381,7 @@ int wilc_deinit(struct wilc_vif *vif)
if (IS_ERR(msg))
return PTR_ERR(msg);

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
netdev_err(vif->ndev, "deinit : Error(%d)\n", result);
else
@@ -3437,7 +3431,7 @@ void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
return;
}

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "message parameters (%d)\n", result);
kfree(msg->body.net_info.buffer);
@@ -3492,7 +3486,7 @@ void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
return;
}

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "synchronous info (%d)\n", result);
kfree(msg->body.async_info.buffer);
@@ -3528,7 +3522,7 @@ void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
if (IS_ERR(msg))
return;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "complete param (%d)\n", result);
kfree(msg);
@@ -3556,7 +3550,7 @@ int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
msg->body.remain_on_ch.duration = duration;
msg->body.remain_on_ch.id = session_id;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc mq send fail\n");
kfree(msg);
@@ -3584,7 +3578,7 @@ int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id)

msg->body.remain_on_ch.id = session_id;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc mq send fail\n");
kfree(msg);
@@ -3617,7 +3611,7 @@ int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
msg->body.reg_frame.frame_type = frame_type;
msg->body.reg_frame.reg = reg;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc mq send fail\n");
kfree(msg);
@@ -3658,7 +3652,7 @@ int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
beacon_info->tail = NULL;
}

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result)
netdev_err(vif->ndev, "wilc mq send fail\n");

@@ -3681,7 +3675,7 @@ int wilc_del_beacon(struct wilc_vif *vif)
if (IS_ERR(msg))
return PTR_ERR(msg);

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
kfree(msg);
@@ -3712,7 +3706,7 @@ int wilc_add_station(struct wilc_vif *vif, struct add_sta_param *sta_param)
}
}

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
kfree(add_sta_info->rates);
@@ -3738,7 +3732,7 @@ int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
else
memcpy(del_sta_info->mac_addr, mac_addr, ETH_ALEN);

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
kfree(msg);
@@ -3774,7 +3768,7 @@ int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
}

del_all_sta_info->assoc_sta = assoc_sta;
- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);

if (result)
netdev_err(vif->ndev, "wilc_mq_send fail\n");
@@ -3809,7 +3803,7 @@ int wilc_edit_station(struct wilc_vif *vif,
}
}

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
kfree(add_sta_info->rates);
@@ -3834,7 +3828,7 @@ int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
msg->body.pwr_mgmt_info.enabled = enabled;
msg->body.pwr_mgmt_info.timeout = timeout;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
kfree(msg);
@@ -3855,7 +3849,7 @@ int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled,
msg->body.multicast_info.enabled = enabled;
msg->body.multicast_info.cnt = count;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
kfree(msg);
@@ -4040,7 +4034,7 @@ int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
msg->body.ip_info.ip_addr = ip_addr;
msg->body.ip_info.idx = idx;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
kfree(msg);
@@ -4061,7 +4055,7 @@ static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
msg->body.ip_info.ip_addr = ip_addr;
msg->body.ip_info.idx = idx;

- result = wilc_enqueue_cmd(msg);
+ result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
kfree(msg);
@@ -4081,7 +4075,7 @@ int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)

msg->body.tx_power.tx_pwr = tx_power;

- ret = wilc_enqueue_cmd(msg);
+ ret = wilc_enqueue_work(msg);
if (ret) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
kfree(msg);
@@ -4099,7 +4093,7 @@ int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
if (IS_ERR(msg))
return PTR_ERR(msg);

- ret = wilc_enqueue_cmd(msg);
+ ret = wilc_enqueue_work(msg);
if (ret) {
netdev_err(vif->ndev, "Failed to get TX PWR\n");
} else {
--
2.7.4

2018-06-26 06:07:53

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 12/12] staging: wilc1000: updated TODO file

Item [1] in TODO list is already addressed, so removed it from TODO file.

[1]. Move handling for each individual members of 'union message_body' out
into a separate 'struct work_struct' and completely remove the
multiplexerthat is currently part of host_if_work(), allowing movement
of the implementation of each message handler into the callsite of the
function that currently queues the 'host_if_msg'.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/TODO | 5 -----
1 file changed, 5 deletions(-)

diff --git a/drivers/staging/wilc1000/TODO b/drivers/staging/wilc1000/TODO
index d123324..725bede 100644
--- a/drivers/staging/wilc1000/TODO
+++ b/drivers/staging/wilc1000/TODO
@@ -1,10 +1,5 @@
TODO:
- rework comments and function headers(also coding style)
-- Move handling for each individual members of 'union message_body' out
- into a separate 'struct work_struct' and completely remove the multiplexer
- that is currently part of host_if_work(), allowing movement of the
- implementation of each message handler into the callsite of the function
- that currently queues the 'host_if_msg'.
- make spi and sdio components coexist in one build
- support soft-ap and p2p mode
- support resume/suspend function
--
2.7.4

2018-06-26 06:07:43

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 09/12] staging: wilc1000: handle freeing of 'key' & 'seq' data in wilc_add_rx_gtk()

Handle freeing of memory allocated to keep 'key' & 'seq' in wilc_add_rx_gtk().
Once completion event is received, free the memory allocated for
to avoid missing of free in work function.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 4 ----
1 file changed, 4 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 2062f4e..2251c39f 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -1667,8 +1667,6 @@ static void handle_key(struct work_struct *work)
}
out_wpa_rx_gtk:
complete(&msg->work_comp);
- kfree(hif_key->attr.wpa.key);
- kfree(hif_key->attr.wpa.seq);
break;

case WPA_PTK:
@@ -2812,8 +2810,6 @@ int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
}

wait_for_completion(&msg->work_comp);
- kfree(msg);
- return 0;

free_key:
kfree(msg->body.key_info.attr.wpa.key);
--
2.7.4

2018-06-26 06:07:50

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 11/12] staging: wilc1000: avoid use of static variable 'rssi'

Instead of static variable now allocating the data and passing to
handle_get_rssi() to fill the rssi information.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index f61a20d..52c0c10 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -196,7 +196,6 @@ u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];

static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];

-static s8 rssi;
static u8 set_ip[2][4];
static u8 get_ip[2][4];
static u32 clients_count;
@@ -1829,7 +1828,7 @@ static void handle_get_rssi(struct work_struct *work)

wid.id = (u16)WID_RSSI;
wid.type = WID_CHAR;
- wid.val = &rssi;
+ wid.val = msg->body.data;
wid.size = sizeof(char);

result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
@@ -3115,14 +3114,21 @@ int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
if (IS_ERR(msg))
return PTR_ERR(msg);

+ msg->body.data = kzalloc(sizeof(s8), GFP_KERNEL);
+ if (!msg->body.data) {
+ kfree(msg);
+ return -ENOMEM;
+ }
+
result = wilc_enqueue_work(msg);
if (result) {
netdev_err(vif->ndev, "Failed to send get host ch param\n");
} else {
wait_for_completion(&msg->work_comp);
- *rssi_level = rssi;
+ *rssi_level = *msg->body.data;
}

+ kfree(msg->body.data);
kfree(msg);

return result;
--
2.7.4

2018-06-26 06:07:47

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 10/12] staging: wilc1000: avoid use of static variable 'inactive_time'

Avoided the use of static variable 'inactive_time' and move it as part of
'sta_inactive_t' structure.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 2251c39f..f61a20d 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -110,6 +110,7 @@ struct set_ip_addr {
};

struct sta_inactive_t {
+ u32 inactive_time;
u8 mac[6];
};

@@ -198,7 +199,6 @@ static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];
static s8 rssi;
static u8 set_ip[2][4];
static u8 get_ip[2][4];
-static u32 inactive_time;
static u32 clients_count;

static void *host_int_parse_join_bss_param(struct network_info *info);
@@ -1927,7 +1927,7 @@ static void handle_get_inactive_time(struct work_struct *work)

wid.id = (u16)WID_GET_INACTIVE_TIME;
wid.type = WID_INT;
- wid.val = (s8 *)&inactive_time;
+ wid.val = (s8 *)&hif_sta_inactive->inactive_time;
wid.size = sizeof(u32);

result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
@@ -3095,7 +3095,7 @@ s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac,
else
wait_for_completion(&msg->work_comp);

- *out_val = inactive_time;
+ *out_val = msg->body.mac_info.inactive_time;
kfree(msg);

return result;
--
2.7.4

2018-06-26 06:07:26

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 04/12] staging: wilc1000: added 'work_comp' completion as part of host_if_msg

Added 'work_comp' completion in 'host_if_msg'. It allows handling the
sync call to wait for sepecific completion event.
The commands can be run in sync way waiting for their specific
completion event.
Added is_sync flag in wilc_create_work_queue() to handle the sync call to
host interface.

After adding completion as part of host_if_msg now
below completion are not required
comp_test_key_block;
comp_test_disconn_block
comp_get_rssi
comp_inactive_time
hif_wait_response

Modified wilc_get_statistics() API to handle get statistic in sync &
async way.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 256 +++++++++++-----------
drivers/staging/wilc1000/host_interface.h | 7 +-
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 2 +-
3 files changed, 132 insertions(+), 133 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index cb627b0..27516f7 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -149,6 +149,8 @@ struct host_if_msg {
struct wilc_vif *vif;
struct work_struct work;
void (*fn)(struct work_struct *ws);
+ struct completion work_comp;
+ bool is_sync;
};

struct join_bss_param {
@@ -186,7 +188,6 @@ static u8 p2p_listen_state;
static struct workqueue_struct *hif_workqueue;
static struct completion hif_thread_comp;
static struct completion hif_driver_comp;
-static struct completion hif_wait_response;
static struct mutex hif_deinit_lock;
static struct timer_list periodic_rssi;
static struct wilc_vif *periodic_rssi_vif;
@@ -205,8 +206,10 @@ static void *host_int_parse_join_bss_param(struct network_info *info);
static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
static s32 handle_scan_done(struct wilc_vif *vif, enum scan_event evt);

+/* 'msg' should be free by the caller for syc */
static struct host_if_msg*
-wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *))
+wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
+ bool is_sync)
{
struct host_if_msg *msg;

@@ -218,6 +221,9 @@ wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *))
return ERR_PTR(-ENOMEM);
msg->fn = work_fun;
msg->vif = vif;
+ msg->is_sync = is_sync;
+ if (is_sync)
+ init_completion(&msg->work_comp);

return msg;
}
@@ -434,8 +440,8 @@ static void handle_get_mac_address(struct work_struct *work)

if (ret)
netdev_err(vif->ndev, "Failed to get mac address\n");
- complete(&hif_wait_response);
- kfree(msg);
+ complete(&msg->work_comp);
+ /* free 'msg' data later, in caller */
complete(&hif_thread_comp);
}

@@ -1618,7 +1624,7 @@ static void handle_key(struct work_struct *work)
wilc_get_vif_idx(vif));
}
out_wep:
- complete(&hif_drv->comp_test_key_block);
+ complete(&msg->work_comp);
break;

case WPA_RX_GTK:
@@ -1682,7 +1688,7 @@ static void handle_key(struct work_struct *work)
kfree(key_buf);
}
out_wpa_rx_gtk:
- complete(&hif_drv->comp_test_key_block);
+ complete(&msg->work_comp);
kfree(hif_key->attr.wpa.key);
kfree(hif_key->attr.wpa.seq);
break;
@@ -1739,19 +1745,21 @@ static void handle_key(struct work_struct *work)
}

out_wpa_ptk:
- complete(&hif_drv->comp_test_key_block);
+ complete(&msg->work_comp);
kfree(hif_key->attr.wpa.key);
break;

case PMKSA:
result = wilc_pmksa_key_copy(vif, hif_key);
+ /*free 'msg', this case it not a sync call*/
+ kfree(msg);
break;
}

if (result)
netdev_err(vif->ndev, "Failed to send key config packet\n");

- kfree(msg);
+ /* free 'msg' data in caller sync call */
complete(&hif_thread_comp);
}

@@ -1825,8 +1833,8 @@ static void handle_disconnect(struct work_struct *work)

out:

- complete(&hif_drv->comp_test_disconn_block);
- kfree(msg);
+ complete(&msg->work_comp);
+ /* free 'msg' in caller after receiving completion */
complete(&hif_thread_comp);
}

@@ -1856,8 +1864,8 @@ static void handle_get_rssi(struct work_struct *work)
if (result)
netdev_err(vif->ndev, "Failed to get RSSI value\n");

- complete(&vif->hif_drv->comp_get_rssi);
- kfree(msg);
+ complete(&msg->work_comp);
+ /* free 'msg' data in caller */
complete(&hif_thread_comp);
}

@@ -1912,9 +1920,12 @@ static void handle_get_statistics(struct work_struct *work)
else if (stats->link_speed != DEFAULT_LINK_SPEED)
wilc_enable_tcp_ack_filter(false);

- if (stats != &vif->wilc->dummy_statistics)
- complete(&hif_wait_response);
- kfree(msg);
+ /* free 'msg' for async command, for sync caller will free it */
+ if (msg->is_sync)
+ complete(&msg->work_comp);
+ else
+ kfree(msg);
+
complete(&hif_thread_comp);
}

@@ -1925,7 +1936,6 @@ static void handle_get_inactive_time(struct work_struct *work)
struct sta_inactive_t *hif_sta_inactive = &msg->body.mac_info;
s32 result = 0;
struct wid wid;
- struct host_if_drv *hif_drv = vif->hif_drv;

wid.id = (u16)WID_SET_STA_MAC_INACTIVE_TIME;
wid.type = WID_STR;
@@ -1957,9 +1967,8 @@ static void handle_get_inactive_time(struct work_struct *work)
netdev_err(vif->ndev, "Failed to get inactive time\n");

out:
- complete(&hif_drv->comp_inactive_time);
-
- kfree(msg);
+ /* free 'msg' data in caller */
+ complete(&msg->work_comp);
complete(&hif_thread_comp);
}

@@ -2143,8 +2152,8 @@ static void handle_del_all_sta(struct work_struct *work)
error:
kfree(wid.val);

- complete(&hif_wait_response);
- kfree(msg);
+ /* free 'msg' data in caller */
+ complete(&msg->work_comp);
complete(&hif_thread_comp);
}

@@ -2365,7 +2374,7 @@ static void listen_timer_cb(struct timer_list *t)

del_timer(&vif->hif_drv->remain_on_ch_timer);

- msg = wilc_alloc_work(vif, handle_listen_state_expired);
+ msg = wilc_alloc_work(vif, handle_listen_state_expired, false);
if (IS_ERR(msg))
return;

@@ -2487,7 +2496,7 @@ static void handle_get_tx_pwr(struct work_struct *work)
if (ret)
netdev_err(vif->ndev, "Failed to get TX PWR\n");

- complete(&hif_wait_response);
+ complete(&msg->work_comp);
complete(&hif_thread_comp);
}

@@ -2513,8 +2522,8 @@ static void handle_hif_exit_work(struct work_struct *work)
{
struct host_if_msg *msg = container_of(work, struct host_if_msg, work);

- kfree(msg);
- complete(&hif_thread_comp);
+ /* free 'msg' data in caller */
+ complete(&msg->work_comp);
}

static void handle_scan_complete(struct work_struct *work)
@@ -2542,7 +2551,7 @@ static void timer_scan_cb(struct timer_list *t)
struct host_if_msg *msg;
int result;

- msg = wilc_alloc_work(vif, handle_scan_timer);
+ msg = wilc_alloc_work(vif, handle_scan_timer, false);
if (IS_ERR(msg))
return;

@@ -2559,7 +2568,7 @@ static void timer_connect_cb(struct timer_list *t)
struct host_if_msg *msg;
int result;

- msg = wilc_alloc_work(vif, handle_connect_timeout);
+ msg = wilc_alloc_work(vif, handle_connect_timeout, false);
if (IS_ERR(msg))
return;

@@ -2580,7 +2589,7 @@ int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
return result;
}

- msg = wilc_alloc_work(vif, handle_key);
+ msg = wilc_alloc_work(vif, handle_key, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -2589,13 +2598,12 @@ int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
msg->body.key_info.attr.wep.index = index;

result = wilc_enqueue_cmd(msg);
- if (result) {
+ if (result)
netdev_err(vif->ndev, "Request to remove WEP key\n");
- kfree(msg);
- } else {
- wait_for_completion(&hif_drv->comp_test_key_block);
- }
+ else
+ wait_for_completion(&msg->work_comp);

+ kfree(msg);
return result;
}

@@ -2611,7 +2619,7 @@ int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
return result;
}

- msg = wilc_alloc_work(vif, handle_key);
+ msg = wilc_alloc_work(vif, handle_key, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -2620,13 +2628,12 @@ int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
msg->body.key_info.attr.wep.index = index;

result = wilc_enqueue_cmd(msg);
- if (result) {
+ if (result)
netdev_err(vif->ndev, "Default key index\n");
- kfree(msg);
- } else {
- wait_for_completion(&hif_drv->comp_test_key_block);
- }
+ else
+ wait_for_completion(&msg->work_comp);

+ kfree(msg);
return result;
}

@@ -2642,7 +2649,7 @@ int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
return -EFAULT;
}

- msg = wilc_alloc_work(vif, handle_key);
+ msg = wilc_alloc_work(vif, handle_key, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -2661,7 +2668,8 @@ int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
if (result)
goto free_key;

- wait_for_completion(&hif_drv->comp_test_key_block);
+ wait_for_completion(&msg->work_comp);
+ kfree(msg);
return 0;

free_key:
@@ -2684,7 +2692,7 @@ int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
return -EFAULT;
}

- msg = wilc_alloc_work(vif, handle_key);
+ msg = wilc_alloc_work(vif, handle_key, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -2705,7 +2713,8 @@ int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
if (result)
goto free_key;

- wait_for_completion(&hif_drv->comp_test_key_block);
+ wait_for_completion(&msg->work_comp);
+ kfree(msg);
return 0;

free_key:
@@ -2736,7 +2745,7 @@ int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
if (tx_mic)
key_len += TX_MIC_KEY_LEN;

- msg = wilc_alloc_work(vif, handle_key);
+ msg = wilc_alloc_work(vif, handle_key, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -2772,7 +2781,8 @@ int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
goto free_key;
}

- wait_for_completion(&hif_drv->comp_test_key_block);
+ wait_for_completion(&msg->work_comp);
+ kfree(msg);
return 0;

free_key:
@@ -2798,7 +2808,7 @@ int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
return -EFAULT;
}

- msg = wilc_alloc_work(vif, handle_key);
+ msg = wilc_alloc_work(vif, handle_key, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -2851,7 +2861,8 @@ int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
goto free_key;
}

- wait_for_completion(&hif_drv->comp_test_key_block);
+ wait_for_completion(&msg->work_comp);
+ kfree(msg);
return 0;

free_key:
@@ -2872,7 +2883,7 @@ int wilc_set_pmkid_info(struct wilc_vif *vif,
struct host_if_msg *msg;
int i;

- msg = wilc_alloc_work(vif, handle_key);
+ msg = wilc_alloc_work(vif, handle_key, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -2900,20 +2911,20 @@ int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
int result = 0;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_get_mac_address);
+ msg = wilc_alloc_work(vif, handle_get_mac_address, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

msg->body.get_mac_info.mac_addr = mac_addr;

result = wilc_enqueue_cmd(msg);
- if (result) {
+ if (result)
netdev_err(vif->ndev, "Failed to send get mac address\n");
- kfree(msg);
- return -EFAULT;
- }
+ else
+ wait_for_completion(&msg->work_comp);
+
+ kfree(msg);

- wait_for_completion(&hif_wait_response);
return result;
}

@@ -2937,7 +2948,7 @@ int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ssid,
return -EFAULT;
}

- msg = wilc_alloc_work(vif, handle_connect);
+ msg = wilc_alloc_work(vif, handle_connect, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3013,18 +3024,17 @@ int wilc_disconnect(struct wilc_vif *vif, u16 reason_code)
return -EFAULT;
}

- msg = wilc_alloc_work(vif, handle_disconnect);
+ msg = wilc_alloc_work(vif, handle_disconnect, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

result = wilc_enqueue_cmd(msg);
- if (result) {
+ if (result)
netdev_err(vif->ndev, "Failed to send message: disconnect\n");
- kfree(msg);
- } else {
- wait_for_completion(&hif_drv->comp_test_disconn_block);
- }
+ else
+ wait_for_completion(&msg->work_comp);

+ kfree(msg);
return result;
}

@@ -3058,7 +3068,7 @@ int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
int result;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_set_channel);
+ msg = wilc_alloc_work(vif, handle_set_channel, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3079,7 +3089,7 @@ int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
int result = 0;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_set_wfi_drv_handler);
+ msg = wilc_alloc_work(vif, handle_set_wfi_drv_handler, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3101,7 +3111,7 @@ int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode)
int result = 0;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_set_operation_mode);
+ msg = wilc_alloc_work(vif, handle_set_operation_mode, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3127,21 +3137,20 @@ s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac,
return -EFAULT;
}

- msg = wilc_alloc_work(vif, handle_get_inactive_time);
+ msg = wilc_alloc_work(vif, handle_get_inactive_time, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

memcpy(msg->body.mac_info.mac, mac, ETH_ALEN);

result = wilc_enqueue_cmd(msg);
- if (result) {
+ if (result)
netdev_err(vif->ndev, "Failed to send get host ch param\n");
- kfree(msg);
- } else {
- wait_for_completion(&hif_drv->comp_inactive_time);
- }
+ else
+ wait_for_completion(&msg->work_comp);

*out_val = inactive_time;
+ kfree(msg);

return result;
}
@@ -3150,37 +3159,36 @@ int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
{
int result = 0;
struct host_if_msg *msg;
- struct host_if_drv *hif_drv = vif->hif_drv;

- msg = wilc_alloc_work(vif, handle_get_rssi);
+ if (!rssi_level) {
+ netdev_err(vif->ndev, "RSS pointer value is null\n");
+ return -EFAULT;
+ }
+
+ msg = wilc_alloc_work(vif, handle_get_rssi, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "Failed to send get host ch param\n");
- kfree(msg);
- return result;
- }
-
- wait_for_completion(&hif_drv->comp_get_rssi);
-
- if (!rssi_level) {
- netdev_err(vif->ndev, "RSS pointer value is null\n");
- return -EFAULT;
+ } else {
+ wait_for_completion(&msg->work_comp);
+ *rssi_level = rssi;
}

- *rssi_level = rssi;
+ kfree(msg);

return result;
}

-int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
+int
+wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats, bool is_sync)
{
int result = 0;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_get_statistics);
+ msg = wilc_alloc_work(vif, handle_get_statistics, is_sync);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3193,8 +3201,11 @@ int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
return result;
}

- if (stats != &vif->wilc->dummy_statistics)
- wait_for_completion(&hif_wait_response);
+ if (is_sync) {
+ wait_for_completion(&msg->work_comp);
+ kfree(msg);
+ }
+
return result;
}

@@ -3213,7 +3224,7 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
return -EFAULT;
}

- msg = wilc_alloc_work(vif, handle_scan);
+ msg = wilc_alloc_work(vif, handle_scan, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3280,7 +3291,7 @@ int wilc_hif_set_cfg(struct wilc_vif *vif,
return -EFAULT;
}

- msg = wilc_alloc_work(vif, handle_cfg_param);
+ msg = wilc_alloc_work(vif, handle_cfg_param, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3302,7 +3313,7 @@ static void get_periodic_rssi(struct timer_list *unused)
}

if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
- wilc_get_statistics(vif, &vif->wilc->dummy_statistics);
+ wilc_get_statistics(vif, &vif->wilc->dummy_statistics, false);

mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000));
}
@@ -3317,8 +3328,6 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
vif = netdev_priv(dev);
wilc = vif->wilc;

- init_completion(&hif_wait_response);
-
hif_drv = kzalloc(sizeof(*hif_drv), GFP_KERNEL);
if (!hif_drv)
return -ENOMEM;
@@ -3339,11 +3348,6 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
mutex_init(&hif_deinit_lock);
}

- init_completion(&hif_drv->comp_test_key_block);
- init_completion(&hif_drv->comp_test_disconn_block);
- init_completion(&hif_drv->comp_get_rssi);
- init_completion(&hif_drv->comp_inactive_time);
-
if (clients_count == 0) {
hif_workqueue = create_singlethread_workqueue("WILC_wq");
if (!hif_workqueue) {
@@ -3414,7 +3418,7 @@ int wilc_deinit(struct wilc_vif *vif)
if (clients_count == 1) {
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_hif_exit_work);
+ msg = wilc_alloc_work(vif, handle_hif_exit_work, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3422,8 +3426,8 @@ int wilc_deinit(struct wilc_vif *vif)
if (result)
netdev_err(vif->ndev, "deinit : Error(%d)\n", result);
else
- wait_for_completion(&hif_thread_comp);
-
+ wait_for_completion(&msg->work_comp);
+ kfree(msg);
destroy_workqueue(hif_workqueue);
}

@@ -3457,7 +3461,7 @@ void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
return;
}

- msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info);
+ msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info, false);
if (IS_ERR(msg))
return;

@@ -3509,7 +3513,7 @@ void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
return;
}

- msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info);
+ msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info, false);
if (IS_ERR(msg)) {
mutex_unlock(&hif_deinit_lock);
return;
@@ -3555,7 +3559,7 @@ void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
if (hif_drv->usr_scan_req.scan_result) {
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_scan_complete);
+ msg = wilc_alloc_work(vif, handle_scan_complete, false);
if (IS_ERR(msg))
return;

@@ -3576,7 +3580,7 @@ int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
int result = 0;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_remain_on_chan_work);
+ msg = wilc_alloc_work(vif, handle_remain_on_chan_work, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3609,7 +3613,7 @@ int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id)

del_timer(&hif_drv->remain_on_ch_timer);

- msg = wilc_alloc_work(vif, handle_listen_state_expired);
+ msg = wilc_alloc_work(vif, handle_listen_state_expired, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3629,7 +3633,7 @@ int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
int result = 0;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_register_frame);
+ msg = wilc_alloc_work(vif, handle_register_frame, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3664,7 +3668,7 @@ int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
struct host_if_msg *msg;
struct beacon_attr *beacon_info;

- msg = wilc_alloc_work(vif, handle_add_beacon);
+ msg = wilc_alloc_work(vif, handle_add_beacon, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3708,7 +3712,7 @@ int wilc_del_beacon(struct wilc_vif *vif)
int result = 0;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_del_beacon);
+ msg = wilc_alloc_work(vif, handle_del_beacon, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3727,7 +3731,7 @@ int wilc_add_station(struct wilc_vif *vif, struct add_sta_param *sta_param)
struct host_if_msg *msg;
struct add_sta_param *add_sta_info;

- msg = wilc_alloc_work(vif, handle_add_station);
+ msg = wilc_alloc_work(vif, handle_add_station, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3758,7 +3762,7 @@ int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
struct host_if_msg *msg;
struct del_sta *del_sta_info;

- msg = wilc_alloc_work(vif, handle_del_station);
+ msg = wilc_alloc_work(vif, handle_del_station, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3786,7 +3790,7 @@ int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
int i;
u8 assoc_sta = 0;

- msg = wilc_alloc_work(vif, handle_del_all_sta);
+ msg = wilc_alloc_work(vif, handle_del_all_sta, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3807,12 +3811,12 @@ int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
del_all_sta_info->assoc_sta = assoc_sta;
result = wilc_enqueue_cmd(msg);

- if (result) {
+ if (result)
netdev_err(vif->ndev, "wilc_mq_send fail\n");
- kfree(msg);
- } else {
- wait_for_completion(&hif_wait_response);
- }
+ else
+ wait_for_completion(&msg->work_comp);
+
+ kfree(msg);

return result;
}
@@ -3824,7 +3828,7 @@ int wilc_edit_station(struct wilc_vif *vif,
struct host_if_msg *msg;
struct add_sta_param *add_sta_info;

- msg = wilc_alloc_work(vif, handle_edit_station);
+ msg = wilc_alloc_work(vif, handle_edit_station, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3858,7 +3862,7 @@ int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
if (wilc_wlan_get_num_conn_ifcs(vif->wilc) == 2 && enabled)
return 0;

- msg = wilc_alloc_work(vif, handle_power_management);
+ msg = wilc_alloc_work(vif, handle_power_management, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3879,7 +3883,7 @@ int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled,
int result = 0;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_set_mcast_filter);
+ msg = wilc_alloc_work(vif, handle_set_mcast_filter, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -4064,7 +4068,7 @@ int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
int result = 0;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_set_ip_address);
+ msg = wilc_alloc_work(vif, handle_set_ip_address, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -4085,7 +4089,7 @@ static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
int result = 0;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_get_ip_address);
+ msg = wilc_alloc_work(vif, handle_get_ip_address, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -4106,7 +4110,7 @@ int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
int ret = 0;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_set_tx_pwr);
+ msg = wilc_alloc_work(vif, handle_set_tx_pwr, false);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -4126,20 +4130,18 @@ int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
int ret = 0;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_get_tx_pwr);
+ msg = wilc_alloc_work(vif, handle_get_tx_pwr, true);
if (IS_ERR(msg))
return PTR_ERR(msg);

ret = wilc_enqueue_cmd(msg);
if (ret) {
netdev_err(vif->ndev, "Failed to get TX PWR\n");
- kfree(msg);
- return ret;
+ } else {
+ wait_for_completion(&msg->work_comp);
+ *tx_power = msg->body.tx_power.tx_pwr;
}

- wait_for_completion(&hif_wait_response);
-
- *tx_power = msg->body.tx_power.tx_pwr;
/* free 'msg' after copying data */
kfree(msg);
return ret;
diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h
index 068b587..0ea22ab 100644
--- a/drivers/staging/wilc1000/host_interface.h
+++ b/drivers/staging/wilc1000/host_interface.h
@@ -273,10 +273,6 @@ struct host_if_drv {
struct cfg_param_attr cfg_values;
/*lock to protect concurrent setting of cfg params*/
struct mutex cfg_values_lock;
- struct completion comp_test_key_block;
- struct completion comp_test_disconn_block;
- struct completion comp_get_rssi;
- struct completion comp_inactive_time;

struct timer_list scan_timer;
struct wilc_vif *scan_timer_vif;
@@ -359,7 +355,8 @@ int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg);
int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
u8 ifc_id);
int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode);
-int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats);
+int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats,
+ bool is_sync);
void wilc_resolve_disconnect_aberration(struct wilc_vif *vif);
int wilc_get_vif_idx(struct wilc_vif *vif);
int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power);
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index e248702..1f09925 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -1148,7 +1148,7 @@ static int get_station(struct wiphy *wiphy, struct net_device *dev,
} else if (vif->iftype == STATION_MODE) {
struct rf_info stats;

- wilc_get_statistics(vif, &stats);
+ wilc_get_statistics(vif, &stats, true);

sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
BIT(NL80211_STA_INFO_RX_PACKETS) |
--
2.7.4

2018-06-26 06:07:23

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 03/12] staging: wilc1000: move the allocation of cmd out of wilc_enqueue_cmd()

Instead of allocating the host_if_cmd in wilc_enqueue_cmd() now moved
the allocation of cmd in the caller. Added the NULL check for
'hif_workqueue' before posting the work queue in wilc_enqueue_cmd().

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 943 +++++++++++++++++-------------
1 file changed, 544 insertions(+), 399 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 998e0ab..cb627b0 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -205,6 +205,23 @@ static void *host_int_parse_join_bss_param(struct network_info *info);
static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
static s32 handle_scan_done(struct wilc_vif *vif, enum scan_event evt);

+static struct host_if_msg*
+wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *))
+{
+ struct host_if_msg *msg;
+
+ if (!work_fun)
+ return ERR_PTR(-EINVAL);
+
+ msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
+ if (!msg)
+ return ERR_PTR(-ENOMEM);
+ msg->fn = work_fun;
+ msg->vif = vif;
+
+ return msg;
+}
+
/*!
* @author syounan
* @date 1 Sep 2010
@@ -213,14 +230,10 @@ static s32 handle_scan_done(struct wilc_vif *vif, enum scan_event evt);
*/
static int wilc_enqueue_cmd(struct host_if_msg *msg)
{
- struct host_if_msg *new_msg;
-
- new_msg = kmemdup(msg, sizeof(*new_msg), GFP_ATOMIC);
- if (!new_msg)
- return -ENOMEM;
+ INIT_WORK(&msg->work, msg->fn);
+ if (!hif_workqueue || !queue_work(hif_workqueue, &msg->work))
+ return -EINVAL;

- INIT_WORK(&new_msg->work, msg->fn);
- queue_work(hif_workqueue, &new_msg->work);
return 0;
}

@@ -896,8 +909,8 @@ static void handle_connect(struct work_struct *work)
result = wilc_enqueue_cmd(msg);
if (result)
goto error;
+
usleep_range(2 * 1000, 2 * 1000);
- kfree(msg);
return;
}

@@ -2348,18 +2361,21 @@ static void listen_timer_cb(struct timer_list *t)
remain_on_ch_timer);
struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
s32 result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;

del_timer(&vif->hif_drv->remain_on_ch_timer);

- memset(&msg, 0, sizeof(struct host_if_msg));
- msg.fn = handle_listen_state_expired;
- msg.vif = vif;
- msg.body.remain_on_ch.id = vif->hif_drv->remain_on_ch.id;
+ msg = wilc_alloc_work(vif, handle_listen_state_expired);
+ if (IS_ERR(msg))
+ return;
+
+ msg->body.remain_on_ch.id = vif->hif_drv->remain_on_ch.id;

- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
+ kfree(msg);
+ }
}

static void handle_power_management(struct work_struct *work)
@@ -2452,6 +2468,7 @@ static void handle_set_tx_pwr(struct work_struct *work)
complete(&hif_thread_comp);
}

+/* Note: 'msg' will be free after using data */
static void handle_get_tx_pwr(struct work_struct *work)
{
struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
@@ -2471,7 +2488,6 @@ static void handle_get_tx_pwr(struct work_struct *work)
netdev_err(vif->ndev, "Failed to get TX PWR\n");

complete(&hif_wait_response);
- kfree(msg);
complete(&hif_thread_comp);
}

@@ -2523,13 +2539,16 @@ static void timer_scan_cb(struct timer_list *t)
{
struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
struct wilc_vif *vif = hif_drv->scan_timer_vif;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
+ int result;

- memset(&msg, 0, sizeof(struct host_if_msg));
- msg.vif = vif;
- msg.fn = handle_scan_timer;
+ msg = wilc_alloc_work(vif, handle_scan_timer);
+ if (IS_ERR(msg))
+ return;

- wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
+ if (result)
+ kfree(msg);
}

static void timer_connect_cb(struct timer_list *t)
@@ -2537,19 +2556,22 @@ static void timer_connect_cb(struct timer_list *t)
struct host_if_drv *hif_drv = from_timer(hif_drv, t,
connect_timer);
struct wilc_vif *vif = hif_drv->connect_timer_vif;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
+ int result;

- memset(&msg, 0, sizeof(struct host_if_msg));
- msg.vif = vif;
- msg.fn = handle_connect_timeout;
+ msg = wilc_alloc_work(vif, handle_connect_timeout);
+ if (IS_ERR(msg))
+ return;

- wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
+ if (result)
+ kfree(msg);
}

int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
struct host_if_drv *hif_drv = vif->hif_drv;

if (!hif_drv) {
@@ -2558,19 +2580,21 @@ int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
return result;
}

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_key);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_key;
- msg.body.key_info.type = WEP;
- msg.body.key_info.action = REMOVEKEY;
- msg.vif = vif;
- msg.body.key_info.attr.wep.index = index;
+ msg->body.key_info.type = WEP;
+ msg->body.key_info.action = REMOVEKEY;
+ msg->body.key_info.attr.wep.index = index;

- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "Request to remove WEP key\n");
- else
+ kfree(msg);
+ } else {
wait_for_completion(&hif_drv->comp_test_key_block);
+ }

return result;
}
@@ -2578,7 +2602,7 @@ int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
struct host_if_drv *hif_drv = vif->hif_drv;

if (!hif_drv) {
@@ -2587,19 +2611,21 @@ int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
return result;
}

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_key);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_key;
- msg.body.key_info.type = WEP;
- msg.body.key_info.action = DEFAULTKEY;
- msg.vif = vif;
- msg.body.key_info.attr.wep.index = index;
+ msg->body.key_info.type = WEP;
+ msg->body.key_info.action = DEFAULTKEY;
+ msg->body.key_info.attr.wep.index = index;

- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "Default key index\n");
- else
+ kfree(msg);
+ } else {
wait_for_completion(&hif_drv->comp_test_key_block);
+ }

return result;
}
@@ -2608,7 +2634,7 @@ int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
u8 index)
{
int result;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
struct host_if_drv *hif_drv = vif->hif_drv;

if (!hif_drv) {
@@ -2616,35 +2642,41 @@ int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
return -EFAULT;
}

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_key);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_key;
- msg.body.key_info.type = WEP;
- msg.body.key_info.action = ADDKEY;
- msg.vif = vif;
- msg.body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL);
- if (!msg.body.key_info.attr.wep.key)
- return -ENOMEM;
+ msg->body.key_info.type = WEP;
+ msg->body.key_info.action = ADDKEY;
+ msg->body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL);
+ if (!msg->body.key_info.attr.wep.key) {
+ result = -ENOMEM;
+ goto free_msg;
+ }

- msg.body.key_info.attr.wep.key_len = len;
- msg.body.key_info.attr.wep.index = index;
+ msg->body.key_info.attr.wep.key_len = len;
+ msg->body.key_info.attr.wep.index = index;

- result = wilc_enqueue_cmd(&msg);
- if (result) {
- netdev_err(vif->ndev, "STA - WEP Key\n");
- kfree(msg.body.key_info.attr.wep.key);
- return result;
- }
+ result = wilc_enqueue_cmd(msg);
+ if (result)
+ goto free_key;

wait_for_completion(&hif_drv->comp_test_key_block);
return 0;
+
+free_key:
+ kfree(msg->body.key_info.attr.wep.key);
+
+free_msg:
+ kfree(msg);
+ return result;
}

int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
u8 index, u8 mode, enum AUTHTYPE auth_type)
{
int result;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
struct host_if_drv *hif_drv = vif->hif_drv;

if (!hif_drv) {
@@ -2652,30 +2684,36 @@ int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
return -EFAULT;
}

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_key);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_key;
- msg.body.key_info.type = WEP;
- msg.body.key_info.action = ADDKEY_AP;
- msg.vif = vif;
- msg.body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL);
- if (!msg.body.key_info.attr.wep.key)
- return -ENOMEM;
+ msg->body.key_info.type = WEP;
+ msg->body.key_info.action = ADDKEY_AP;
+ msg->body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL);
+ if (!msg->body.key_info.attr.wep.key) {
+ result = -ENOMEM;
+ goto free_msg;
+ }

- msg.body.key_info.attr.wep.key_len = len;
- msg.body.key_info.attr.wep.index = index;
- msg.body.key_info.attr.wep.mode = mode;
- msg.body.key_info.attr.wep.auth_type = auth_type;
+ msg->body.key_info.attr.wep.key_len = len;
+ msg->body.key_info.attr.wep.index = index;
+ msg->body.key_info.attr.wep.mode = mode;
+ msg->body.key_info.attr.wep.auth_type = auth_type;

- result = wilc_enqueue_cmd(&msg);
- if (result) {
- netdev_err(vif->ndev, "AP - WEP Key\n");
- kfree(msg.body.key_info.attr.wep.key);
- return result;
- }
+ result = wilc_enqueue_cmd(msg);
+ if (result)
+ goto free_key;

wait_for_completion(&hif_drv->comp_test_key_block);
return 0;
+
+free_key:
+ kfree(msg->body.key_info.attr.wep.key);
+
+free_msg:
+ kfree(msg);
+ return result;
}

int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
@@ -2683,7 +2721,7 @@ int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
u8 mode, u8 cipher_mode, u8 index)
{
int result;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
struct host_if_drv *hif_drv = vif->hif_drv;
u8 key_len = ptk_key_len;

@@ -2698,43 +2736,51 @@ int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
if (tx_mic)
key_len += TX_MIC_KEY_LEN;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_key);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_key;
- msg.body.key_info.type = WPA_PTK;
+ msg->body.key_info.type = WPA_PTK;
if (mode == AP_MODE) {
- msg.body.key_info.action = ADDKEY_AP;
- msg.body.key_info.attr.wpa.index = index;
+ msg->body.key_info.action = ADDKEY_AP;
+ msg->body.key_info.attr.wpa.index = index;
}
if (mode == STATION_MODE)
- msg.body.key_info.action = ADDKEY;
+ msg->body.key_info.action = ADDKEY;

- msg.body.key_info.attr.wpa.key = kmemdup(ptk, ptk_key_len, GFP_KERNEL);
- if (!msg.body.key_info.attr.wpa.key)
- return -ENOMEM;
+ msg->body.key_info.attr.wpa.key = kmemdup(ptk, ptk_key_len, GFP_KERNEL);
+ if (!msg->body.key_info.attr.wpa.key) {
+ result = -ENOMEM;
+ goto free_msg;
+ }

if (rx_mic)
- memcpy(msg.body.key_info.attr.wpa.key + 16, rx_mic,
+ memcpy(msg->body.key_info.attr.wpa.key + 16, rx_mic,
RX_MIC_KEY_LEN);

if (tx_mic)
- memcpy(msg.body.key_info.attr.wpa.key + 24, tx_mic,
+ memcpy(msg->body.key_info.attr.wpa.key + 24, tx_mic,
TX_MIC_KEY_LEN);

- msg.body.key_info.attr.wpa.key_len = key_len;
- msg.body.key_info.attr.wpa.mac_addr = mac_addr;
- msg.body.key_info.attr.wpa.mode = cipher_mode;
- msg.vif = vif;
+ msg->body.key_info.attr.wpa.key_len = key_len;
+ msg->body.key_info.attr.wpa.mac_addr = mac_addr;
+ msg->body.key_info.attr.wpa.mode = cipher_mode;

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "PTK Key\n");
- kfree(msg.body.key_info.attr.wpa.key);
- return result;
+ goto free_key;
}

wait_for_completion(&hif_drv->comp_test_key_block);
return 0;
+
+free_key:
+ kfree(msg->body.key_info.attr.wpa.key);
+
+free_msg:
+ kfree(msg);
+ return result;
}

int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
@@ -2743,7 +2789,7 @@ int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
u8 cipher_mode)
{
int result;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
struct host_if_drv *hif_drv = vif->hif_drv;
u8 key_len = gtk_key_len;

@@ -2751,7 +2797,10 @@ int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
netdev_err(vif->ndev, "driver is null\n");
return -EFAULT;
}
- memset(&msg, 0, sizeof(struct host_if_msg));
+
+ msg = wilc_alloc_work(vif, handle_key);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

if (rx_mic)
key_len += RX_MIC_KEY_LEN;
@@ -2760,80 +2809,88 @@ int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
key_len += TX_MIC_KEY_LEN;

if (key_rsc) {
- msg.body.key_info.attr.wpa.seq = kmemdup(key_rsc,
- key_rsc_len,
- GFP_KERNEL);
- if (!msg.body.key_info.attr.wpa.seq)
- return -ENOMEM;
+ msg->body.key_info.attr.wpa.seq = kmemdup(key_rsc,
+ key_rsc_len,
+ GFP_KERNEL);
+ if (!msg->body.key_info.attr.wpa.seq) {
+ result = -ENOMEM;
+ goto free_msg;
+ }
}

- msg.fn = handle_key;
- msg.body.key_info.type = WPA_RX_GTK;
- msg.vif = vif;
+ msg->body.key_info.type = WPA_RX_GTK;

if (mode == AP_MODE) {
- msg.body.key_info.action = ADDKEY_AP;
- msg.body.key_info.attr.wpa.mode = cipher_mode;
+ msg->body.key_info.action = ADDKEY_AP;
+ msg->body.key_info.attr.wpa.mode = cipher_mode;
}
if (mode == STATION_MODE)
- msg.body.key_info.action = ADDKEY;
+ msg->body.key_info.action = ADDKEY;

- msg.body.key_info.attr.wpa.key = kmemdup(rx_gtk,
- key_len,
- GFP_KERNEL);
- if (!msg.body.key_info.attr.wpa.key) {
- kfree(msg.body.key_info.attr.wpa.seq);
- return -ENOMEM;
+ msg->body.key_info.attr.wpa.key = kmemdup(rx_gtk, key_len, GFP_KERNEL);
+ if (!msg->body.key_info.attr.wpa.key) {
+ result = -ENOMEM;
+ goto free_seq;
}

if (rx_mic)
- memcpy(msg.body.key_info.attr.wpa.key + 16, rx_mic,
+ memcpy(msg->body.key_info.attr.wpa.key + 16, rx_mic,
RX_MIC_KEY_LEN);

if (tx_mic)
- memcpy(msg.body.key_info.attr.wpa.key + 24, tx_mic,
+ memcpy(msg->body.key_info.attr.wpa.key + 24, tx_mic,
TX_MIC_KEY_LEN);

- msg.body.key_info.attr.wpa.index = index;
- msg.body.key_info.attr.wpa.key_len = key_len;
- msg.body.key_info.attr.wpa.seq_len = key_rsc_len;
+ msg->body.key_info.attr.wpa.index = index;
+ msg->body.key_info.attr.wpa.key_len = key_len;
+ msg->body.key_info.attr.wpa.seq_len = key_rsc_len;

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "RX GTK\n");
- kfree(msg.body.key_info.attr.wpa.seq);
- kfree(msg.body.key_info.attr.wpa.key);
- return result;
+ goto free_key;
}

wait_for_completion(&hif_drv->comp_test_key_block);
return 0;
+
+free_key:
+ kfree(msg->body.key_info.attr.wpa.key);
+
+free_seq:
+ kfree(msg->body.key_info.attr.wpa.seq);
+
+free_msg:
+ kfree(msg);
+ return result;
}

int wilc_set_pmkid_info(struct wilc_vif *vif,
struct host_if_pmkid_attr *pmkid)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
int i;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_key);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_key;
- msg.body.key_info.type = PMKSA;
- msg.body.key_info.action = ADDKEY;
- msg.vif = vif;
+ msg->body.key_info.type = PMKSA;
+ msg->body.key_info.action = ADDKEY;

for (i = 0; i < pmkid->numpmkid; i++) {
- memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].bssid,
+ memcpy(msg->body.key_info.attr.pmkid.pmkidlist[i].bssid,
&pmkid->pmkidlist[i].bssid, ETH_ALEN);
- memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].pmkid,
+ memcpy(msg->body.key_info.attr.pmkid.pmkidlist[i].pmkid,
&pmkid->pmkidlist[i].pmkid, PMKID_LEN);
}

- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "PMKID Info\n");
+ kfree(msg);
+ }

return result;
}
@@ -2841,17 +2898,18 @@ int wilc_set_pmkid_info(struct wilc_vif *vif,
int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_get_mac_address);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_get_mac_address;
- msg.body.get_mac_info.mac_addr = mac_addr;
- msg.vif = vif;
+ msg->body.get_mac_info.mac_addr = mac_addr;

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "Failed to send get mac address\n");
+ kfree(msg);
return -EFAULT;
}

@@ -2866,7 +2924,7 @@ int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ssid,
u8 channel, void *join_params)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
struct host_if_drv *hif_drv = vif->hif_drv;

if (!hif_drv || !connect_result) {
@@ -2879,56 +2937,75 @@ int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ssid,
return -EFAULT;
}

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_connect);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_connect;
- msg.body.con_info.security = security;
- msg.body.con_info.auth_type = auth_type;
- msg.body.con_info.ch = channel;
- msg.body.con_info.result = connect_result;
- msg.body.con_info.arg = user_arg;
- msg.body.con_info.params = join_params;
- msg.vif = vif;
+ msg->body.con_info.security = security;
+ msg->body.con_info.auth_type = auth_type;
+ msg->body.con_info.ch = channel;
+ msg->body.con_info.result = connect_result;
+ msg->body.con_info.arg = user_arg;
+ msg->body.con_info.params = join_params;

if (bssid) {
- msg.body.con_info.bssid = kmemdup(bssid, 6, GFP_KERNEL);
- if (!msg.body.con_info.bssid)
- return -ENOMEM;
+ msg->body.con_info.bssid = kmemdup(bssid, 6, GFP_KERNEL);
+ if (!msg->body.con_info.bssid) {
+ result = -ENOMEM;
+ goto free_msg;
+ }
}

if (ssid) {
- msg.body.con_info.ssid_len = ssid_len;
- msg.body.con_info.ssid = kmemdup(ssid, ssid_len, GFP_KERNEL);
- if (!msg.body.con_info.ssid)
- return -ENOMEM;
+ msg->body.con_info.ssid_len = ssid_len;
+ msg->body.con_info.ssid = kmemdup(ssid, ssid_len, GFP_KERNEL);
+ if (!msg->body.con_info.ssid) {
+ result = -ENOMEM;
+ goto free_bssid;
+ }
}

if (ies) {
- msg.body.con_info.ies_len = ies_len;
- msg.body.con_info.ies = kmemdup(ies, ies_len, GFP_KERNEL);
- if (!msg.body.con_info.ies)
- return -ENOMEM;
+ msg->body.con_info.ies_len = ies_len;
+ msg->body.con_info.ies = kmemdup(ies, ies_len, GFP_KERNEL);
+ if (!msg->body.con_info.ies) {
+ result = -ENOMEM;
+ goto free_ssid;
+ }
}
if (hif_drv->hif_state < HOST_IF_CONNECTING)
hif_drv->hif_state = HOST_IF_CONNECTING;

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "send message: Set join request\n");
- return -EFAULT;
+ goto free_ies;
}

hif_drv->connect_timer_vif = vif;
mod_timer(&hif_drv->connect_timer,
jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT));

+ return 0;
+
+free_ies:
+ kfree(msg->body.con_info.ies);
+
+free_ssid:
+ kfree(msg->body.con_info.ssid);
+
+free_bssid:
+ kfree(msg->body.con_info.bssid);
+
+free_msg:
+ kfree(msg);
return result;
}

int wilc_disconnect(struct wilc_vif *vif, u16 reason_code)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
struct host_if_drv *hif_drv = vif->hif_drv;

if (!hif_drv) {
@@ -2936,16 +3013,17 @@ int wilc_disconnect(struct wilc_vif *vif, u16 reason_code)
return -EFAULT;
}

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_disconnect);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_disconnect;
- msg.vif = vif;
-
- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "Failed to send message: disconnect\n");
- else
+ kfree(msg);
+ } else {
wait_for_completion(&hif_drv->comp_test_disconn_block);
+ }

return result;
}
@@ -2978,39 +3056,41 @@ static s32 host_int_get_assoc_res_info(struct wilc_vif *vif,
int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
{
int result;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
+
+ msg = wilc_alloc_work(vif, handle_set_channel);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- memset(&msg, 0, sizeof(struct host_if_msg));
- msg.fn = handle_set_channel;
- msg.body.channel_info.set_ch = channel;
- msg.vif = vif;
+ msg->body.channel_info.set_ch = channel;

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "wilc mq send fail\n");
- return -EINVAL;
+ kfree(msg);
}

- return 0;
+ return result;
}

int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
u8 ifc_id)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
+
+ msg = wilc_alloc_work(vif, handle_set_wfi_drv_handler);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- memset(&msg, 0, sizeof(struct host_if_msg));
- msg.fn = handle_set_wfi_drv_handler;
- msg.body.drv.handler = index;
- msg.body.drv.mode = mode;
- msg.body.drv.name = ifc_id;
- msg.vif = vif;
+ msg->body.drv.handler = index;
+ msg->body.drv.mode = mode;
+ msg->body.drv.name = ifc_id;

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "wilc mq send fail\n");
- result = -EINVAL;
+ kfree(msg);
}

return result;
@@ -3019,17 +3099,17 @@ int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;

- memset(&msg, 0, sizeof(struct host_if_msg));
- msg.fn = handle_set_operation_mode;
- msg.body.mode.mode = mode;
- msg.vif = vif;
+ msg = wilc_alloc_work(vif, handle_set_operation_mode);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- result = wilc_enqueue_cmd(&msg);
+ msg->body.mode.mode = mode;
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "wilc mq send fail\n");
- result = -EINVAL;
+ kfree(msg);
}

return result;
@@ -3039,7 +3119,7 @@ s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac,
u32 *out_val)
{
s32 result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
struct host_if_drv *hif_drv = vif->hif_drv;

if (!hif_drv) {
@@ -3047,17 +3127,19 @@ s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac,
return -EFAULT;
}

- memset(&msg, 0, sizeof(struct host_if_msg));
- memcpy(msg.body.mac_info.mac, mac, ETH_ALEN);
+ msg = wilc_alloc_work(vif, handle_get_inactive_time);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_get_inactive_time;
- msg.vif = vif;
+ memcpy(msg->body.mac_info.mac, mac, ETH_ALEN);

- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "Failed to send get host ch param\n");
- else
+ kfree(msg);
+ } else {
wait_for_completion(&hif_drv->comp_inactive_time);
+ }

*out_val = inactive_time;

@@ -3067,17 +3149,18 @@ s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac,
int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
struct host_if_drv *hif_drv = vif->hif_drv;

- memset(&msg, 0, sizeof(struct host_if_msg));
- msg.fn = handle_get_rssi;
- msg.vif = vif;
+ msg = wilc_alloc_work(vif, handle_get_rssi);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "Failed to send get host ch param\n");
- return -EFAULT;
+ kfree(msg);
+ return result;
}

wait_for_completion(&hif_drv->comp_get_rssi);
@@ -3095,17 +3178,19 @@ int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
+
+ msg = wilc_alloc_work(vif, handle_get_statistics);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- memset(&msg, 0, sizeof(struct host_if_msg));
- msg.fn = handle_get_statistics;
- msg.body.data = (char *)stats;
- msg.vif = vif;
+ msg->body.data = (char *)stats;

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "Failed to send get host channel\n");
- return -EFAULT;
+ kfree(msg);
+ return result;
}

if (stats != &vif->wilc->dummy_statistics)
@@ -3119,8 +3204,8 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
struct hidden_network *hidden_network)
{
int result = 0;
- struct host_if_msg msg;
- struct scan_attr *scan_info = &msg.body.scan_info;
+ struct host_if_msg *msg;
+ struct scan_attr *scan_info;
struct host_if_drv *hif_drv = vif->hif_drv;

if (!hif_drv || !scan_result) {
@@ -3128,16 +3213,17 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
return -EFAULT;
}

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_scan);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_scan;
+ scan_info = &msg->body.scan_info;

if (hidden_network) {
scan_info->hidden_network.net_info = hidden_network->net_info;
scan_info->hidden_network.n_ssids = hidden_network->n_ssids;
}

- msg.vif = vif;
scan_info->src = scan_source;
scan_info->type = scan_type;
scan_info->result = scan_result;
@@ -3147,44 +3233,63 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
scan_info->ch_freq_list = kmemdup(ch_freq_list,
ch_list_len,
GFP_KERNEL);
- if (!scan_info->ch_freq_list)
- return -ENOMEM;
+ if (!scan_info->ch_freq_list) {
+ result = -ENOMEM;
+ goto free_msg;
+ }

scan_info->ies_len = ies_len;
scan_info->ies = kmemdup(ies, ies_len, GFP_KERNEL);
- if (!scan_info->ies)
- return -ENOMEM;
+ if (!scan_info->ies) {
+ result = -ENOMEM;
+ goto free_freq_list;
+ }

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "Error in sending message queue\n");
- return -EINVAL;
+ goto free_ies;
}

hif_drv->scan_timer_vif = vif;
mod_timer(&hif_drv->scan_timer,
jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT));

+ return 0;
+
+free_ies:
+ kfree(scan_info->ies);
+
+free_freq_list:
+ kfree(scan_info->ch_freq_list);
+
+free_msg:
+ kfree(msg);
return result;
}

int wilc_hif_set_cfg(struct wilc_vif *vif,
struct cfg_param_attr *cfg_param)
{
- struct host_if_msg msg;
+ struct host_if_msg *msg;
struct host_if_drv *hif_drv = vif->hif_drv;
+ int result;

if (!hif_drv) {
netdev_err(vif->ndev, "hif_drv NULL\n");
return -EFAULT;
}

- memset(&msg, 0, sizeof(struct host_if_msg));
- msg.fn = handle_cfg_param;
- msg.body.cfg_info = *cfg_param;
- msg.vif = vif;
+ msg = wilc_alloc_work(vif, handle_cfg_param);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);
+
+ msg->body.cfg_info = *cfg_param;
+ result = wilc_enqueue_cmd(msg);
+ if (result)
+ kfree(msg);

- return wilc_enqueue_cmd(&msg);
+ return result;
}

static void get_periodic_rssi(struct timer_list *unused)
@@ -3278,7 +3383,6 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
int wilc_deinit(struct wilc_vif *vif)
{
int result = 0;
- struct host_if_msg msg;
struct host_if_drv *hif_drv = vif->hif_drv;

if (!hif_drv) {
@@ -3307,14 +3411,15 @@ int wilc_deinit(struct wilc_vif *vif)

hif_drv->hif_state = HOST_IF_IDLE;

- memset(&msg, 0, sizeof(struct host_if_msg));
-
if (clients_count == 1) {
- msg.fn = handle_hif_exit_work;
- msg.vif = vif;
+ struct host_if_msg *msg;

- result = wilc_enqueue_cmd(&msg);
- if (result != 0)
+ msg = wilc_alloc_work(vif, handle_hif_exit_work);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);
+
+ result = wilc_enqueue_cmd(msg);
+ if (result)
netdev_err(vif->ndev, "deinit : Error(%d)\n", result);
else
wait_for_completion(&hif_thread_comp);
@@ -3333,7 +3438,7 @@ int wilc_deinit(struct wilc_vif *vif)
void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
{
s32 result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
int id;
struct host_if_drv *hif_drv = NULL;
struct wilc_vif *vif;
@@ -3352,27 +3457,29 @@ void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
return;
}

- memset(&msg, 0, sizeof(struct host_if_msg));
-
- msg.fn = handle_rcvd_ntwrk_info;
- msg.vif = vif;
+ msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info);
+ if (IS_ERR(msg))
+ return;

- msg.body.net_info.len = length;
- msg.body.net_info.buffer = kmemdup(buffer, length, GFP_KERNEL);
- if (!msg.body.net_info.buffer)
+ msg->body.net_info.len = length;
+ msg->body.net_info.buffer = kmemdup(buffer, length, GFP_KERNEL);
+ if (!msg->body.net_info.buffer) {
+ kfree(msg);
return;
+ }

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "message parameters (%d)\n", result);
- kfree(msg.body.net_info.buffer);
+ kfree(msg->body.net_info.buffer);
+ kfree(msg);
}
}

void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
{
s32 result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
int id;
struct host_if_drv *hif_drv = NULL;
struct wilc_vif *vif;
@@ -3402,22 +3509,25 @@ void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
return;
}

- memset(&msg, 0, sizeof(struct host_if_msg));
-
- msg.fn = handle_rcvd_gnrl_async_info;
- msg.vif = vif;
+ msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info);
+ if (IS_ERR(msg)) {
+ mutex_unlock(&hif_deinit_lock);
+ return;
+ }

- msg.body.async_info.len = length;
- msg.body.async_info.buffer = kmemdup(buffer, length, GFP_KERNEL);
- if (!msg.body.async_info.buffer) {
+ msg->body.async_info.len = length;
+ msg->body.async_info.buffer = kmemdup(buffer, length, GFP_KERNEL);
+ if (!msg->body.async_info.buffer) {
+ kfree(msg);
mutex_unlock(&hif_deinit_lock);
return;
}

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "synchronous info (%d)\n", result);
- kfree(msg.body.async_info.buffer);
+ kfree(msg->body.async_info.buffer);
+ kfree(msg);
}

mutex_unlock(&hif_deinit_lock);
@@ -3426,7 +3536,6 @@ void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
{
s32 result = 0;
- struct host_if_msg msg;
int id;
struct host_if_drv *hif_drv = NULL;
struct wilc_vif *vif;
@@ -3444,14 +3553,17 @@ void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
return;

if (hif_drv->usr_scan_req.scan_result) {
- memset(&msg, 0, sizeof(struct host_if_msg));
+ struct host_if_msg *msg;

- msg.fn = handle_scan_complete;
- msg.vif = vif;
+ msg = wilc_alloc_work(vif, handle_scan_complete);
+ if (IS_ERR(msg))
+ return;

- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "complete param (%d)\n", result);
+ kfree(msg);
+ }
}
}

@@ -3462,22 +3574,24 @@ int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
void *user_arg)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_remain_on_chan_work);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_remain_on_chan_work;
- msg.body.remain_on_ch.ch = chan;
- msg.body.remain_on_ch.expired = expired;
- msg.body.remain_on_ch.ready = ready;
- msg.body.remain_on_ch.arg = user_arg;
- msg.body.remain_on_ch.duration = duration;
- msg.body.remain_on_ch.id = session_id;
- msg.vif = vif;
+ msg->body.remain_on_ch.ch = chan;
+ msg->body.remain_on_ch.expired = expired;
+ msg->body.remain_on_ch.ready = ready;
+ msg->body.remain_on_ch.arg = user_arg;
+ msg->body.remain_on_ch.duration = duration;
+ msg->body.remain_on_ch.id = session_id;

- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "wilc mq send fail\n");
+ kfree(msg);
+ }

return result;
}
@@ -3485,7 +3599,7 @@ int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;
struct host_if_drv *hif_drv = vif->hif_drv;

if (!hif_drv) {
@@ -3495,14 +3609,17 @@ int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id)

del_timer(&hif_drv->remain_on_ch_timer);

- memset(&msg, 0, sizeof(struct host_if_msg));
- msg.fn = handle_listen_state_expired;
- msg.vif = vif;
- msg.body.remain_on_ch.id = session_id;
+ msg = wilc_alloc_work(vif, handle_listen_state_expired);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- result = wilc_enqueue_cmd(&msg);
- if (result)
+ msg->body.remain_on_ch.id = session_id;
+
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "wilc mq send fail\n");
+ kfree(msg);
+ }

return result;
}
@@ -3510,30 +3627,32 @@ int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id)
int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_register_frame);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_register_frame;
switch (frame_type) {
case ACTION:
- msg.body.reg_frame.reg_id = ACTION_FRM_IDX;
+ msg->body.reg_frame.reg_id = ACTION_FRM_IDX;
break;

case PROBE_REQ:
- msg.body.reg_frame.reg_id = PROBE_REQ_IDX;
+ msg->body.reg_frame.reg_id = PROBE_REQ_IDX;
break;

default:
break;
}
- msg.body.reg_frame.frame_type = frame_type;
- msg.body.reg_frame.reg = reg;
- msg.vif = vif;
+ msg->body.reg_frame.frame_type = frame_type;
+ msg->body.reg_frame.reg = reg;

- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "wilc mq send fail\n");
+ kfree(msg);
+ }

return result;
}
@@ -3542,13 +3661,14 @@ int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
u32 head_len, u8 *head, u32 tail_len, u8 *tail)
{
int result = 0;
- struct host_if_msg msg;
- struct beacon_attr *beacon_info = &msg.body.beacon_info;
+ struct host_if_msg *msg;
+ struct beacon_attr *beacon_info;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_add_beacon);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_add_beacon;
- msg.vif = vif;
+ beacon_info = &msg->body.beacon_info;
beacon_info->interval = interval;
beacon_info->dtim_period = dtim_period;
beacon_info->head_len = head_len;
@@ -3569,15 +3689,15 @@ int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
beacon_info->tail = NULL;
}

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result)
netdev_err(vif->ndev, "wilc mq send fail\n");

error:
if (result) {
kfree(beacon_info->head);
-
kfree(beacon_info->tail);
+ kfree(msg);
}

return result;
@@ -3586,14 +3706,17 @@ int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
int wilc_del_beacon(struct wilc_vif *vif)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;

- msg.fn = handle_del_beacon;
- msg.vif = vif;
+ msg = wilc_alloc_work(vif, handle_del_beacon);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
+ kfree(msg);
+ }

return result;
}
@@ -3601,27 +3724,30 @@ int wilc_del_beacon(struct wilc_vif *vif)
int wilc_add_station(struct wilc_vif *vif, struct add_sta_param *sta_param)
{
int result = 0;
- struct host_if_msg msg;
- struct add_sta_param *add_sta_info = &msg.body.add_sta_info;
+ struct host_if_msg *msg;
+ struct add_sta_param *add_sta_info;

- memset(&msg, 0, sizeof(struct host_if_msg));
-
- msg.fn = handle_add_station;
- msg.vif = vif;
+ msg = wilc_alloc_work(vif, handle_add_station);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

+ add_sta_info = &msg->body.add_sta_info;
memcpy(add_sta_info, sta_param, sizeof(struct add_sta_param));
if (add_sta_info->rates_len > 0) {
add_sta_info->rates = kmemdup(sta_param->rates,
add_sta_info->rates_len,
GFP_KERNEL);
- if (!add_sta_info->rates)
+ if (!add_sta_info->rates) {
+ kfree(msg);
return -ENOMEM;
+ }
}

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
kfree(add_sta_info->rates);
+ kfree(msg);
}
return result;
}
@@ -3629,38 +3755,42 @@ int wilc_add_station(struct wilc_vif *vif, struct add_sta_param *sta_param)
int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
{
int result = 0;
- struct host_if_msg msg;
- struct del_sta *del_sta_info = &msg.body.del_sta_info;
+ struct host_if_msg *msg;
+ struct del_sta *del_sta_info;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_del_station);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_del_station;
- msg.vif = vif;
+ del_sta_info = &msg->body.del_sta_info;

if (!mac_addr)
eth_broadcast_addr(del_sta_info->mac_addr);
else
memcpy(del_sta_info->mac_addr, mac_addr, ETH_ALEN);

- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
+ kfree(msg);
+ }
return result;
}

int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
{
int result = 0;
- struct host_if_msg msg;
- struct del_all_sta *del_all_sta_info = &msg.body.del_all_sta_info;
+ struct host_if_msg *msg;
+ struct del_all_sta *del_all_sta_info;
u8 zero_addr[ETH_ALEN] = {0};
int i;
u8 assoc_sta = 0;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_del_all_sta);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_del_all_sta;
- msg.vif = vif;
+ del_all_sta_info = &msg->body.del_all_sta_info;

for (i = 0; i < MAX_NUM_STA; i++) {
if (memcmp(mac_addr[i], zero_addr, ETH_ALEN)) {
@@ -3669,16 +3799,20 @@ int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
assoc_sta++;
}
}
- if (!assoc_sta)
- return result;
+ if (!assoc_sta) {
+ kfree(msg);
+ return 0;
+ }

del_all_sta_info->assoc_sta = assoc_sta;
- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);

- if (result)
+ if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
- else
+ kfree(msg);
+ } else {
wait_for_completion(&hif_wait_response);
+ }

return result;
}
@@ -3687,27 +3821,30 @@ int wilc_edit_station(struct wilc_vif *vif,
struct add_sta_param *sta_param)
{
int result = 0;
- struct host_if_msg msg;
- struct add_sta_param *add_sta_info = &msg.body.add_sta_info;
-
- memset(&msg, 0, sizeof(struct host_if_msg));
+ struct host_if_msg *msg;
+ struct add_sta_param *add_sta_info;

- msg.fn = handle_edit_station;
- msg.vif = vif;
+ msg = wilc_alloc_work(vif, handle_edit_station);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- memcpy(add_sta_info, sta_param, sizeof(struct add_sta_param));
+ add_sta_info = &msg->body.add_sta_info;
+ memcpy(add_sta_info, sta_param, sizeof(*add_sta_info));
if (add_sta_info->rates_len > 0) {
add_sta_info->rates = kmemdup(sta_param->rates,
add_sta_info->rates_len,
GFP_KERNEL);
- if (!add_sta_info->rates)
+ if (!add_sta_info->rates) {
+ kfree(msg);
return -ENOMEM;
+ }
}

- result = wilc_enqueue_cmd(&msg);
+ result = wilc_enqueue_cmd(msg);
if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
kfree(add_sta_info->rates);
+ kfree(msg);
}

return result;
@@ -3716,23 +3853,23 @@ int wilc_edit_station(struct wilc_vif *vif,
int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
{
int result = 0;
- struct host_if_msg msg;
- struct power_mgmt_param *pwr_mgmt_info = &msg.body.pwr_mgmt_info;
+ struct host_if_msg *msg;

if (wilc_wlan_get_num_conn_ifcs(vif->wilc) == 2 && enabled)
return 0;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_power_management);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_power_management;
- msg.vif = vif;
+ msg->body.pwr_mgmt_info.enabled = enabled;
+ msg->body.pwr_mgmt_info.timeout = timeout;

- pwr_mgmt_info->enabled = enabled;
- pwr_mgmt_info->timeout = timeout;
-
- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
+ kfree(msg);
+ }
return result;
}

@@ -3740,20 +3877,20 @@ int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled,
u32 count)
{
int result = 0;
- struct host_if_msg msg;
- struct set_multicast *multicast_filter_param = &msg.body.multicast_info;
-
- memset(&msg, 0, sizeof(struct host_if_msg));
+ struct host_if_msg *msg;

- msg.fn = handle_set_mcast_filter;
- msg.vif = vif;
+ msg = wilc_alloc_work(vif, handle_set_mcast_filter);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- multicast_filter_param->enabled = enabled;
- multicast_filter_param->cnt = count;
+ msg->body.multicast_info.enabled = enabled;
+ msg->body.multicast_info.cnt = count;

- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
+ kfree(msg);
+ }
return result;
}

@@ -3925,19 +4062,20 @@ static void *host_int_parse_join_bss_param(struct network_info *info)
int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_set_ip_address);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_set_ip_address;
+ msg->body.ip_info.ip_addr = ip_addr;
+ msg->body.ip_info.idx = idx;

- msg.body.ip_info.ip_addr = ip_addr;
- msg.vif = vif;
- msg.body.ip_info.idx = idx;
-
- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
+ kfree(msg);
+ }

return result;
}
@@ -3945,19 +4083,20 @@ int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
{
int result = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_get_ip_address);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_get_ip_address;
+ msg->body.ip_info.ip_addr = ip_addr;
+ msg->body.ip_info.idx = idx;

- msg.body.ip_info.ip_addr = ip_addr;
- msg.vif = vif;
- msg.body.ip_info.idx = idx;
-
- result = wilc_enqueue_cmd(&msg);
- if (result)
+ result = wilc_enqueue_cmd(msg);
+ if (result) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
+ kfree(msg);
+ }

return result;
}
@@ -3965,17 +4104,19 @@ static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
{
int ret = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_set_tx_pwr);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_set_tx_pwr;
- msg.body.tx_power.tx_pwr = tx_power;
- msg.vif = vif;
+ msg->body.tx_power.tx_pwr = tx_power;

- ret = wilc_enqueue_cmd(&msg);
- if (ret)
+ ret = wilc_enqueue_cmd(msg);
+ if (ret) {
netdev_err(vif->ndev, "wilc_mq_send fail\n");
+ kfree(msg);
+ }

return ret;
}
@@ -3983,19 +4124,23 @@ int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
{
int ret = 0;
- struct host_if_msg msg;
+ struct host_if_msg *msg;

- memset(&msg, 0, sizeof(struct host_if_msg));
+ msg = wilc_alloc_work(vif, handle_get_tx_pwr);
+ if (IS_ERR(msg))
+ return PTR_ERR(msg);

- msg.fn = handle_get_tx_pwr;
- msg.vif = vif;
-
- ret = wilc_enqueue_cmd(&msg);
- if (ret)
+ ret = wilc_enqueue_cmd(msg);
+ if (ret) {
netdev_err(vif->ndev, "Failed to get TX PWR\n");
+ kfree(msg);
+ return ret;
+ }

wait_for_completion(&hif_wait_response);
- *tx_power = msg.body.tx_power.tx_pwr;

+ *tx_power = msg->body.tx_power.tx_pwr;
+ /* free 'msg' after copying data */
+ kfree(msg);
return ret;
}
--
2.7.4

2018-06-26 06:07:17

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 01/12] staging: wilc1000: remove host_if_work() to handle TODO list issue

Remove multiplexing of command at host_if_work().
Make use of function pointer instead of command ID to track individual
work_struct separately.

Modified the handler function to take work_struct pointer as argument
and its return type is changes to void. Now prototype of 'handle_'
function is same work_struct i.e. 'void (*fun)(struct struct *)' to
register with work_queue.
Removed host_if_work() because its not required now.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 574 +++++++++++++++---------------
1 file changed, 278 insertions(+), 296 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 0aaae33..4f6008e 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -184,6 +184,7 @@ struct host_if_msg {
union message_body body;
struct wilc_vif *vif;
struct work_struct work;
+ void (*fn)(struct work_struct *ws);
};

struct join_bss_param {
@@ -239,7 +240,6 @@ static u32 clients_count;
static void *host_int_parse_join_bss_param(struct network_info *info);
static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
static s32 handle_scan_done(struct wilc_vif *vif, enum scan_event evt);
-static void host_if_work(struct work_struct *work);

/*!
* @author syounan
@@ -255,7 +255,7 @@ static int wilc_enqueue_cmd(struct host_if_msg *msg)
if (!new_msg)
return -ENOMEM;

- INIT_WORK(&new_msg->work, host_if_work);
+ INIT_WORK(&new_msg->work, msg->fn);
queue_work(hif_workqueue, &new_msg->work);
return 0;
}
@@ -284,9 +284,11 @@ static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
return wilc->vif[index];
}

-static void handle_set_channel(struct wilc_vif *vif,
- struct channel_attr *hif_set_ch)
+static void handle_set_channel(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct channel_attr *hif_set_ch = &msg->body.channel_info;
int ret = 0;
struct wid wid;

@@ -300,27 +302,28 @@ static void handle_set_channel(struct wilc_vif *vif,

if (ret)
netdev_err(vif->ndev, "Failed to set channel\n");
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static int handle_set_wfi_drv_handler(struct wilc_vif *vif,
- struct drv_handler *hif_drv_handler)
+static void handle_set_wfi_drv_handler(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct drv_handler *hif_drv_handler = &msg->body.drv;
int ret = 0;
struct wid wid;
u8 *currbyte, *buffer;
struct host_if_drv *hif_drv = NULL;

- if (!vif->hif_drv)
- return -EINVAL;
-
- if (!hif_drv_handler)
- return -EINVAL;
+ if (!vif->hif_drv || !hif_drv_handler)
+ goto free_msg;

hif_drv = vif->hif_drv;

buffer = kzalloc(DRV_HANDLER_SIZE, GFP_KERNEL);
if (!buffer)
- return -ENOMEM;
+ goto free_msg;

currbyte = buffer;
*currbyte = hif_drv->driver_handler_id & DRV_HANDLER_MASK;
@@ -340,20 +343,22 @@ static int handle_set_wfi_drv_handler(struct wilc_vif *vif,

ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
hif_drv->driver_handler_id);
- if (ret) {
+ if (ret)
netdev_err(vif->ndev, "Failed to set driver handler\n");
- complete(&hif_driver_comp);
- kfree(buffer);
- return ret;
- }
+
complete(&hif_driver_comp);
kfree(buffer);
- return 0;
+
+free_msg:
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_set_operation_mode(struct wilc_vif *vif,
- struct op_mode *hif_op_mode)
+static void handle_set_operation_mode(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct op_mode *hif_op_mode = &msg->body.mode;
int ret = 0;
struct wid wid;

@@ -370,10 +375,16 @@ static void handle_set_operation_mode(struct wilc_vif *vif,

if (ret)
netdev_err(vif->ndev, "Failed to set driver handler\n");
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_set_ip_address(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
+static void handle_set_ip_address(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ u8 *ip_addr = msg->body.ip_info.ip_addr;
+ u8 idx = msg->body.ip_info.idx;
int ret = 0;
struct wid wid;
char firmware_ip_addr[4] = {0};
@@ -395,10 +406,15 @@ static void handle_set_ip_address(struct wilc_vif *vif, u8 *ip_addr, u8 idx)

if (ret)
netdev_err(vif->ndev, "Failed to set IP address\n");
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_get_ip_address(struct wilc_vif *vif, u8 idx)
+static void handle_get_ip_address(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ u8 idx = msg->body.ip_info.idx;
int ret = 0;
struct wid wid;

@@ -419,11 +435,15 @@ static void handle_get_ip_address(struct wilc_vif *vif, u8 idx)

if (ret)
netdev_err(vif->ndev, "Failed to get IP address\n");
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_get_mac_address(struct wilc_vif *vif,
- struct get_mac_addr *get_mac_addr)
+static void handle_get_mac_address(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct get_mac_addr *get_mac_addr = &msg->body.get_mac_info;
int ret = 0;
struct wid wid;

@@ -438,10 +458,15 @@ static void handle_get_mac_address(struct wilc_vif *vif,
if (ret)
netdev_err(vif->ndev, "Failed to get mac address\n");
complete(&hif_wait_response);
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_cfg_param(struct wilc_vif *vif, struct cfg_param_attr *param)
+static void handle_cfg_param(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct cfg_param_attr *param = &msg->body.cfg_info;
int ret = 0;
struct wid wid_list[32];
struct host_if_drv *hif_drv = vif->hif_drv;
@@ -730,10 +755,15 @@ static void handle_cfg_param(struct wilc_vif *vif, struct cfg_param_attr *param)

unlock:
mutex_unlock(&hif_drv->cfg_values_lock);
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static s32 handle_scan(struct wilc_vif *vif, struct scan_attr *scan_info)
+static void handle_scan(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct scan_attr *scan_info = &msg->body.scan_info;
s32 result = 0;
struct wid wid_list[5];
u32 index = 0;
@@ -843,7 +873,8 @@ static s32 handle_scan(struct wilc_vif *vif, struct scan_attr *scan_info)

kfree(hdn_ntwk_wid_val);

- return result;
+ kfree(msg);
+ complete(&hif_thread_comp);
}

static s32 handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
@@ -885,9 +916,11 @@ static s32 handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
}

u8 wilc_connected_ssid[6] = {0};
-static s32 handle_connect(struct wilc_vif *vif,
- struct connect_attr *conn_attr)
+static void handle_connect(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct connect_attr *conn_attr = &msg->body.con_info;
s32 result = 0;
struct wid wid_list[8];
u32 wid_cnt = 0, dummyval = 0;
@@ -895,10 +928,18 @@ static s32 handle_connect(struct wilc_vif *vif,
struct join_bss_param *bss_param;
struct host_if_drv *hif_drv = vif->hif_drv;

+ if (msg->vif->hif_drv->usr_scan_req.scan_result) {
+ result = wilc_enqueue_cmd(msg);
+ if (result)
+ goto error;
+ usleep_range(2 * 1000, 2 * 1000);
+ kfree(msg);
+ return;
+ }
+
if (memcmp(conn_attr->bssid, wilc_connected_ssid, ETH_ALEN) == 0) {
- result = 0;
netdev_err(vif->ndev, "Discard connect request\n");
- return result;
+ goto error;
}

bss_param = conn_attr->params;
@@ -1138,11 +1179,14 @@ static s32 handle_connect(struct wilc_vif *vif,
conn_attr->ies = NULL;

kfree(cur_byte);
- return result;
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static s32 handle_connect_timeout(struct wilc_vif *vif)
+static void handle_connect_timeout(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
s32 result = 0;
struct connect_info info;
struct wid wid;
@@ -1151,7 +1195,7 @@ static s32 handle_connect_timeout(struct wilc_vif *vif)

if (!hif_drv) {
netdev_err(vif->ndev, "Driver handler is NULL\n");
- return result;
+ goto out;
}

hif_drv->hif_state = HOST_IF_IDLE;
@@ -1170,7 +1214,7 @@ static s32 handle_connect_timeout(struct wilc_vif *vif)
hif_drv->usr_conn_req.ies_len,
GFP_KERNEL);
if (!info.req_ies)
- return -ENOMEM;
+ goto out;
}

hif_drv->usr_conn_req.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
@@ -1206,15 +1250,18 @@ static s32 handle_connect_timeout(struct wilc_vif *vif)

eth_zero_addr(wilc_connected_ssid);

- return result;
+out:
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static s32 handle_rcvd_ntwrk_info(struct wilc_vif *vif,
- struct rcvd_net_info *rcvd_info)
+static void handle_rcvd_ntwrk_info(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct rcvd_net_info *rcvd_info = &msg->body.net_info;
u32 i;
bool found;
- s32 result = 0;
struct network_info *info = NULL;
void *params = NULL;
struct host_if_drv *hif_drv = vif->hif_drv;
@@ -1228,7 +1275,6 @@ static s32 handle_rcvd_ntwrk_info(struct wilc_vif *vif,
wilc_parse_network_info(rcvd_info->buffer, &info);
if (!info || !scan_req->scan_result) {
netdev_err(vif->ndev, "driver is null\n");
- result = -EINVAL;
goto done;
}

@@ -1274,7 +1320,8 @@ static s32 handle_rcvd_ntwrk_info(struct wilc_vif *vif,
kfree(info);
}

- return result;
+ kfree(msg);
+ complete(&hif_thread_comp);
}

static s32 host_int_get_assoc_res_info(struct wilc_vif *vif,
@@ -1411,24 +1458,23 @@ static inline void host_int_handle_disconnect(struct wilc_vif *vif)
hif_drv->hif_state = HOST_IF_IDLE;
}

-static s32 handle_rcvd_gnrl_async_info(struct wilc_vif *vif,
- struct rcvd_async_info *rcvd_info)
+static void handle_rcvd_gnrl_async_info(struct work_struct *work)
{
- s32 result = 0;
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct rcvd_async_info *rcvd_info = &msg->body.async_info;
u8 msg_type = 0;
u8 mac_status;
struct host_if_drv *hif_drv = vif->hif_drv;

if (!rcvd_info->buffer) {
netdev_err(vif->ndev, "Received buffer is NULL\n");
- return -EINVAL;
+ goto free_msg;
}

if (!hif_drv) {
netdev_err(vif->ndev, "Driver handler is NULL\n");
- kfree(rcvd_info->buffer);
- rcvd_info->buffer = NULL;
- return -ENODEV;
+ goto free_rcvd_info;
}

if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP ||
@@ -1436,18 +1482,14 @@ static s32 handle_rcvd_gnrl_async_info(struct wilc_vif *vif,
hif_drv->usr_scan_req.scan_result) {
if (!hif_drv->usr_conn_req.conn_result) {
netdev_err(vif->ndev, "driver is null\n");
- kfree(rcvd_info->buffer);
- rcvd_info->buffer = NULL;
- return -EINVAL;
+ goto free_rcvd_info;
}

msg_type = rcvd_info->buffer[0];

if ('I' != msg_type) {
netdev_err(vif->ndev, "Received Message incorrect.\n");
- kfree(rcvd_info->buffer);
- rcvd_info->buffer = NULL;
- return -EFAULT;
+ goto free_rcvd_info;
}

mac_status = rcvd_info->buffer[7];
@@ -1464,10 +1506,13 @@ static s32 handle_rcvd_gnrl_async_info(struct wilc_vif *vif,
}
}

+free_rcvd_info:
kfree(rcvd_info->buffer);
rcvd_info->buffer = NULL;

- return result;
+free_msg:
+ kfree(msg);
+ complete(&hif_thread_comp);
}

static int wilc_pmksa_key_copy(struct wilc_vif *vif, struct key_attr *hif_key)
@@ -1504,8 +1549,11 @@ static int wilc_pmksa_key_copy(struct wilc_vif *vif, struct key_attr *hif_key)
return ret;
}

-static int handle_key(struct wilc_vif *vif, struct key_attr *hif_key)
+static void handle_key(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct key_attr *hif_key = &msg->body.key_info;
int result = 0;
struct wid wid;
struct wid wid_list[5];
@@ -1726,11 +1774,14 @@ static int handle_key(struct wilc_vif *vif, struct key_attr *hif_key)
if (result)
netdev_err(vif->ndev, "Failed to send key config packet\n");

- return result;
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_disconnect(struct wilc_vif *vif)
+static void handle_disconnect(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
struct wid wid;
struct host_if_drv *hif_drv = vif->hif_drv;
struct disconnect_info disconn_info;
@@ -1798,6 +1849,8 @@ static void handle_disconnect(struct wilc_vif *vif)
out:

complete(&hif_drv->comp_test_disconn_block);
+ kfree(msg);
+ complete(&hif_thread_comp);
}

void wilc_resolve_disconnect_aberration(struct wilc_vif *vif)
@@ -1809,8 +1862,10 @@ void wilc_resolve_disconnect_aberration(struct wilc_vif *vif)
wilc_disconnect(vif, 1);
}

-static void handle_get_rssi(struct wilc_vif *vif)
+static void handle_get_rssi(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
s32 result = 0;
struct wid wid;

@@ -1821,19 +1876,21 @@ static void handle_get_rssi(struct wilc_vif *vif)

result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
wilc_get_vif_idx(vif));
- if (result) {
+ if (result)
netdev_err(vif->ndev, "Failed to get RSSI value\n");
- result = -EFAULT;
- }

complete(&vif->hif_drv->comp_get_rssi);
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static s32 handle_get_statistics(struct wilc_vif *vif,
- struct rf_info *stats)
+static void handle_get_statistics(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
struct wid wid_list[5];
u32 wid_cnt = 0, result = 0;
+ struct rf_info *stats = (struct rf_info *)msg->body.data;

wid_list[wid_cnt].id = WID_LINKSPEED;
wid_list[wid_cnt].type = WID_CHAR;
@@ -1880,12 +1937,15 @@ static s32 handle_get_statistics(struct wilc_vif *vif,

if (stats != &vif->wilc->dummy_statistics)
complete(&hif_wait_response);
- return 0;
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static s32 handle_get_inactive_time(struct wilc_vif *vif,
- struct sta_inactive_t *hif_sta_inactive)
+static void handle_get_inactive_time(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct sta_inactive_t *hif_sta_inactive = &msg->body.mac_info;
s32 result = 0;
struct wid wid;
struct host_if_drv *hif_drv = vif->hif_drv;
@@ -1895,7 +1955,7 @@ static s32 handle_get_inactive_time(struct wilc_vif *vif,
wid.size = ETH_ALEN;
wid.val = kmalloc(wid.size, GFP_KERNEL);
if (!wid.val)
- return -ENOMEM;
+ goto out;

ether_addr_copy(wid.val, hif_sta_inactive->mac);

@@ -1905,7 +1965,7 @@ static s32 handle_get_inactive_time(struct wilc_vif *vif,

if (result) {
netdev_err(vif->ndev, "Failed to SET inactive time\n");
- return -EFAULT;
+ goto out;
}

wid.id = (u16)WID_GET_INACTIVE_TIME;
@@ -1916,18 +1976,21 @@ static s32 handle_get_inactive_time(struct wilc_vif *vif,
result = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
wilc_get_vif_idx(vif));

- if (result) {
+ if (result)
netdev_err(vif->ndev, "Failed to get inactive time\n");
- return -EFAULT;
- }

+out:
complete(&hif_drv->comp_inactive_time);

- return result;
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_add_beacon(struct wilc_vif *vif, struct beacon_attr *param)
+static void handle_add_beacon(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct beacon_attr *param = &msg->body.beacon_info;
s32 result = 0;
struct wid wid;
u8 *cur_byte;
@@ -1976,10 +2039,14 @@ static void handle_add_beacon(struct wilc_vif *vif, struct beacon_attr *param)
kfree(wid.val);
kfree(param->head);
kfree(param->tail);
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_del_beacon(struct wilc_vif *vif)
+static void handle_del_beacon(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
s32 result = 0;
struct wid wid;
u8 del_beacon = 0;
@@ -1993,6 +2060,8 @@ static void handle_del_beacon(struct wilc_vif *vif)
wilc_get_vif_idx(vif));
if (result)
netdev_err(vif->ndev, "Failed to send delete beacon\n");
+ kfree(msg);
+ complete(&hif_thread_comp);
}

static u32 wilc_hif_pack_sta_param(u8 *buff, struct add_sta_param *param)
@@ -2025,9 +2094,11 @@ static u32 wilc_hif_pack_sta_param(u8 *buff, struct add_sta_param *param)
return cur_byte - buff;
}

-static void handle_add_station(struct wilc_vif *vif,
- struct add_sta_param *param)
+static void handle_add_station(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct add_sta_param *param = &msg->body.add_sta_info;
s32 result = 0;
struct wid wid;
u8 *cur_byte;
@@ -2051,11 +2122,15 @@ static void handle_add_station(struct wilc_vif *vif,
error:
kfree(param->rates);
kfree(wid.val);
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_del_all_sta(struct wilc_vif *vif,
- struct del_all_sta *param)
+static void handle_del_all_sta(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct del_all_sta *param = &msg->body.del_all_sta_info;
s32 result = 0;
struct wid wid;
u8 *curr_byte;
@@ -2092,10 +2167,15 @@ static void handle_del_all_sta(struct wilc_vif *vif,
kfree(wid.val);

complete(&hif_wait_response);
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_del_station(struct wilc_vif *vif, struct del_sta *param)
+static void handle_del_station(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct del_sta *param = &msg->body.del_sta_info;
s32 result = 0;
struct wid wid;

@@ -2116,11 +2196,15 @@ static void handle_del_station(struct wilc_vif *vif, struct del_sta *param)

error:
kfree(wid.val);
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_edit_station(struct wilc_vif *vif,
- struct add_sta_param *param)
+static void handle_edit_station(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct add_sta_param *param = &msg->body.edit_sta_info;
s32 result = 0;
struct wid wid;
u8 *cur_byte;
@@ -2144,6 +2228,8 @@ static void handle_edit_station(struct wilc_vif *vif,
error:
kfree(param->rates);
kfree(wid.val);
+ kfree(msg);
+ complete(&hif_thread_comp);
}

static int handle_remain_on_chan(struct wilc_vif *vif,
@@ -2213,9 +2299,11 @@ static int handle_remain_on_chan(struct wilc_vif *vif,
return result;
}

-static int handle_register_frame(struct wilc_vif *vif,
- struct reg_frame *hif_reg_frame)
+static void handle_register_frame(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct reg_frame *hif_reg_frame = &msg->body.reg_frame;
s32 result = 0;
struct wid wid;
u8 *cur_byte;
@@ -2224,7 +2312,7 @@ static int handle_register_frame(struct wilc_vif *vif,
wid.type = WID_STR;
wid.val = kmalloc(sizeof(u16) + 2, GFP_KERNEL);
if (!wid.val)
- return -ENOMEM;
+ goto out;

cur_byte = wid.val;

@@ -2237,17 +2325,19 @@ static int handle_register_frame(struct wilc_vif *vif,
result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
wilc_get_vif_idx(vif));
kfree(wid.val);
- if (result) {
+ if (result)
netdev_err(vif->ndev, "Failed to frame register\n");
- result = -EINVAL;
- }

- return result;
+out:
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static u32 handle_listen_state_expired(struct wilc_vif *vif,
- struct remain_ch *hif_remain_ch)
+static void handle_listen_state_expired(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct remain_ch *hif_remain_ch = &msg->body.remain_on_ch;
u8 remain_on_chan_flag;
struct wid wid;
s32 result = 0;
@@ -2261,7 +2351,7 @@ static u32 handle_listen_state_expired(struct wilc_vif *vif,
wid.val = kmalloc(wid.size, GFP_KERNEL);

if (!wid.val)
- return -ENOMEM;
+ goto free_msg;

wid.val[0] = remain_on_chan_flag;
wid.val[1] = FALSE_FRMWR_CHANNEL;
@@ -2271,7 +2361,7 @@ static u32 handle_listen_state_expired(struct wilc_vif *vif,
kfree(wid.val);
if (result != 0) {
netdev_err(vif->ndev, "Failed to set remain channel\n");
- return result;
+ goto free_msg;
}

if (hif_drv->remain_on_ch.expired) {
@@ -2281,10 +2371,11 @@ static u32 handle_listen_state_expired(struct wilc_vif *vif,
p2p_listen_state = 0;
} else {
netdev_dbg(vif->ndev, "Not in listen state\n");
- result = -EFAULT;
}

- return result;
+free_msg:
+ kfree(msg);
+ complete(&hif_thread_comp);
}

static void listen_timer_cb(struct timer_list *t)
@@ -2298,7 +2389,7 @@ static void listen_timer_cb(struct timer_list *t)
del_timer(&vif->hif_drv->remain_on_ch_timer);

memset(&msg, 0, sizeof(struct host_if_msg));
- msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
+ msg.fn = handle_listen_state_expired;
msg.vif = vif;
msg.body.remain_on_ch.id = vif->hif_drv->remain_on_ch.id;

@@ -2307,9 +2398,11 @@ static void listen_timer_cb(struct timer_list *t)
netdev_err(vif->ndev, "wilc_mq_send fail\n");
}

-static void handle_power_management(struct wilc_vif *vif,
- struct power_mgmt_param *pm_param)
+static void handle_power_management(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct power_mgmt_param *pm_param = &msg->body.pwr_mgmt_info;
s32 result = 0;
struct wid wid;
s8 power_mode;
@@ -2328,11 +2421,15 @@ static void handle_power_management(struct wilc_vif *vif,
wilc_get_vif_idx(vif));
if (result)
netdev_err(vif->ndev, "Failed to send power management\n");
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_set_mcast_filter(struct wilc_vif *vif,
- struct set_multicast *hif_set_mc)
+static void handle_set_mcast_filter(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ struct set_multicast *hif_set_mc = &msg->body.multicast_info;
s32 result = 0;
struct wid wid;
u8 *cur_byte;
@@ -2366,10 +2463,15 @@ static void handle_set_mcast_filter(struct wilc_vif *vif,

error:
kfree(wid.val);
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_set_tx_pwr(struct wilc_vif *vif, u8 tx_pwr)
+static void handle_set_tx_pwr(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ u8 tx_pwr = msg->body.tx_power.tx_pwr;
int ret;
struct wid wid;

@@ -2382,10 +2484,15 @@ static void handle_set_tx_pwr(struct wilc_vif *vif, u8 tx_pwr)
wilc_get_vif_idx(vif));
if (ret)
netdev_err(vif->ndev, "Failed to set TX PWR\n");
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void handle_get_tx_pwr(struct wilc_vif *vif, u8 *tx_pwr)
+static void handle_get_tx_pwr(struct work_struct *work)
{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc_vif *vif = msg->vif;
+ u8 *tx_pwr = &msg->body.tx_power.tx_pwr;
int ret = 0;
struct wid wid;

@@ -2400,174 +2507,50 @@ static void handle_get_tx_pwr(struct wilc_vif *vif, u8 *tx_pwr)
netdev_err(vif->ndev, "Failed to get TX PWR\n");

complete(&hif_wait_response);
+ kfree(msg);
+ complete(&hif_thread_comp);
}

-static void host_if_work(struct work_struct *work)
+static void handle_scan_timer(struct work_struct *work)
{
- struct host_if_msg *msg;
- struct wilc *wilc;
- int ret = 0;
-
- msg = container_of(work, struct host_if_msg, work);
- wilc = msg->vif->wilc;
-
- if (msg->id == HOST_IF_MSG_CONNECT &&
- msg->vif->hif_drv->usr_scan_req.scan_result) {
- wilc_enqueue_cmd(msg);
- usleep_range(2 * 1000, 2 * 1000);
- goto free_msg;
- }
- switch (msg->id) {
- case HOST_IF_MSG_SCAN:
- handle_scan(msg->vif, &msg->body.scan_info);
- break;
-
- case HOST_IF_MSG_CONNECT:
- handle_connect(msg->vif, &msg->body.con_info);
- break;
-
- case HOST_IF_MSG_RCVD_NTWRK_INFO:
- handle_rcvd_ntwrk_info(msg->vif, &msg->body.net_info);
- break;
-
- case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO:
- handle_rcvd_gnrl_async_info(msg->vif,
- &msg->body.async_info);
- break;
-
- case HOST_IF_MSG_KEY:
- handle_key(msg->vif, &msg->body.key_info);
- break;
-
- case HOST_IF_MSG_CFG_PARAMS:
- handle_cfg_param(msg->vif, &msg->body.cfg_info);
- break;
-
- case HOST_IF_MSG_SET_CHANNEL:
- handle_set_channel(msg->vif, &msg->body.channel_info);
- break;
-
- case HOST_IF_MSG_DISCONNECT:
- handle_disconnect(msg->vif);
- break;
-
- case HOST_IF_MSG_RCVD_SCAN_COMPLETE:
- del_timer(&msg->vif->hif_drv->scan_timer);
-
- if (!wilc_wlan_get_num_conn_ifcs(wilc))
- wilc_chip_sleep_manually(wilc);
-
- handle_scan_done(msg->vif, SCAN_EVENT_DONE);
-
- if (msg->vif->hif_drv->remain_on_ch_pending)
- handle_remain_on_chan(msg->vif,
- &msg->body.remain_on_ch);
-
- break;
-
- case HOST_IF_MSG_GET_RSSI:
- handle_get_rssi(msg->vif);
- break;
-
- case HOST_IF_MSG_GET_STATISTICS:
- handle_get_statistics(msg->vif,
- (struct rf_info *)msg->body.data);
- break;
-
- case HOST_IF_MSG_ADD_BEACON:
- handle_add_beacon(msg->vif, &msg->body.beacon_info);
- break;
-
- case HOST_IF_MSG_DEL_BEACON:
- handle_del_beacon(msg->vif);
- break;
-
- case HOST_IF_MSG_ADD_STATION:
- handle_add_station(msg->vif, &msg->body.add_sta_info);
- break;
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);

- case HOST_IF_MSG_DEL_STATION:
- handle_del_station(msg->vif, &msg->body.del_sta_info);
- break;
-
- case HOST_IF_MSG_EDIT_STATION:
- handle_edit_station(msg->vif, &msg->body.edit_sta_info);
- break;
-
- case HOST_IF_MSG_GET_INACTIVETIME:
- handle_get_inactive_time(msg->vif, &msg->body.mac_info);
- break;
+ handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
+ kfree(msg);
+ complete(&hif_thread_comp);
+}

- case HOST_IF_MSG_SCAN_TIMER_FIRED:
- handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
- break;
+static void handle_remain_on_chan_work(struct work_struct *work)
+{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);

- case HOST_IF_MSG_CONNECT_TIMER_FIRED:
- handle_connect_timeout(msg->vif);
- break;
+ handle_remain_on_chan(msg->vif, &msg->body.remain_on_ch);
+ kfree(msg);
+ complete(&hif_thread_comp);
+}

- case HOST_IF_MSG_POWER_MGMT:
- handle_power_management(msg->vif,
- &msg->body.pwr_mgmt_info);
- break;
+static void handle_hif_exit_work(struct work_struct *work)
+{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);

- case HOST_IF_MSG_SET_WFIDRV_HANDLER:
- ret = handle_set_wfi_drv_handler(msg->vif, &msg->body.drv);
- break;
+ kfree(msg);
+ complete(&hif_thread_comp);
+}

- case HOST_IF_MSG_SET_OPERATION_MODE:
- handle_set_operation_mode(msg->vif, &msg->body.mode);
- break;
+static void handle_scan_complete(struct work_struct *work)
+{
+ struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+ struct wilc *wilc = msg->vif->wilc;

- case HOST_IF_MSG_SET_IPADDRESS:
- handle_set_ip_address(msg->vif,
- msg->body.ip_info.ip_addr,
- msg->body.ip_info.idx);
- break;
+ del_timer(&msg->vif->hif_drv->scan_timer);

- case HOST_IF_MSG_GET_IPADDRESS:
- handle_get_ip_address(msg->vif, msg->body.ip_info.idx);
- break;
+ if (!wilc_wlan_get_num_conn_ifcs(wilc))
+ wilc_chip_sleep_manually(wilc);

- case HOST_IF_MSG_GET_MAC_ADDRESS:
- handle_get_mac_address(msg->vif,
- &msg->body.get_mac_info);
- break;
+ handle_scan_done(msg->vif, SCAN_EVENT_DONE);

- case HOST_IF_MSG_REMAIN_ON_CHAN:
+ if (msg->vif->hif_drv->remain_on_ch_pending)
handle_remain_on_chan(msg->vif, &msg->body.remain_on_ch);
- break;
-
- case HOST_IF_MSG_REGISTER_FRAME:
- handle_register_frame(msg->vif, &msg->body.reg_frame);
- break;
-
- case HOST_IF_MSG_LISTEN_TIMER_FIRED:
- handle_listen_state_expired(msg->vif, &msg->body.remain_on_ch);
- break;
-
- case HOST_IF_MSG_SET_MULTICAST_FILTER:
- handle_set_mcast_filter(msg->vif, &msg->body.multicast_info);
- break;
-
- case HOST_IF_MSG_DEL_ALL_STA:
- handle_del_all_sta(msg->vif, &msg->body.del_all_sta_info);
- break;
-
- case HOST_IF_MSG_SET_TX_POWER:
- handle_set_tx_pwr(msg->vif, msg->body.tx_power.tx_pwr);
- break;
-
- case HOST_IF_MSG_GET_TX_POWER:
- handle_get_tx_pwr(msg->vif, &msg->body.tx_power.tx_pwr);
- break;
- default:
- netdev_err(msg->vif->ndev, "[Host Interface] undefined\n");
- break;
- }
-free_msg:
- if (ret)
- netdev_err(msg->vif->ndev, "Host cmd %d failed\n", msg->id);
kfree(msg);
complete(&hif_thread_comp);
}
@@ -2580,7 +2563,7 @@ static void timer_scan_cb(struct timer_list *t)

memset(&msg, 0, sizeof(struct host_if_msg));
msg.vif = vif;
- msg.id = HOST_IF_MSG_SCAN_TIMER_FIRED;
+ msg.fn = handle_scan_timer;

wilc_enqueue_cmd(&msg);
}
@@ -2594,7 +2577,7 @@ static void timer_connect_cb(struct timer_list *t)

memset(&msg, 0, sizeof(struct host_if_msg));
msg.vif = vif;
- msg.id = HOST_IF_MSG_CONNECT_TIMER_FIRED;
+ msg.fn = handle_connect_timeout;

wilc_enqueue_cmd(&msg);
}
@@ -2613,7 +2596,7 @@ int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_KEY;
+ msg.fn = handle_key;
msg.body.key_info.type = WEP;
msg.body.key_info.action = REMOVEKEY;
msg.vif = vif;
@@ -2642,7 +2625,7 @@ int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_KEY;
+ msg.fn = handle_key;
msg.body.key_info.type = WEP;
msg.body.key_info.action = DEFAULTKEY;
msg.vif = vif;
@@ -2671,7 +2654,7 @@ int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_KEY;
+ msg.fn = handle_key;
msg.body.key_info.type = WEP;
msg.body.key_info.action = ADDKEY;
msg.vif = vif;
@@ -2707,7 +2690,7 @@ int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_KEY;
+ msg.fn = handle_key;
msg.body.key_info.type = WEP;
msg.body.key_info.action = ADDKEY_AP;
msg.vif = vif;
@@ -2753,7 +2736,7 @@ int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_KEY;
+ msg.fn = handle_key;
msg.body.key_info.type = WPA_PTK;
if (mode == AP_MODE) {
msg.body.key_info.action = ADDKEY_AP;
@@ -2820,7 +2803,7 @@ int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
return -ENOMEM;
}

- msg.id = HOST_IF_MSG_KEY;
+ msg.fn = handle_key;
msg.body.key_info.type = WPA_RX_GTK;
msg.vif = vif;

@@ -2872,7 +2855,7 @@ int wilc_set_pmkid_info(struct wilc_vif *vif,

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_KEY;
+ msg.fn = handle_key;
msg.body.key_info.type = PMKSA;
msg.body.key_info.action = ADDKEY;
msg.vif = vif;
@@ -2898,7 +2881,7 @@ int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_GET_MAC_ADDRESS;
+ msg.fn = handle_get_mac_address;
msg.body.get_mac_info.mac_addr = mac_addr;
msg.vif = vif;

@@ -2934,8 +2917,7 @@ int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ssid,

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_CONNECT;
-
+ msg.fn = handle_connect;
msg.body.con_info.security = security;
msg.body.con_info.auth_type = auth_type;
msg.body.con_info.ch = channel;
@@ -2992,7 +2974,7 @@ int wilc_disconnect(struct wilc_vif *vif, u16 reason_code)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_DISCONNECT;
+ msg.fn = handle_disconnect;
msg.vif = vif;

result = wilc_enqueue_cmd(&msg);
@@ -3035,7 +3017,7 @@ int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
struct host_if_msg msg;

memset(&msg, 0, sizeof(struct host_if_msg));
- msg.id = HOST_IF_MSG_SET_CHANNEL;
+ msg.fn = handle_set_channel;
msg.body.channel_info.set_ch = channel;
msg.vif = vif;

@@ -3055,7 +3037,7 @@ int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
struct host_if_msg msg;

memset(&msg, 0, sizeof(struct host_if_msg));
- msg.id = HOST_IF_MSG_SET_WFIDRV_HANDLER;
+ msg.fn = handle_set_wfi_drv_handler;
msg.body.drv.handler = index;
msg.body.drv.mode = mode;
msg.body.drv.name = ifc_id;
@@ -3076,7 +3058,7 @@ int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode)
struct host_if_msg msg;

memset(&msg, 0, sizeof(struct host_if_msg));
- msg.id = HOST_IF_MSG_SET_OPERATION_MODE;
+ msg.fn = handle_set_operation_mode;
msg.body.mode.mode = mode;
msg.vif = vif;

@@ -3104,7 +3086,7 @@ s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac,
memset(&msg, 0, sizeof(struct host_if_msg));
memcpy(msg.body.mac_info.mac, mac, ETH_ALEN);

- msg.id = HOST_IF_MSG_GET_INACTIVETIME;
+ msg.fn = handle_get_inactive_time;
msg.vif = vif;

result = wilc_enqueue_cmd(&msg);
@@ -3125,7 +3107,7 @@ int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
struct host_if_drv *hif_drv = vif->hif_drv;

memset(&msg, 0, sizeof(struct host_if_msg));
- msg.id = HOST_IF_MSG_GET_RSSI;
+ msg.fn = handle_get_rssi;
msg.vif = vif;

result = wilc_enqueue_cmd(&msg);
@@ -3152,7 +3134,7 @@ int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
struct host_if_msg msg;

memset(&msg, 0, sizeof(struct host_if_msg));
- msg.id = HOST_IF_MSG_GET_STATISTICS;
+ msg.fn = handle_get_statistics;
msg.body.data = (char *)stats;
msg.vif = vif;

@@ -3184,7 +3166,7 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_SCAN;
+ msg.fn = handle_scan;

if (hidden_network) {
scan_info->hidden_network.net_info = hidden_network->net_info;
@@ -3234,7 +3216,7 @@ int wilc_hif_set_cfg(struct wilc_vif *vif,
}

memset(&msg, 0, sizeof(struct host_if_msg));
- msg.id = HOST_IF_MSG_CFG_PARAMS;
+ msg.fn = handle_cfg_param;
msg.body.cfg_info = *cfg_param;
msg.vif = vif;

@@ -3364,7 +3346,7 @@ int wilc_deinit(struct wilc_vif *vif)
memset(&msg, 0, sizeof(struct host_if_msg));

if (clients_count == 1) {
- msg.id = HOST_IF_MSG_EXIT;
+ msg.fn = handle_hif_exit_work;
msg.vif = vif;

result = wilc_enqueue_cmd(&msg);
@@ -3408,7 +3390,7 @@ void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_RCVD_NTWRK_INFO;
+ msg.fn = handle_rcvd_ntwrk_info;
msg.vif = vif;

msg.body.net_info.len = length;
@@ -3458,7 +3440,7 @@ void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO;
+ msg.fn = handle_rcvd_gnrl_async_info;
msg.vif = vif;

msg.body.async_info.len = length;
@@ -3500,7 +3482,7 @@ void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
if (hif_drv->usr_scan_req.scan_result) {
memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_RCVD_SCAN_COMPLETE;
+ msg.fn = handle_scan_complete;
msg.vif = vif;

result = wilc_enqueue_cmd(&msg);
@@ -3520,7 +3502,7 @@ int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_REMAIN_ON_CHAN;
+ msg.fn = handle_remain_on_chan_work;
msg.body.remain_on_ch.ch = chan;
msg.body.remain_on_ch.expired = expired;
msg.body.remain_on_ch.ready = ready;
@@ -3550,7 +3532,7 @@ int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id)
del_timer(&hif_drv->remain_on_ch_timer);

memset(&msg, 0, sizeof(struct host_if_msg));
- msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
+ msg.fn = handle_listen_state_expired;
msg.vif = vif;
msg.body.remain_on_ch.id = session_id;

@@ -3568,7 +3550,7 @@ int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_REGISTER_FRAME;
+ msg.fn = handle_register_frame;
switch (frame_type) {
case ACTION:
msg.body.reg_frame.reg_id = ACTION_FRM_IDX;
@@ -3601,7 +3583,7 @@ int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_ADD_BEACON;
+ msg.fn = handle_add_beacon;
msg.vif = vif;
beacon_info->interval = interval;
beacon_info->dtim_period = dtim_period;
@@ -3642,7 +3624,7 @@ int wilc_del_beacon(struct wilc_vif *vif)
int result = 0;
struct host_if_msg msg;

- msg.id = HOST_IF_MSG_DEL_BEACON;
+ msg.fn = handle_del_beacon;
msg.vif = vif;

result = wilc_enqueue_cmd(&msg);
@@ -3660,7 +3642,7 @@ int wilc_add_station(struct wilc_vif *vif, struct add_sta_param *sta_param)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_ADD_STATION;
+ msg.fn = handle_add_station;
msg.vif = vif;

memcpy(add_sta_info, sta_param, sizeof(struct add_sta_param));
@@ -3688,7 +3670,7 @@ int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_DEL_STATION;
+ msg.fn = handle_del_station;
msg.vif = vif;

if (!mac_addr)
@@ -3713,7 +3695,7 @@ int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_DEL_ALL_STA;
+ msg.fn = handle_del_all_sta;
msg.vif = vif;

for (i = 0; i < MAX_NUM_STA; i++) {
@@ -3746,7 +3728,7 @@ int wilc_edit_station(struct wilc_vif *vif,

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_EDIT_STATION;
+ msg.fn = handle_edit_station;
msg.vif = vif;

memcpy(add_sta_info, sta_param, sizeof(struct add_sta_param));
@@ -3778,7 +3760,7 @@ int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_POWER_MGMT;
+ msg.fn = handle_power_management;
msg.vif = vif;

pwr_mgmt_info->enabled = enabled;
@@ -3799,7 +3781,7 @@ int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled,

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_SET_MULTICAST_FILTER;
+ msg.fn = handle_set_mcast_filter;
msg.vif = vif;

multicast_filter_param->enabled = enabled;
@@ -3983,7 +3965,7 @@ int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_SET_IPADDRESS;
+ msg.fn = handle_set_ip_address;

msg.body.ip_info.ip_addr = ip_addr;
msg.vif = vif;
@@ -4003,7 +3985,7 @@ static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_GET_IPADDRESS;
+ msg.fn = handle_get_ip_address;

msg.body.ip_info.ip_addr = ip_addr;
msg.vif = vif;
@@ -4023,7 +4005,7 @@ int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_SET_TX_POWER;
+ msg.fn = handle_set_tx_pwr;
msg.body.tx_power.tx_pwr = tx_power;
msg.vif = vif;

@@ -4041,7 +4023,7 @@ int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)

memset(&msg, 0, sizeof(struct host_if_msg));

- msg.id = HOST_IF_MSG_GET_TX_POWER;
+ msg.fn = handle_get_tx_pwr;
msg.vif = vif;

ret = wilc_enqueue_cmd(&msg);
--
2.7.4

2018-06-26 06:07:30

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 05/12] staging: wilc1000: remove 'hif_thread_comp' completions

Remove 'hif_thread_comp' completions as its not required after adding
completion event as part work data to handle each sync call.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 35 -------------------------------
1 file changed, 35 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 27516f7..17c20b9 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -186,7 +186,6 @@ static struct host_if_drv *terminated_handle;
bool wilc_optaining_ip;
static u8 p2p_listen_state;
static struct workqueue_struct *hif_workqueue;
-static struct completion hif_thread_comp;
static struct completion hif_driver_comp;
static struct mutex hif_deinit_lock;
static struct timer_list periodic_rssi;
@@ -286,7 +285,6 @@ static void handle_set_channel(struct work_struct *work)
if (ret)
netdev_err(vif->ndev, "Failed to set channel\n");
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_set_wfi_drv_handler(struct work_struct *work)
@@ -334,7 +332,6 @@ static void handle_set_wfi_drv_handler(struct work_struct *work)

free_msg:
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_set_operation_mode(struct work_struct *work)
@@ -359,7 +356,6 @@ static void handle_set_operation_mode(struct work_struct *work)
if (ret)
netdev_err(vif->ndev, "Failed to set driver handler\n");
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_set_ip_address(struct work_struct *work)
@@ -390,7 +386,6 @@ static void handle_set_ip_address(struct work_struct *work)
if (ret)
netdev_err(vif->ndev, "Failed to set IP address\n");
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_get_ip_address(struct work_struct *work)
@@ -419,7 +414,6 @@ static void handle_get_ip_address(struct work_struct *work)
if (ret)
netdev_err(vif->ndev, "Failed to get IP address\n");
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_get_mac_address(struct work_struct *work)
@@ -442,7 +436,6 @@ static void handle_get_mac_address(struct work_struct *work)
netdev_err(vif->ndev, "Failed to get mac address\n");
complete(&msg->work_comp);
/* free 'msg' data later, in caller */
- complete(&hif_thread_comp);
}

static void handle_cfg_param(struct work_struct *work)
@@ -739,7 +732,6 @@ static void handle_cfg_param(struct work_struct *work)
unlock:
mutex_unlock(&hif_drv->cfg_values_lock);
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_scan(struct work_struct *work)
@@ -857,7 +849,6 @@ static void handle_scan(struct work_struct *work)
kfree(hdn_ntwk_wid_val);

kfree(msg);
- complete(&hif_thread_comp);
}

static s32 handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
@@ -1163,7 +1154,6 @@ static void handle_connect(struct work_struct *work)

kfree(cur_byte);
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_connect_timeout(struct work_struct *work)
@@ -1235,7 +1225,6 @@ static void handle_connect_timeout(struct work_struct *work)

out:
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_rcvd_ntwrk_info(struct work_struct *work)
@@ -1304,7 +1293,6 @@ static void handle_rcvd_ntwrk_info(struct work_struct *work)
}

kfree(msg);
- complete(&hif_thread_comp);
}

static s32 host_int_get_assoc_res_info(struct wilc_vif *vif,
@@ -1495,7 +1483,6 @@ static void handle_rcvd_gnrl_async_info(struct work_struct *work)

free_msg:
kfree(msg);
- complete(&hif_thread_comp);
}

static int wilc_pmksa_key_copy(struct wilc_vif *vif, struct key_attr *hif_key)
@@ -1760,7 +1747,6 @@ static void handle_key(struct work_struct *work)
netdev_err(vif->ndev, "Failed to send key config packet\n");

/* free 'msg' data in caller sync call */
- complete(&hif_thread_comp);
}

static void handle_disconnect(struct work_struct *work)
@@ -1835,7 +1821,6 @@ static void handle_disconnect(struct work_struct *work)

complete(&msg->work_comp);
/* free 'msg' in caller after receiving completion */
- complete(&hif_thread_comp);
}

void wilc_resolve_disconnect_aberration(struct wilc_vif *vif)
@@ -1866,7 +1851,6 @@ static void handle_get_rssi(struct work_struct *work)

complete(&msg->work_comp);
/* free 'msg' data in caller */
- complete(&hif_thread_comp);
}

static void handle_get_statistics(struct work_struct *work)
@@ -1925,8 +1909,6 @@ static void handle_get_statistics(struct work_struct *work)
complete(&msg->work_comp);
else
kfree(msg);
-
- complete(&hif_thread_comp);
}

static void handle_get_inactive_time(struct work_struct *work)
@@ -1969,7 +1951,6 @@ static void handle_get_inactive_time(struct work_struct *work)
out:
/* free 'msg' data in caller */
complete(&msg->work_comp);
- complete(&hif_thread_comp);
}

static void handle_add_beacon(struct work_struct *work)
@@ -2026,7 +2007,6 @@ static void handle_add_beacon(struct work_struct *work)
kfree(param->head);
kfree(param->tail);
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_del_beacon(struct work_struct *work)
@@ -2047,7 +2027,6 @@ static void handle_del_beacon(struct work_struct *work)
if (result)
netdev_err(vif->ndev, "Failed to send delete beacon\n");
kfree(msg);
- complete(&hif_thread_comp);
}

static u32 wilc_hif_pack_sta_param(u8 *buff, struct add_sta_param *param)
@@ -2109,7 +2088,6 @@ static void handle_add_station(struct work_struct *work)
kfree(param->rates);
kfree(wid.val);
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_del_all_sta(struct work_struct *work)
@@ -2154,7 +2132,6 @@ static void handle_del_all_sta(struct work_struct *work)

/* free 'msg' data in caller */
complete(&msg->work_comp);
- complete(&hif_thread_comp);
}

static void handle_del_station(struct work_struct *work)
@@ -2183,7 +2160,6 @@ static void handle_del_station(struct work_struct *work)
error:
kfree(wid.val);
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_edit_station(struct work_struct *work)
@@ -2215,7 +2191,6 @@ static void handle_edit_station(struct work_struct *work)
kfree(param->rates);
kfree(wid.val);
kfree(msg);
- complete(&hif_thread_comp);
}

static int handle_remain_on_chan(struct wilc_vif *vif,
@@ -2316,7 +2291,6 @@ static void handle_register_frame(struct work_struct *work)

out:
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_listen_state_expired(struct work_struct *work)
@@ -2361,7 +2335,6 @@ static void handle_listen_state_expired(struct work_struct *work)

free_msg:
kfree(msg);
- complete(&hif_thread_comp);
}

static void listen_timer_cb(struct timer_list *t)
@@ -2411,7 +2384,6 @@ static void handle_power_management(struct work_struct *work)
if (result)
netdev_err(vif->ndev, "Failed to send power management\n");
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_set_mcast_filter(struct work_struct *work)
@@ -2453,7 +2425,6 @@ static void handle_set_mcast_filter(struct work_struct *work)
error:
kfree(wid.val);
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_set_tx_pwr(struct work_struct *work)
@@ -2474,7 +2445,6 @@ static void handle_set_tx_pwr(struct work_struct *work)
if (ret)
netdev_err(vif->ndev, "Failed to set TX PWR\n");
kfree(msg);
- complete(&hif_thread_comp);
}

/* Note: 'msg' will be free after using data */
@@ -2497,7 +2467,6 @@ static void handle_get_tx_pwr(struct work_struct *work)
netdev_err(vif->ndev, "Failed to get TX PWR\n");

complete(&msg->work_comp);
- complete(&hif_thread_comp);
}

static void handle_scan_timer(struct work_struct *work)
@@ -2506,7 +2475,6 @@ static void handle_scan_timer(struct work_struct *work)

handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_remain_on_chan_work(struct work_struct *work)
@@ -2515,7 +2483,6 @@ static void handle_remain_on_chan_work(struct work_struct *work)

handle_remain_on_chan(msg->vif, &msg->body.remain_on_ch);
kfree(msg);
- complete(&hif_thread_comp);
}

static void handle_hif_exit_work(struct work_struct *work)
@@ -2541,7 +2508,6 @@ static void handle_scan_complete(struct work_struct *work)
if (msg->vif->hif_drv->remain_on_ch_pending)
handle_remain_on_chan(msg->vif, &msg->body.remain_on_ch);
kfree(msg);
- complete(&hif_thread_comp);
}

static void timer_scan_cb(struct timer_list *t)
@@ -3343,7 +3309,6 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
wilc_optaining_ip = false;

if (clients_count == 0) {
- init_completion(&hif_thread_comp);
init_completion(&hif_driver_comp);
mutex_init(&hif_deinit_lock);
}
--
2.7.4