2018-09-04 11:03:30

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 00/26] staging: wilc1000: avoid use of static and global variable

This patch set mainly contains changes to avoid the use of static
and global variables. Also contains few patch to avoid the checkpatch
warning arise due to code refactor.

Changes since v1:
1. rework on patch#10, use dynamically allocating memory to maintain
multicast mac address filter list.
2. rework on patch#11, only move hif_workqueue to 'wilc' struct.
3. dropped patch#12 of previous patchset version.
4. modified patch#18 & #19 as per the review comments.
5. patch#22, change 'int' to 'bool' type for 'connecting' variable.
6. added 3 new patches #24,25 &26 in this series.


Ajay Singh (26):
staging: wilc1000: move 'wilc_enable_ps' global variable into 'wilc'
struct
staging: wilc1000: move 'aging_timer' static variable to wilc_priv
struct
staging: wilc1000: fix to use correct index to free scanned info in
clear_shadow_scan()
staging: wilc1000: remove unnecessary NULL check in
clear_shadow_scan()
staging: wilc1000: moved last_scanned_shadow & last_scanned_cnt to
wilc_priv struct
staging: wilc1000: move during_ip_timer & wilc_optaining_ip to
'wilc_vif' struct
staging: wilc1000: remove unused variable 'op_ifcs'
staging: wilc1000: avoid use of extra 'if' condition in wilc_init()
staging: wilc1000: move static variable clients_count to 'wilc'
structure
staging: wilc1000: refactor code to avoid use of
wilc_set_multicast_list global
staging: wilc1000: move hif_workqueue static variables to 'wilc'
structure
staging: wilc1000: move 'periodic_rssi' as part of 'wilc_vif' struct
staging: wilc1000: rename 'dummy_statistics' variable to
'periodic_stat'
staging: wilc1000: move 'rcv_assoc_resp' as part of hif_drv
staging: wilc1000: refactor tcp_process() to avoid extra leading tabs
staging: wilc1000: use lowercase for get_BSSID() and HIL variable
staging: wilc1000: move tcp_ack_filter algo related variables to
'wilc_vif' struct
staging: wilc1000: avoid line over 80 chars in
wilc_wlan_txq_filter_dup_tcp_ack()
staging: wilc1000: use short names to fix over 80 issue in
tcp_process()
staging: wilc1000: remove unused code to set and get IP address
staging: wilc1000: move 'chip_ps_state' static variable as part of
'wilc' struct
staging: wilc1000: move 'wilc_connecting' static variable to
'wilc_vif' struct
staging: wilc1000: remove unnecessary static variable
'p2p_listen_state'
staging: wilc1000: refactor code to move initilization in
wilc_netdev_init()
staging: wilc1000: refactor wilc_netdev_init() to handle memory free
in error path
staging: wilc1000: remove handle_hif_exit_work() function

drivers/staging/wilc1000/coreconfigurator.c | 4 +-
drivers/staging/wilc1000/host_interface.c | 215 ++++------------------
drivers/staging/wilc1000/host_interface.h | 13 +-
drivers/staging/wilc1000/linux_wlan.c | 79 +++++---
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 197 ++++++++++----------
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 41 ++++-
drivers/staging/wilc1000/wilc_wlan.c | 174 ++++++++---------
drivers/staging/wilc1000/wilc_wlan.h | 5 +-
8 files changed, 307 insertions(+), 421 deletions(-)

--
2.7.4


2018-09-04 11:04:42

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 21/26] staging: wilc1000: move 'chip_ps_state' static variable as part of 'wilc' struct

Move the static variable as part of 'wilc' priv struct.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/linux_wlan.c | 1 +
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 1 +
drivers/staging/wilc1000/wilc_wlan.c | 10 ++++------
3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 1300318..8c6b63a 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -1066,6 +1066,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
wl->io_type = io_type;
wl->hif_func = ops;
wl->enable_ps = true;
+ wl->chip_ps_state = CHIP_WAKEDUP;
INIT_LIST_HEAD(&wl->txq_head.list);
INIT_LIST_HEAD(&wl->rxq_head.list);

diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 26b87c4..ede967b 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -201,6 +201,7 @@ struct wilc {
bool enable_ps;
int clients_count;
struct workqueue_struct *hif_workqueue;
+ enum chip_ps_states chip_ps_state;
};

struct wilc_wfi_mon_priv {
diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index 4c5a69e..6ff3e58 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -9,8 +9,6 @@
#include "wilc_wfi_netdevice.h"
#include "wilc_wlan_cfg.h"

-static enum chip_ps_states chip_ps_state = CHIP_WAKEDUP;
-
static inline bool is_wilc1000(u32 id)
{
return ((id & 0xfffff000) == 0x100000 ? true : false);
@@ -444,7 +442,7 @@ void chip_wakeup(struct wilc *wilc)
} while ((clk_status_reg & 0x1) == 0);
}

- if (chip_ps_state == CHIP_SLEEPING_MANUAL) {
+ if (wilc->chip_ps_state == CHIP_SLEEPING_MANUAL) {
if (wilc_get_chipid(wilc, false) < 0x1002b0) {
u32 val32;

@@ -457,19 +455,19 @@ void chip_wakeup(struct wilc *wilc)
wilc->hif_func->hif_write_reg(wilc, 0x1e9c, val32);
}
}
- chip_ps_state = CHIP_WAKEDUP;
+ wilc->chip_ps_state = CHIP_WAKEDUP;
}

void wilc_chip_sleep_manually(struct wilc *wilc)
{
- if (chip_ps_state != CHIP_WAKEDUP)
+ if (wilc->chip_ps_state != CHIP_WAKEDUP)
return;
acquire_bus(wilc, ACQUIRE_ONLY);

chip_allow_sleep(wilc);
wilc->hif_func->hif_write_reg(wilc, 0x10a8, 1);

- chip_ps_state = CHIP_SLEEPING_MANUAL;
+ wilc->chip_ps_state = CHIP_SLEEPING_MANUAL;
release_bus(wilc, RELEASE_ONLY);
}

--
2.7.4

2018-09-04 11:03:53

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 07/26] staging: wilc1000: remove unused variable 'op_ifcs'

After code refactor in previous commit now 'op_ifcs' is not require any
more, so remove it.

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

diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 1690890..3418d2d 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -82,8 +82,6 @@ static const struct wiphy_wowlan_support wowlan_support = {
.flags = WIPHY_WOWLAN_ANY
};

-static u8 op_ifcs;
-
#define CHAN2G(_channel, _freq, _flags) { \
.band = NL80211_BAND_2GHZ, \
.center_freq = (_freq), \
@@ -2164,7 +2162,6 @@ int wilc_init_host_int(struct net_device *net)

timer_setup(&priv->aging_timer, remove_network_from_shadow, 0);
timer_setup(&vif->during_ip_timer, clear_during_ip, 0);
- op_ifcs++;

priv->p2p_listen_state = false;

@@ -2184,8 +2181,6 @@ int wilc_deinit_host_int(struct net_device *net)

priv->p2p_listen_state = false;

- op_ifcs--;
-
mutex_destroy(&priv->scan_req_lock);
ret = wilc_deinit(vif);

--
2.7.4

2018-09-04 11:04:35

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 19/26] staging: wilc1000: use short names to fix over 80 issue in tcp_process()

Use short variable names to avoid line over 80 chars checkpatch warning
in tcp_process().

struct pending_acks_info --> struct pending_ack
int tcp_pending_ack_idx --> int ack_idx
u32 pending_ack --> u32 pending_ack_idx

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 6 ++---
drivers/staging/wilc1000/wilc_wlan.c | 34 +++++++++++++--------------
drivers/staging/wilc1000/wilc_wlan.h | 2 +-
3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 09f619b..26b87c4 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -115,7 +115,7 @@ struct ack_session_info {
u16 status;
};

-struct pending_acks_info {
+struct pending_acks {
u32 ack_num;
u32 session_index;
struct txq_entry_t *txqe;
@@ -123,10 +123,10 @@ struct pending_acks_info {

struct tcp_ack_filter {
struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
- struct pending_acks_info pending_acks_info[MAX_PENDING_ACKS];
+ struct pending_acks pending_acks[MAX_PENDING_ACKS];
u32 pending_base;
u32 tcp_session;
- u32 pending_acks;
+ u32 pending_acks_idx;
bool enabled;
};

diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index 46db790..4c5a69e 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -125,14 +125,14 @@ static inline int add_tcp_pending_ack(struct wilc_vif *vif, u32 ack,
struct txq_entry_t *txqe)
{
struct tcp_ack_filter *f = &vif->ack_filter;
- u32 i = f->pending_base + f->pending_acks;
+ u32 i = f->pending_base + f->pending_acks_idx;

if (i < MAX_PENDING_ACKS) {
- f->pending_acks_info[i].ack_num = ack;
- f->pending_acks_info[i].txqe = txqe;
- f->pending_acks_info[i].session_index = session_index;
- txqe->tcp_pending_ack_idx = i;
- f->pending_acks++;
+ f->pending_acks[i].ack_num = ack;
+ f->pending_acks[i].txqe = txqe;
+ f->pending_acks[i].session_index = session_index;
+ txqe->ack_idx = i;
+ f->pending_acks_idx++;
}
return 0;
}
@@ -200,24 +200,24 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)

spin_lock_irqsave(&wilc->txq_spinlock, flags);
for (i = f->pending_base;
- i < (f->pending_base + f->pending_acks); i++) {
+ i < (f->pending_base + f->pending_acks_idx); i++) {
u32 index;
u32 bigger_ack_num;

if (i >= MAX_PENDING_ACKS)
break;

- index = f->pending_acks_info[i].session_index;
+ index = f->pending_acks[i].session_index;

if (index >= 2 * MAX_TCP_SESSION)
break;

bigger_ack_num = f->ack_session_info[index].bigger_ack_num;

- if (f->pending_acks_info[i].ack_num < bigger_ack_num) {
+ if (f->pending_acks[i].ack_num < bigger_ack_num) {
struct txq_entry_t *tqe;

- tqe = f->pending_acks_info[i].txqe;
+ tqe = f->pending_acks[i].txqe;
if (tqe) {
wilc_wlan_txq_remove(wilc, tqe);
tqe->status = 1;
@@ -229,7 +229,7 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
}
}
}
- f->pending_acks = 0;
+ f->pending_acks_idx = 0;
f->tcp_session = 0;

if (f->pending_base == 0)
@@ -275,7 +275,7 @@ static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer,
tqe->buffer_size = buffer_size;
tqe->tx_complete_func = NULL;
tqe->priv = NULL;
- tqe->tcp_pending_ack_idx = NOT_TCP_ACK;
+ tqe->ack_idx = NOT_TCP_ACK;

if (wilc_wlan_txq_add_to_head(vif, tqe)) {
kfree(tqe);
@@ -307,7 +307,7 @@ int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
tqe->tx_complete_func = func;
tqe->priv = priv;

- tqe->tcp_pending_ack_idx = NOT_TCP_ACK;
+ tqe->ack_idx = NOT_TCP_ACK;
if (vif->ack_filter.enabled)
tcp_process(dev, tqe);
wilc_wlan_txq_add_to_tail(dev, tqe);
@@ -335,7 +335,7 @@ int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
tqe->buffer_size = buffer_size;
tqe->tx_complete_func = func;
tqe->priv = priv;
- tqe->tcp_pending_ack_idx = NOT_TCP_ACK;
+ tqe->ack_idx = NOT_TCP_ACK;
wilc_wlan_txq_add_to_tail(dev, tqe);
return 1;
}
@@ -668,9 +668,9 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count)
tqe->status = 1;
if (tqe->tx_complete_func)
tqe->tx_complete_func(tqe->priv, tqe->status);
- if (tqe->tcp_pending_ack_idx != NOT_TCP_ACK &&
- tqe->tcp_pending_ack_idx < MAX_PENDING_ACKS)
- vif->ack_filter.pending_acks_info[tqe->tcp_pending_ack_idx].txqe = NULL;
+ if (tqe->ack_idx != NOT_TCP_ACK &&
+ tqe->ack_idx < MAX_PENDING_ACKS)
+ vif->ack_filter.pending_acks[tqe->ack_idx].txqe = NULL;
kfree(tqe);
} while (--entries);

diff --git a/drivers/staging/wilc1000/wilc_wlan.h b/drivers/staging/wilc1000/wilc_wlan.h
index 0fdffdd..8c49c0c 100644
--- a/drivers/staging/wilc1000/wilc_wlan.h
+++ b/drivers/staging/wilc1000/wilc_wlan.h
@@ -212,7 +212,7 @@
struct txq_entry_t {
struct list_head list;
int type;
- int tcp_pending_ack_idx;
+ int ack_idx;
u8 *buffer;
int buffer_size;
void *priv;
--
2.7.4

2018-09-11 15:30:02

by Ajay Singh

[permalink] [raw]
Subject: Re: [PATCH v2 25/26] staging: wilc1000: refactor wilc_netdev_init() to handle memory free in error path

Hi Claudiu,

On Tue, 11 Sep 2018 12:21:13 +0300
Claudiu Beznea <[email protected]> wrote:

> On 04.09.2018 09:39, Ajay Singh wrote:
> > Refactor the wilc_netdev_init() to cleanup the memory for error
> > scenario and remove unnecessary 'dev' pointer check.
> >
> > Signed-off-by: Ajay Singh <[email protected]>
> > ---
> > drivers/staging/wilc1000/linux_wlan.c | 36
> > ++++++++++++++++-------
> > drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 6 +++- 2 files
> > changed, 30 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/staging/wilc1000/linux_wlan.c
> > b/drivers/staging/wilc1000/linux_wlan.c index d7d43fd..91a45a7
> > 100644 --- a/drivers/staging/wilc1000/linux_wlan.c
> > +++ b/drivers/staging/wilc1000/linux_wlan.c
> > @@ -1073,10 +1073,8 @@ int wilc_netdev_init(struct wilc **wilc,
> > struct device *dev, int io_type, INIT_LIST_HEAD(&wl->rxq_head.list);
> >
> > wl->hif_workqueue =
> > create_singlethread_workqueue("WILC_wq");
> > - if (!wl->hif_workqueue) {
> > - kfree(wl);
> > - return -ENOMEM;
> > - }
> > + if (!wl->hif_workqueue)
> > + goto free_wl;
> >
> > register_inetaddr_notifier(&g_dev_notifier);
> >
> > @@ -1085,7 +1083,7 @@ int wilc_netdev_init(struct wilc **wilc,
> > struct device *dev, int io_type,
> > ndev = alloc_etherdev(sizeof(struct wilc_vif));
> > if (!ndev)
> > - return -ENOMEM;
> > + goto free_ndev;
> >
> > vif = netdev_priv(ndev);
> > memset(vif, 0, sizeof(struct wilc_vif));
> > @@ -1106,15 +1104,13 @@ int wilc_netdev_init(struct wilc **wilc,
> > struct device *dev, int io_type, ndev->netdev_ops =
> > &wilc_netdev_ops;
> > wdev = wilc_create_wiphy(ndev, dev);
> > -
> > - if (dev)
> > - SET_NETDEV_DEV(ndev, dev);
> > -
> > if (!wdev) {
> > netdev_err(ndev, "Can't register WILC
> > Wiphy\n");
> > - return -1;
> > + goto free_ndev;
> > }
> >
> > + SET_NETDEV_DEV(ndev, dev);
> > +
> > vif->ndev->ieee80211_ptr = wdev;
> > vif->ndev->ml_priv = vif;
> > wdev->netdev = vif->ndev;
> > @@ -1125,11 +1121,29 @@ int wilc_netdev_init(struct wilc **wilc,
> > struct device *dev, int io_type,
> > ret = register_netdev(ndev);
> > if (ret)
> > - return ret;
> > + goto free_ndev;
>
> In case this happens you will loose the return code of
> register_netdev() and you will return instead -ENOMEM. Maybe, the
> best approach will be to initialize ret = -ENOMEM while declaring it

Thanks for your suggestion to handle the return code.
I will work on it and submit the changes in different series.

Regards,
Ajay

2018-09-04 11:03:47

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 05/26] staging: wilc1000: moved last_scanned_shadow & last_scanned_cnt to wilc_priv struct

Avoid use of static variables and moved the varibles as part of private
data. last_scanned_shadow & last_scanned_cnt variable is moved to
'wilc_priv' to maintain for each interface. After moving static
variable, clear_shadow_scan() doesn't require check 'op_ifcs'
count as now for each interface the againg timer is initiated.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 105 +++++++++++-----------
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 2 +
2 files changed, 52 insertions(+), 55 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 00a167b..1eac244 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -82,8 +82,6 @@ static const struct wiphy_wowlan_support wowlan_support = {
.flags = WIPHY_WOWLAN_ANY
};

-static struct network_info last_scanned_shadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
-static u32 last_scanned_cnt;
struct timer_list wilc_during_ip_timer;
static u8 op_ifcs;

@@ -157,21 +155,18 @@ static struct ieee80211_supported_band wilc_band_2ghz = {
#define AGING_TIME (9 * 1000)
#define DURING_IP_TIME_OUT 15000

-static void clear_shadow_scan(void)
+static void clear_shadow_scan(struct wilc_priv *priv)
{
int i;

- if (op_ifcs != 0)
- return;
-
- for (i = 0; i < last_scanned_cnt; i++) {
- kfree(last_scanned_shadow[i].ies);
- last_scanned_shadow[i].ies = NULL;
+ for (i = 0; i < priv->scanned_cnt; i++) {
+ kfree(priv->scanned_shadow[i].ies);
+ priv->scanned_shadow[i].ies = NULL;

- kfree(last_scanned_shadow[i].join_params);
- last_scanned_shadow[i].join_params = NULL;
+ kfree(priv->scanned_shadow[i].join_params);
+ priv->scanned_shadow[i].join_params = NULL;
}
- last_scanned_cnt = 0;
+ priv->scanned_cnt = 0;
}

static u32 get_rssi_avg(struct network_info *network_info)
@@ -193,14 +188,14 @@ static void refresh_scan(struct wilc_priv *priv, bool direct_scan)
struct wiphy *wiphy = priv->dev->ieee80211_ptr->wiphy;
int i;

- for (i = 0; i < last_scanned_cnt; i++) {
+ for (i = 0; i < priv->scanned_cnt; i++) {
struct network_info *network_info;
s32 freq;
struct ieee80211_channel *channel;
int rssi;
struct cfg80211_bss *bss;

- network_info = &last_scanned_shadow[i];
+ network_info = &priv->scanned_shadow[i];

if (!memcmp("DIRECT-", network_info->ssid, 7) && !direct_scan)
continue;
@@ -224,20 +219,20 @@ static void refresh_scan(struct wilc_priv *priv, bool direct_scan)
}
}

-static void reset_shadow_found(void)
+static void reset_shadow_found(struct wilc_priv *priv)
{
int i;

- for (i = 0; i < last_scanned_cnt; i++)
- last_scanned_shadow[i].found = 0;
+ for (i = 0; i < priv->scanned_cnt; i++)
+ priv->scanned_shadow[i].found = 0;
}

-static void update_scan_time(void)
+static void update_scan_time(struct wilc_priv *priv)
{
int i;

- for (i = 0; i < last_scanned_cnt; i++)
- last_scanned_shadow[i].time_scan = jiffies;
+ for (i = 0; i < priv->scanned_cnt; i++)
+ priv->scanned_shadow[i].time_scan = jiffies;
}

static void remove_network_from_shadow(struct timer_list *t)
@@ -246,22 +241,22 @@ static void remove_network_from_shadow(struct timer_list *t)
unsigned long now = jiffies;
int i, j;

- for (i = 0; i < last_scanned_cnt; i++) {
- if (!time_after(now, last_scanned_shadow[i].time_scan +
+ for (i = 0; i < priv->scanned_cnt; i++) {
+ if (!time_after(now, priv->scanned_shadow[i].time_scan +
(unsigned long)(SCAN_RESULT_EXPIRE)))
continue;
- kfree(last_scanned_shadow[i].ies);
- last_scanned_shadow[i].ies = NULL;
+ kfree(priv->scanned_shadow[i].ies);
+ priv->scanned_shadow[i].ies = NULL;

- kfree(last_scanned_shadow[i].join_params);
+ kfree(priv->scanned_shadow[i].join_params);

- for (j = i; (j < last_scanned_cnt - 1); j++)
- last_scanned_shadow[j] = last_scanned_shadow[j + 1];
+ for (j = i; (j < priv->scanned_cnt - 1); j++)
+ priv->scanned_shadow[j] = priv->scanned_shadow[j + 1];

- last_scanned_cnt--;
+ priv->scanned_cnt--;
}

- if (last_scanned_cnt != 0)
+ if (priv->scanned_cnt != 0)
mod_timer(&priv->aging_timer,
jiffies + msecs_to_jiffies(AGING_TIME));
}
@@ -277,13 +272,13 @@ static int is_network_in_shadow(struct network_info *nw_info,
int state = -1;
int i;

- if (last_scanned_cnt == 0) {
+ if (priv->scanned_cnt == 0) {
mod_timer(&priv->aging_timer,
jiffies + msecs_to_jiffies(AGING_TIME));
state = -1;
} else {
- for (i = 0; i < last_scanned_cnt; i++) {
- if (memcmp(last_scanned_shadow[i].bssid,
+ for (i = 0; i < priv->scanned_cnt; i++) {
+ if (memcmp(priv->scanned_shadow[i].bssid,
nw_info->bssid, 6) == 0) {
state = i;
break;
@@ -301,16 +296,16 @@ static void add_network_to_shadow(struct network_info *nw_info,
u8 rssi_index = 0;
struct network_info *shadow_nw_info;

- if (last_scanned_cnt >= MAX_NUM_SCANNED_NETWORKS_SHADOW)
+ if (priv->scanned_cnt >= MAX_NUM_SCANNED_NETWORKS_SHADOW)
return;

if (ap_found == -1) {
- ap_index = last_scanned_cnt;
- last_scanned_cnt++;
+ ap_index = priv->scanned_cnt;
+ priv->scanned_cnt++;
} else {
ap_index = ap_found;
}
- shadow_nw_info = &last_scanned_shadow[ap_index];
+ shadow_nw_info = &priv->scanned_shadow[ap_index];
rssi_index = shadow_nw_info->rssi_history.index;
shadow_nw_info->rssi_history.samples[rssi_index++] = nw_info->rssi;
if (rssi_index == NUM_RSSI) {
@@ -402,7 +397,7 @@ static void cfg_scan_result(enum scan_event scan_event,
u32 i;

for (i = 0; i < priv->rcvd_ch_cnt; i++) {
- if (memcmp(last_scanned_shadow[i].bssid,
+ if (memcmp(priv->scanned_shadow[i].bssid,
network_info->bssid, 6) == 0)
break;
}
@@ -410,8 +405,8 @@ static void cfg_scan_result(enum scan_event scan_event,
if (i >= priv->rcvd_ch_cnt)
return;

- last_scanned_shadow[i].rssi = network_info->rssi;
- last_scanned_shadow[i].time_scan = jiffies;
+ priv->scanned_shadow[i].rssi = network_info->rssi;
+ priv->scanned_shadow[i].time_scan = jiffies;
}
} else if (scan_event == SCAN_EVENT_DONE) {
refresh_scan(priv, false);
@@ -437,7 +432,7 @@ static void cfg_scan_result(enum scan_event scan_event,
.aborted = false,
};

- update_scan_time();
+ update_scan_time(priv);
refresh_scan(priv, false);

cfg80211_scan_done(priv->scan_req, &info);
@@ -448,11 +443,11 @@ static void cfg_scan_result(enum scan_event scan_event,
}
}

-static inline bool wilc_wfi_cfg_scan_time_expired(int i)
+static inline bool wilc_cfg_scan_time_expired(struct wilc_priv *priv, int i)
{
unsigned long now = jiffies;

- if (time_after(now, last_scanned_shadow[i].time_scan_cached +
+ if (time_after(now, priv->scanned_shadow[i].time_scan_cached +
(unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ))))
return true;
else
@@ -501,11 +496,11 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt,
memcpy(priv->associated_bss, conn_info->bssid,
ETH_ALEN);

- for (i = 0; i < last_scanned_cnt; i++) {
- if (memcmp(last_scanned_shadow[i].bssid,
+ for (i = 0; i < priv->scanned_cnt; i++) {
+ if (memcmp(priv->scanned_shadow[i].bssid,
conn_info->bssid,
ETH_ALEN) == 0) {
- if (wilc_wfi_cfg_scan_time_expired(i))
+ if (wilc_cfg_scan_time_expired(priv, i))
scan_refresh = true;

break;
@@ -619,7 +614,7 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)

priv->rcvd_ch_cnt = 0;

- reset_shadow_found();
+ reset_shadow_found(priv);

priv->cfg_scanning = true;
if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) {
@@ -679,18 +674,18 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
else
wfi_drv->p2p_connect = 0;

- for (i = 0; i < last_scanned_cnt; i++) {
- if (sme->ssid_len == last_scanned_shadow[i].ssid_len &&
- memcmp(last_scanned_shadow[i].ssid,
+ for (i = 0; i < priv->scanned_cnt; i++) {
+ if (sme->ssid_len == priv->scanned_shadow[i].ssid_len &&
+ memcmp(priv->scanned_shadow[i].ssid,
sme->ssid,
sme->ssid_len) == 0) {
if (!sme->bssid) {
if (sel_bssi_idx == UINT_MAX ||
- last_scanned_shadow[i].rssi >
- last_scanned_shadow[sel_bssi_idx].rssi)
+ priv->scanned_shadow[i].rssi >
+ priv->scanned_shadow[sel_bssi_idx].rssi)
sel_bssi_idx = i;
} else {
- if (memcmp(last_scanned_shadow[i].bssid,
+ if (memcmp(priv->scanned_shadow[i].bssid,
sme->bssid,
ETH_ALEN) == 0) {
sel_bssi_idx = i;
@@ -700,8 +695,8 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
}
}

- if (sel_bssi_idx < last_scanned_cnt) {
- nw_info = &last_scanned_shadow[sel_bssi_idx];
+ if (sel_bssi_idx < priv->scanned_cnt) {
+ nw_info = &priv->scanned_shadow[sel_bssi_idx];
} else {
ret = -ENOENT;
wilc_connecting = 0;
@@ -2194,7 +2189,7 @@ int wilc_deinit_host_int(struct net_device *net)
ret = wilc_deinit(vif);

del_timer_sync(&priv->aging_timer);
- clear_shadow_scan();
+ clear_shadow_scan(priv);
if (op_ifcs == 0)
del_timer_sync(&wilc_during_ip_timer);

diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index a76b68c..3767e31 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -95,6 +95,8 @@ struct wilc_priv {
struct mutex scan_req_lock;
bool p2p_listen_state;
struct timer_list aging_timer;
+ struct network_info scanned_shadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
+ int scanned_cnt;
};

struct frame_reg {
--
2.7.4

2018-09-04 11:04:59

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 26/26] staging: wilc1000: remove handle_hif_exit_work() function

Cleanup to remove handle_hif_exit_work(), as after code refactoring its
not required anymore.

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

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 85113fb..5388be9 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -2593,14 +2593,6 @@ static void handle_remain_on_chan_work(struct work_struct *work)
kfree(msg);
}

-static void handle_hif_exit_work(struct work_struct *work)
-{
- struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
-
- /* free 'msg' data in caller */
- complete(&msg->work_comp);
-}
-
static void handle_scan_complete(struct work_struct *work)
{
struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
--
2.7.4

2018-09-04 11:04:25

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 16/26] staging: wilc1000: use lowercase for get_BSSID() and HIL variable

Cleanup patch to use lowercase name for get_BSSID() and HIL variable.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/coreconfigurator.c | 4 ++--
drivers/staging/wilc1000/wilc_wlan.c | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/wilc1000/coreconfigurator.c b/drivers/staging/wilc1000/coreconfigurator.c
index e542067..d6d3a97 100644
--- a/drivers/staging/wilc1000/coreconfigurator.c
+++ b/drivers/staging/wilc1000/coreconfigurator.c
@@ -116,7 +116,7 @@ static inline void get_address3(u8 *msa, u8 *addr)
memcpy(addr, msa + 16, 6);
}

-static inline void get_BSSID(u8 *data, u8 *bssid)
+static inline void get_bssid(u8 *data, u8 *bssid)
{
if (get_from_ds(data) == 1)
get_address2(data, bssid);
@@ -233,7 +233,7 @@ s32 wilc_parse_network_info(u8 *msg_buffer,
network_info->tsf_hi = tsf_lo | ((u64)tsf_hi << 32);

get_ssid(msa, network_info->ssid, &network_info->ssid_len);
- get_BSSID(msa, network_info->bssid);
+ get_bssid(msa, network_info->bssid);

network_info->ch = get_current_channel_802_11n(msa, rx_len
+ FCS_LEN);
diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index bf45b4c..d397c27 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -164,7 +164,7 @@ static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
struct wilc *wilc = vif->wilc;
const struct iphdr *ip_hdr_ptr;
const struct tcphdr *tcp_hdr_ptr;
- u32 IHL, total_length, data_offset;
+ u32 ihl, total_length, data_offset;

spin_lock_irqsave(&wilc->txq_spinlock, flags);

@@ -176,12 +176,12 @@ static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
if (ip_hdr_ptr->protocol != IPPROTO_TCP)
goto out;

- IHL = ip_hdr_ptr->ihl << 2;
- tcp_hdr_ptr = buffer + ETH_HLEN + IHL;
+ ihl = ip_hdr_ptr->ihl << 2;
+ tcp_hdr_ptr = buffer + ETH_HLEN + ihl;
total_length = ntohs(ip_hdr_ptr->tot_len);

data_offset = tcp_hdr_ptr->doff << 2;
- if (total_length == (IHL + data_offset)) {
+ if (total_length == (ihl + data_offset)) {
u32 seq_no, ack_no;

seq_no = ntohl(tcp_hdr_ptr->seq);
--
2.7.4

2018-09-04 11:03:39

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 03/26] staging: wilc1000: fix to use correct index to free scanned info in clear_shadow_scan()

Fixes to use correct index to free the allocated memory for ies
information. The check was done using 'last_scanned_cnt' index and its
not correct, so use the correct index ('i') to check for before freeing
the allocated memory.

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

diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index d853508..ede9134 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -165,9 +165,9 @@ static void clear_shadow_scan(void)
return;

for (i = 0; i < last_scanned_cnt; i++) {
- if (last_scanned_shadow[last_scanned_cnt].ies) {
+ if (last_scanned_shadow[i].ies) {
kfree(last_scanned_shadow[i].ies);
- last_scanned_shadow[last_scanned_cnt].ies = NULL;
+ last_scanned_shadow[i].ies = NULL;
}

kfree(last_scanned_shadow[i].join_params);
--
2.7.4

2018-09-11 14:19:43

by Claudiu Beznea

[permalink] [raw]
Subject: Re: [PATCH v2 25/26] staging: wilc1000: refactor wilc_netdev_init() to handle memory free in error path



On 04.09.2018 09:39, Ajay Singh wrote:
> Refactor the wilc_netdev_init() to cleanup the memory for error
> scenario and remove unnecessary 'dev' pointer check.
>
> Signed-off-by: Ajay Singh <[email protected]>
> ---
> drivers/staging/wilc1000/linux_wlan.c | 36 ++++++++++++++++-------
> drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 6 +++-
> 2 files changed, 30 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
> index d7d43fd..91a45a7 100644
> --- a/drivers/staging/wilc1000/linux_wlan.c
> +++ b/drivers/staging/wilc1000/linux_wlan.c
> @@ -1073,10 +1073,8 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
> INIT_LIST_HEAD(&wl->rxq_head.list);
>
> wl->hif_workqueue = create_singlethread_workqueue("WILC_wq");
> - if (!wl->hif_workqueue) {
> - kfree(wl);
> - return -ENOMEM;
> - }
> + if (!wl->hif_workqueue)
> + goto free_wl;
>
> register_inetaddr_notifier(&g_dev_notifier);
>
> @@ -1085,7 +1083,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
>
> ndev = alloc_etherdev(sizeof(struct wilc_vif));
> if (!ndev)
> - return -ENOMEM;
> + goto free_ndev;
>
> vif = netdev_priv(ndev);
> memset(vif, 0, sizeof(struct wilc_vif));
> @@ -1106,15 +1104,13 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
> ndev->netdev_ops = &wilc_netdev_ops;
>
> wdev = wilc_create_wiphy(ndev, dev);
> -
> - if (dev)
> - SET_NETDEV_DEV(ndev, dev);
> -
> if (!wdev) {
> netdev_err(ndev, "Can't register WILC Wiphy\n");
> - return -1;
> + goto free_ndev;
> }
>
> + SET_NETDEV_DEV(ndev, dev);
> +
> vif->ndev->ieee80211_ptr = wdev;
> vif->ndev->ml_priv = vif;
> wdev->netdev = vif->ndev;
> @@ -1125,11 +1121,29 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
>
> ret = register_netdev(ndev);
> if (ret)
> - return ret;
> + goto free_ndev;

In case this happens you will loose the return code of register_netdev()
and you will return instead -ENOMEM. Maybe, the best approach will be to
initialize ret = -ENOMEM while declaring it

>
> vif->iftype = STATION_MODE;
> vif->mac_opened = 0;
> }
>
> return 0;
> +
> +free_ndev:
> + for (; i >= 0; i--) {
> + if (wl->vif[i]) {
> + if (wl->vif[i]->iftype == STATION_MODE)
> + unregister_netdev(wl->vif[i]->ndev);
> +
> + if (wl->vif[i]->ndev) {
> + wilc_free_wiphy(wl->vif[i]->ndev);
> + free_netdev(wl->vif[i]->ndev);
> + }
> + }
> + }
> + unregister_inetaddr_notifier(&g_dev_notifier);
> + destroy_workqueue(wl->hif_workqueue);
> +free_wl:
> + kfree(wl);
> + return -ENOMEM;

and here to just return ret.

> }
> diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
> index d103dce2..37c26d4 100644
> --- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
> +++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
> @@ -2145,8 +2145,12 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net,
> set_wiphy_dev(wdev->wiphy, dev);
>
> ret = wiphy_register(wdev->wiphy);
> - if (ret)
> + if (ret) {
> netdev_err(net, "Cannot register wiphy device\n");
> + wiphy_free(wdev->wiphy);
> + kfree(wdev);
> + return NULL;
> + }
>
> priv->dev = net;
> return wdev;
>

2018-09-04 11:04:11

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 12/26] staging: wilc1000: move 'periodic_rssi' as part of 'wilc_vif' struct

Refactor code to move 'periodic_rssi' as part of wilc_vif struct. Move
'dummy_statistics' from 'wilc' struct to 'wilc_vif' to maintain for
each interface separately.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 19 ++++++++-----------
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 3 ++-
2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 6facffc..e79ef6c 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -190,8 +190,6 @@ static struct host_if_drv *terminated_handle;
static u8 p2p_listen_state;
static struct completion hif_driver_comp;
static struct mutex hif_deinit_lock;
-static struct timer_list periodic_rssi;
-static struct wilc_vif *periodic_rssi_vif;

static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];

@@ -3422,9 +3420,9 @@ int wilc_hif_set_cfg(struct wilc_vif *vif,
return result;
}

-static void get_periodic_rssi(struct timer_list *unused)
+static void get_periodic_rssi(struct timer_list *t)
{
- struct wilc_vif *vif = periodic_rssi_vif;
+ struct wilc_vif *vif = from_timer(vif, t, periodic_rssi);

if (!vif->hif_drv) {
netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
@@ -3432,9 +3430,9 @@ 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, false);
+ wilc_get_statistics(vif, &vif->dummy_statistics, false);

- mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000));
+ mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
}

int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
@@ -3468,12 +3466,11 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
kfree(hif_drv);
return -ENOMEM;
}
-
- periodic_rssi_vif = vif;
- timer_setup(&periodic_rssi, get_periodic_rssi, 0);
- mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000));
}

+ timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
+ mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
+
timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0);
timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0);
timer_setup(&hif_drv->remain_on_ch_timer, listen_timer_cb, 0);
@@ -3513,7 +3510,7 @@ int wilc_deinit(struct wilc_vif *vif)

del_timer_sync(&hif_drv->scan_timer);
del_timer_sync(&hif_drv->connect_timer);
- del_timer_sync(&periodic_rssi);
+ del_timer_sync(&vif->periodic_rssi);
del_timer_sync(&hif_drv->remain_on_ch_timer);

wilc_set_wfi_drv_handler(vif, 0, 0, 0);
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 77641eb..c103a07 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -120,6 +120,8 @@ struct wilc_vif {
u8 ifc_id;
struct timer_list during_ip_timer;
bool obtaining_ip;
+ struct timer_list periodic_rssi;
+ struct rf_info dummy_statistics;
};

struct wilc {
@@ -169,7 +171,6 @@ struct wilc {
struct device *dev;
bool suspend_event;

- struct rf_info dummy_statistics;
bool enable_ps;
int clients_count;
struct workqueue_struct *hif_workqueue;
--
2.7.4

2018-09-04 11:04:45

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 22/26] staging: wilc1000: move 'wilc_connecting' static variable to 'wilc_vif' struct

Move static variable 'wilc_connecting' as part of 'wilc_vif' private
struct. Remove "wilc_" prefix from name as its already part of wilc_vif
struct.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 4 ++--
drivers/staging/wilc1000/host_interface.h | 2 --
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 18 ++++++++----------
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 1 +
4 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 14dfa61..7805ec1 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -724,7 +724,7 @@ static void handle_scan(struct work_struct *work)
goto error;
}

- if (vif->obtaining_ip || wilc_connecting) {
+ if (vif->obtaining_ip || vif->connecting) {
netdev_err(vif->ndev, "Don't do obss scan\n");
result = -EBUSY;
goto error;
@@ -2330,7 +2330,7 @@ static int handle_remain_on_chan(struct wilc_vif *vif,
goto error;
}

- if (vif->obtaining_ip || wilc_connecting) {
+ if (vif->obtaining_ip || vif->connecting) {
result = -EBUSY;
goto error;
}
diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h
index 6006769..a48818f 100644
--- a/drivers/staging/wilc1000/host_interface.h
+++ b/drivers/staging/wilc1000/host_interface.h
@@ -361,6 +361,4 @@ int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power);

extern u8 wilc_connected_ssid[6];

-extern int wilc_connecting;
-
#endif
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 35a83d4..d103dce2 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -453,8 +453,6 @@ static inline bool wilc_cfg_scan_time_expired(struct wilc_priv *priv, int i)
return false;
}

-int wilc_connecting;
-
static void cfg_connect_result(enum conn_event conn_disconn_evt,
struct connect_info *conn_info,
u8 mac_status,
@@ -468,7 +466,7 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt,
struct host_if_drv *wfi_drv = priv->hif_drv;
u8 null_bssid[ETH_ALEN] = {0};

- wilc_connecting = 0;
+ vif->connecting = false;

if (conn_disconn_evt == CONN_DISCONN_EVENT_CONN_RESP) {
u16 connect_status;
@@ -666,7 +664,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
enum authtype auth_type = ANY;
u32 cipher_group;

- wilc_connecting = 1;
+ vif->connecting = true;

if (!(strncmp(sme->ssid, "DIRECT-", 7)))
wfi_drv->p2p_connect = 1;
@@ -698,7 +696,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
nw_info = &priv->scanned_shadow[sel_bssi_idx];
} else {
ret = -ENOENT;
- wilc_connecting = 0;
+ vif->connecting = false;
return ret;
}

@@ -741,7 +739,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
ret = -ENOTSUPP;
netdev_err(dev, "%s: Unsupported cipher\n",
__func__);
- wilc_connecting = 0;
+ vif->connecting = false;
return ret;
}
}
@@ -792,7 +790,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
if (ret != 0) {
netdev_err(dev, "wilc_set_join_req(): Error\n");
ret = -ENOENT;
- wilc_connecting = 0;
+ vif->connecting = false;
return ret;
}

@@ -809,7 +807,7 @@ static int disconnect(struct wiphy *wiphy, struct net_device *dev,
int ret;
u8 null_bssid[ETH_ALEN] = {0};

- wilc_connecting = 0;
+ vif->connecting = false;

if (!wilc)
return -EIO;
@@ -1747,7 +1745,7 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,

switch (type) {
case NL80211_IFTYPE_STATION:
- wilc_connecting = 0;
+ vif->connecting = false;
dev->ieee80211_ptr->iftype = type;
priv->wdev->iftype = type;
vif->monitor_flag = 0;
@@ -1762,7 +1760,7 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
break;

case NL80211_IFTYPE_P2P_CLIENT:
- wilc_connecting = 0;
+ vif->connecting = false;
dev->ieee80211_ptr->iftype = type;
priv->wdev->iftype = type;
vif->monitor_flag = 0;
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index ede967b..1837808 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -149,6 +149,7 @@ struct wilc_vif {
struct timer_list periodic_rssi;
struct rf_info periodic_stat;
struct tcp_ack_filter ack_filter;
+ bool connecting;
};

struct wilc {
--
2.7.4

2018-09-04 11:04:31

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 18/26] staging: wilc1000: avoid line over 80 chars in wilc_wlan_txq_filter_dup_tcp_ack()

Cleanup patch to avoid line over 80 chars checkpatch issue introduced in
previous code refactor commit.

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

diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index 52402c3..46db790 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -199,19 +199,20 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
unsigned long flags;

spin_lock_irqsave(&wilc->txq_spinlock, flags);
- for (i = f->pending_base; i < (f->pending_base + f->pending_acks); i++) {
- u32 session_index;
+ for (i = f->pending_base;
+ i < (f->pending_base + f->pending_acks); i++) {
+ u32 index;
u32 bigger_ack_num;

if (i >= MAX_PENDING_ACKS)
break;

- session_index = f->pending_acks_info[i].session_index;
+ index = f->pending_acks_info[i].session_index;

- if (session_index >= 2 * MAX_TCP_SESSION)
+ if (index >= 2 * MAX_TCP_SESSION)
break;

- bigger_ack_num = f->ack_session_info[session_index].bigger_ack_num;
+ bigger_ack_num = f->ack_session_info[index].bigger_ack_num;

if (f->pending_acks_info[i].ack_num < bigger_ack_num) {
struct txq_entry_t *tqe;
--
2.7.4

2018-09-04 11:03:37

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 02/26] staging: wilc1000: move 'aging_timer' static variable to wilc_priv struct

Moved 'aging_timer' to wilc_priv struct instead of having it as static
variable.
As 'aging_timer' is maintained for each interfaces so 'op_ifcs' check is
not required before the timer_setup() and del_timer_sync() call.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 25 ++++++++++++-----------
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 2 +-
2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 4727a8a..d853508 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -85,7 +85,6 @@ static const struct wiphy_wowlan_support wowlan_support = {
static struct network_info last_scanned_shadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
static u32 last_scanned_cnt;
struct timer_list wilc_during_ip_timer;
-static struct timer_list aging_timer;
static u8 op_ifcs;

#define CHAN2G(_channel, _freq, _flags) { \
@@ -165,8 +164,6 @@ static void clear_shadow_scan(void)
if (op_ifcs != 0)
return;

- del_timer_sync(&aging_timer);
-
for (i = 0; i < last_scanned_cnt; i++) {
if (last_scanned_shadow[last_scanned_cnt].ies) {
kfree(last_scanned_shadow[i].ies);
@@ -245,8 +242,9 @@ static void update_scan_time(void)
last_scanned_shadow[i].time_scan = jiffies;
}

-static void remove_network_from_shadow(struct timer_list *unused)
+static void remove_network_from_shadow(struct timer_list *t)
{
+ struct wilc_priv *priv = from_timer(priv, t, aging_timer);
unsigned long now = jiffies;
int i, j;

@@ -266,7 +264,8 @@ static void remove_network_from_shadow(struct timer_list *unused)
}

if (last_scanned_cnt != 0)
- mod_timer(&aging_timer, jiffies + msecs_to_jiffies(AGING_TIME));
+ mod_timer(&priv->aging_timer,
+ jiffies + msecs_to_jiffies(AGING_TIME));
}

static void clear_during_ip(struct timer_list *unused)
@@ -274,13 +273,15 @@ static void clear_during_ip(struct timer_list *unused)
wilc_optaining_ip = false;
}

-static int is_network_in_shadow(struct network_info *nw_info, void *user_void)
+static int is_network_in_shadow(struct network_info *nw_info,
+ struct wilc_priv *priv)
{
int state = -1;
int i;

if (last_scanned_cnt == 0) {
- mod_timer(&aging_timer, jiffies + msecs_to_jiffies(AGING_TIME));
+ mod_timer(&priv->aging_timer,
+ jiffies + msecs_to_jiffies(AGING_TIME));
state = -1;
} else {
for (i = 0; i < last_scanned_cnt; i++) {
@@ -295,9 +296,9 @@ static int is_network_in_shadow(struct network_info *nw_info, void *user_void)
}

static void add_network_to_shadow(struct network_info *nw_info,
- void *user_void, void *join_params)
+ struct wilc_priv *priv, void *join_params)
{
- int ap_found = is_network_in_shadow(nw_info, user_void);
+ int ap_found = is_network_in_shadow(nw_info, priv);
u32 ap_index = 0;
u8 rssi_index = 0;
struct network_info *shadow_nw_info;
@@ -2166,10 +2167,9 @@ int wilc_init_host_int(struct net_device *net)
int ret;
struct wilc_priv *priv = wdev_priv(net->ieee80211_ptr);

- if (op_ifcs == 0) {
- timer_setup(&aging_timer, remove_network_from_shadow, 0);
+ timer_setup(&priv->aging_timer, remove_network_from_shadow, 0);
+ if (op_ifcs == 0)
timer_setup(&wilc_during_ip_timer, clear_during_ip, 0);
- }
op_ifcs++;

priv->p2p_listen_state = false;
@@ -2195,6 +2195,7 @@ int wilc_deinit_host_int(struct net_device *net)
mutex_destroy(&priv->scan_req_lock);
ret = wilc_deinit(vif);

+ del_timer_sync(&priv->aging_timer);
clear_shadow_scan();
if (op_ifcs == 0)
del_timer_sync(&wilc_during_ip_timer);
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 8b74d61..a76b68c 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -94,7 +94,7 @@ struct wilc_priv {
/* mutexes */
struct mutex scan_req_lock;
bool p2p_listen_state;
-
+ struct timer_list aging_timer;
};

struct frame_reg {
--
2.7.4

2018-09-04 11:04:18

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 14/26] staging: wilc1000: move 'rcv_assoc_resp' as part of hif_drv

Avoid use of static variable and move 'rcv_assoc_resp' as part of
'hif_drv' struct. Rename from 'rcv_assoc_resp' to 'assoc_resp'.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 8 +++-----
drivers/staging/wilc1000/host_interface.h | 1 +
2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 18448fa..c3f2fc9 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -191,8 +191,6 @@ static u8 p2p_listen_state;
static struct completion hif_driver_comp;
static struct mutex hif_deinit_lock;

-static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];
-
static u8 set_ip[2][4];
static u8 get_ip[2][4];

@@ -1502,16 +1500,16 @@ static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
if (mac_status == MAC_STATUS_CONNECTED) {
u32 assoc_resp_info_len;

- memset(rcv_assoc_resp, 0, MAX_ASSOC_RESP_FRAME_SIZE);
+ memset(hif_drv->assoc_resp, 0, MAX_ASSOC_RESP_FRAME_SIZE);

- host_int_get_assoc_res_info(vif, rcv_assoc_resp,
+ host_int_get_assoc_res_info(vif, hif_drv->assoc_resp,
MAX_ASSOC_RESP_FRAME_SIZE,
&assoc_resp_info_len);

if (assoc_resp_info_len != 0) {
s32 err = 0;

- err = wilc_parse_assoc_resp_info(rcv_assoc_resp,
+ err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp,
assoc_resp_info_len,
&conn_info);
if (err)
diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h
index 4dd8510..12dec47 100644
--- a/drivers/staging/wilc1000/host_interface.h
+++ b/drivers/staging/wilc1000/host_interface.h
@@ -284,6 +284,7 @@ struct host_if_drv {

bool ifc_up;
int driver_handler_id;
+ u8 assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];
};

struct add_sta_param {
--
2.7.4

2018-09-04 11:04:52

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 24/26] staging: wilc1000: refactor code to move initilization in wilc_netdev_init()

Refactor code to move the initialization of wilc related parameters in
wilc_netdev_init() and move their deinitialization in
wilc_netdev_cleanup(). For 'hif_workqueue' creation 'clients_count' check
is not required as the single instance is maintained.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 23 -----------------------
drivers/staging/wilc1000/linux_wlan.c | 8 ++++++++
2 files changed, 8 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 9d90994..85113fb 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -3392,13 +3392,6 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
if (wilc->clients_count == 0) {
init_completion(&hif_driver_comp);
mutex_init(&hif_deinit_lock);
-
- wilc->hif_workqueue = create_singlethread_workqueue("WILC_wq");
- if (!wilc->hif_workqueue) {
- netdev_err(vif->ndev, "Failed to create workqueue\n");
- kfree(hif_drv);
- return -ENOMEM;
- }
}

timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
@@ -3458,22 +3451,6 @@ int wilc_deinit(struct wilc_vif *vif)

hif_drv->hif_state = HOST_IF_IDLE;

- if (vif->wilc->clients_count == 1) {
- struct host_if_msg *msg;
-
- msg = wilc_alloc_work(vif, handle_hif_exit_work, true);
- if (!IS_ERR(msg)) {
- result = wilc_enqueue_work(msg);
- if (result)
- netdev_err(vif->ndev, "deinit : Error(%d)\n",
- result);
- else
- wait_for_completion(&msg->work_comp);
- kfree(msg);
- }
- destroy_workqueue(vif->wilc->hif_workqueue);
- }
-
kfree(hif_drv);

vif->wilc->clients_count--;
diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 8c6b63a..d7d43fd 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -1036,6 +1036,8 @@ void wilc_netdev_cleanup(struct wilc *wilc)
}
}

+ flush_workqueue(wilc->hif_workqueue);
+ destroy_workqueue(wilc->hif_workqueue);
kfree(wilc);
wilc_debugfs_remove();
}
@@ -1070,6 +1072,12 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
INIT_LIST_HEAD(&wl->txq_head.list);
INIT_LIST_HEAD(&wl->rxq_head.list);

+ wl->hif_workqueue = create_singlethread_workqueue("WILC_wq");
+ if (!wl->hif_workqueue) {
+ kfree(wl);
+ return -ENOMEM;
+ }
+
register_inetaddr_notifier(&g_dev_notifier);

for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
--
2.7.4

2018-09-04 11:04:49

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 23/26] staging: wilc1000: remove unnecessary static variable 'p2p_listen_state'

Remove the use of unnecessary static variable 'p2p_listen_state'.
Already 'p2p_listen_state' is present in 'wilc_priv' struct. So making
use of that variable as its getting set in channel ready and
remain on channel expired callback.

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

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 7805ec1..9d90994 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -187,7 +187,6 @@ struct join_bss_param {
};

static struct host_if_drv *terminated_handle;
-static u8 p2p_listen_state;
static struct completion hif_driver_comp;
static struct mutex hif_deinit_lock;

@@ -2355,7 +2354,6 @@ static int handle_remain_on_chan(struct wilc_vif *vif,
netdev_err(vif->ndev, "Failed to set remain on channel\n");

error:
- p2p_listen_state = 1;
hif_drv->remain_on_ch_timer_vif = vif;
mod_timer(&hif_drv->remain_on_ch_timer,
jiffies + msecs_to_jiffies(hif_remain_ch->duration));
@@ -2411,8 +2409,9 @@ static void handle_listen_state_expired(struct work_struct *work)
struct wid wid;
int result;
struct host_if_drv *hif_drv = vif->hif_drv;
+ struct wilc_priv *priv = wdev_priv(vif->ndev->ieee80211_ptr);

- if (p2p_listen_state) {
+ if (priv->p2p_listen_state) {
remain_on_chan_flag = false;
wid.id = WID_REMAIN_ON_CHAN;
wid.type = WID_STR;
@@ -2437,7 +2436,6 @@ static void handle_listen_state_expired(struct work_struct *work)
hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
hif_remain_ch->id);
}
- p2p_listen_state = 0;
} else {
netdev_dbg(vif->ndev, "Not in listen state\n");
}
--
2.7.4

2018-09-04 11:04:07

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 11/26] staging: wilc1000: move hif_workqueue static variables to 'wilc' structure

Avoid use of static variable hif_workqueue and move it inside 'wilc'
structure.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 13 ++++++++-----
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 1 +
2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index f5617ac..6facffc 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -188,7 +188,6 @@ struct join_bss_param {

static struct host_if_drv *terminated_handle;
static u8 p2p_listen_state;
-static struct workqueue_struct *hif_workqueue;
static struct completion hif_driver_comp;
static struct mutex hif_deinit_lock;
static struct timer_list periodic_rssi;
@@ -226,7 +225,11 @@ wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
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))
+
+ if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue)
+ return -EINVAL;
+
+ if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work))
return -EINVAL;

return 0;
@@ -3459,8 +3462,8 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
init_completion(&hif_driver_comp);
mutex_init(&hif_deinit_lock);

- hif_workqueue = create_singlethread_workqueue("WILC_wq");
- if (!hif_workqueue) {
+ wilc->hif_workqueue = create_singlethread_workqueue("WILC_wq");
+ if (!wilc->hif_workqueue) {
netdev_err(vif->ndev, "Failed to create workqueue\n");
kfree(hif_drv);
return -ENOMEM;
@@ -3538,7 +3541,7 @@ int wilc_deinit(struct wilc_vif *vif)
wait_for_completion(&msg->work_comp);
kfree(msg);
}
- destroy_workqueue(hif_workqueue);
+ destroy_workqueue(vif->wilc->hif_workqueue);
}

kfree(hif_drv);
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 8cccbbc..77641eb 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -172,6 +172,7 @@ struct wilc {
struct rf_info dummy_statistics;
bool enable_ps;
int clients_count;
+ struct workqueue_struct *hif_workqueue;
};

struct wilc_wfi_mon_priv {
--
2.7.4

2018-09-04 11:04:28

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 17/26] staging: wilc1000: move tcp_ack_filter algo related variables to 'wilc_vif' struct

Avoid use of static variables and move them as part of wilc_vif struct.
Move all the parameters related to tcp_ack_filter algo to wilc_vif
struct.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 4 +-
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 4 +-
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 27 ++++++
drivers/staging/wilc1000/wilc_wlan.c | 107 +++++++++-------------
drivers/staging/wilc1000/wilc_wlan.h | 2 +-
5 files changed, 77 insertions(+), 67 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index c3f2fc9..b5d5b8e 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -2072,9 +2072,9 @@ static void handle_get_statistics(struct work_struct *work)

if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
stats->link_speed != DEFAULT_LINK_SPEED)
- wilc_enable_tcp_ack_filter(true);
+ wilc_enable_tcp_ack_filter(vif, true);
else if (stats->link_speed != DEFAULT_LINK_SPEED)
- wilc_enable_tcp_ack_filter(false);
+ wilc_enable_tcp_ack_filter(vif, false);

/* free 'msg' for async command, for sync caller will free it */
if (msg->is_sync)
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 3418d2d..35a83d4 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -1125,9 +1125,9 @@ static int get_station(struct wiphy *wiphy, struct net_device *dev,

if (stats.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
stats.link_speed != DEFAULT_LINK_SPEED)
- wilc_enable_tcp_ack_filter(true);
+ wilc_enable_tcp_ack_filter(vif, true);
else if (stats.link_speed != DEFAULT_LINK_SPEED)
- wilc_enable_tcp_ack_filter(false);
+ wilc_enable_tcp_ack_filter(vif, false);
}
return 0;
}
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index f20a2e3..09f619b 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -104,6 +104,32 @@ struct frame_reg {
bool reg;
};

+#define MAX_TCP_SESSION 25
+#define MAX_PENDING_ACKS 256
+
+struct ack_session_info {
+ u32 seq_num;
+ u32 bigger_ack_num;
+ u16 src_port;
+ u16 dst_port;
+ u16 status;
+};
+
+struct pending_acks_info {
+ u32 ack_num;
+ u32 session_index;
+ struct txq_entry_t *txqe;
+};
+
+struct tcp_ack_filter {
+ struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
+ struct pending_acks_info pending_acks_info[MAX_PENDING_ACKS];
+ u32 pending_base;
+ u32 tcp_session;
+ u32 pending_acks;
+ bool enabled;
+};
+
struct wilc_vif {
u8 idx;
u8 iftype;
@@ -122,6 +148,7 @@ struct wilc_vif {
bool obtaining_ip;
struct timer_list periodic_rssi;
struct rf_info periodic_stat;
+ struct tcp_ack_filter ack_filter;
};

struct wilc {
diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index d397c27..52402c3 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -93,63 +93,46 @@ static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
return 0;
}

-struct ack_session_info;
-struct ack_session_info {
- u32 seq_num;
- u32 bigger_ack_num;
- u16 src_port;
- u16 dst_port;
- u16 status;
-};
-
-struct pending_acks_info {
- u32 ack_num;
- u32 session_index;
- struct txq_entry_t *txqe;
-};
-
#define NOT_TCP_ACK (-1)

-#define MAX_TCP_SESSION 25
-#define MAX_PENDING_ACKS 256
-static struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
-static struct pending_acks_info pending_acks_info[MAX_PENDING_ACKS];
-
-static u32 pending_base;
-static u32 tcp_session;
-static u32 pending_acks;
-
-static inline int add_tcp_session(u32 src_prt, u32 dst_prt, u32 seq)
+static inline int add_tcp_session(struct wilc_vif *vif, u32 src_prt,
+ u32 dst_prt, u32 seq)
{
- if (tcp_session < 2 * MAX_TCP_SESSION) {
- ack_session_info[tcp_session].seq_num = seq;
- ack_session_info[tcp_session].bigger_ack_num = 0;
- ack_session_info[tcp_session].src_port = src_prt;
- ack_session_info[tcp_session].dst_port = dst_prt;
- tcp_session++;
+ struct tcp_ack_filter *f = &vif->ack_filter;
+
+ if (f->tcp_session < 2 * MAX_TCP_SESSION) {
+ f->ack_session_info[f->tcp_session].seq_num = seq;
+ f->ack_session_info[f->tcp_session].bigger_ack_num = 0;
+ f->ack_session_info[f->tcp_session].src_port = src_prt;
+ f->ack_session_info[f->tcp_session].dst_port = dst_prt;
+ f->tcp_session++;
}
return 0;
}

-static inline int update_tcp_session(u32 index, u32 ack)
+static inline int update_tcp_session(struct wilc_vif *vif, u32 index, u32 ack)
{
+ struct tcp_ack_filter *f = &vif->ack_filter;
+
if (index < 2 * MAX_TCP_SESSION &&
- ack > ack_session_info[index].bigger_ack_num)
- ack_session_info[index].bigger_ack_num = ack;
+ ack > f->ack_session_info[index].bigger_ack_num)
+ f->ack_session_info[index].bigger_ack_num = ack;
return 0;
}

-static inline int add_tcp_pending_ack(u32 ack, u32 session_index,
+static inline int add_tcp_pending_ack(struct wilc_vif *vif, u32 ack,
+ u32 session_index,
struct txq_entry_t *txqe)
{
- u32 i = pending_base + pending_acks;
+ struct tcp_ack_filter *f = &vif->ack_filter;
+ u32 i = f->pending_base + f->pending_acks;

if (i < MAX_PENDING_ACKS) {
- pending_acks_info[i].ack_num = ack;
- pending_acks_info[i].txqe = txqe;
- pending_acks_info[i].session_index = session_index;
+ f->pending_acks_info[i].ack_num = ack;
+ f->pending_acks_info[i].txqe = txqe;
+ f->pending_acks_info[i].session_index = session_index;
txqe->tcp_pending_ack_idx = i;
- pending_acks++;
+ f->pending_acks++;
}
return 0;
}
@@ -162,6 +145,7 @@ static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
unsigned long flags;
struct wilc_vif *vif = netdev_priv(dev);
struct wilc *wilc = vif->wilc;
+ struct tcp_ack_filter *f = &vif->ack_filter;
const struct iphdr *ip_hdr_ptr;
const struct tcphdr *tcp_hdr_ptr;
u32 ihl, total_length, data_offset;
@@ -186,19 +170,19 @@ static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)

seq_no = ntohl(tcp_hdr_ptr->seq);
ack_no = ntohl(tcp_hdr_ptr->ack_seq);
- for (i = 0; i < tcp_session; i++) {
- u32 j = ack_session_info[i].seq_num;
+ for (i = 0; i < f->tcp_session; i++) {
+ u32 j = f->ack_session_info[i].seq_num;

if (i < 2 * MAX_TCP_SESSION &&
j == seq_no) {
- update_tcp_session(i, ack_no);
+ update_tcp_session(vif, i, ack_no);
break;
}
}
- if (i == tcp_session)
- add_tcp_session(0, 0, seq_no);
+ if (i == f->tcp_session)
+ add_tcp_session(vif, 0, 0, seq_no);

- add_tcp_pending_ack(ack_no, i, tqe);
+ add_tcp_pending_ack(vif, ack_no, i, tqe);
}

out:
@@ -209,29 +193,30 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
{
struct wilc_vif *vif = netdev_priv(dev);
struct wilc *wilc = vif->wilc;
+ struct tcp_ack_filter *f = &vif->ack_filter;
u32 i = 0;
u32 dropped = 0;
unsigned long flags;

spin_lock_irqsave(&wilc->txq_spinlock, flags);
- for (i = pending_base; i < (pending_base + pending_acks); i++) {
+ for (i = f->pending_base; i < (f->pending_base + f->pending_acks); i++) {
u32 session_index;
u32 bigger_ack_num;

if (i >= MAX_PENDING_ACKS)
break;

- session_index = pending_acks_info[i].session_index;
+ session_index = f->pending_acks_info[i].session_index;

if (session_index >= 2 * MAX_TCP_SESSION)
break;

- bigger_ack_num = ack_session_info[session_index].bigger_ack_num;
+ bigger_ack_num = f->ack_session_info[session_index].bigger_ack_num;

- if (pending_acks_info[i].ack_num < bigger_ack_num) {
+ if (f->pending_acks_info[i].ack_num < bigger_ack_num) {
struct txq_entry_t *tqe;

- tqe = pending_acks_info[i].txqe;
+ tqe = f->pending_acks_info[i].txqe;
if (tqe) {
wilc_wlan_txq_remove(wilc, tqe);
tqe->status = 1;
@@ -243,13 +228,13 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
}
}
}
- pending_acks = 0;
- tcp_session = 0;
+ f->pending_acks = 0;
+ f->tcp_session = 0;

- if (pending_base == 0)
- pending_base = MAX_TCP_SESSION;
+ if (f->pending_base == 0)
+ f->pending_base = MAX_TCP_SESSION;
else
- pending_base = 0;
+ f->pending_base = 0;

spin_unlock_irqrestore(&wilc->txq_spinlock, flags);

@@ -262,11 +247,9 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
return 1;
}

-static bool enabled;
-
-void wilc_enable_tcp_ack_filter(bool value)
+void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value)
{
- enabled = value;
+ vif->ack_filter.enabled = value;
}

static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer,
@@ -324,7 +307,7 @@ int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
tqe->priv = priv;

tqe->tcp_pending_ack_idx = NOT_TCP_ACK;
- if (enabled)
+ if (vif->ack_filter.enabled)
tcp_process(dev, tqe);
wilc_wlan_txq_add_to_tail(dev, tqe);
return wilc->txq_entries;
@@ -686,7 +669,7 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count)
tqe->tx_complete_func(tqe->priv, tqe->status);
if (tqe->tcp_pending_ack_idx != NOT_TCP_ACK &&
tqe->tcp_pending_ack_idx < MAX_PENDING_ACKS)
- pending_acks_info[tqe->tcp_pending_ack_idx].txqe = NULL;
+ vif->ack_filter.pending_acks_info[tqe->tcp_pending_ack_idx].txqe = NULL;
kfree(tqe);
} while (--entries);

diff --git a/drivers/staging/wilc1000/wilc_wlan.h b/drivers/staging/wilc1000/wilc_wlan.h
index 1f874d1..0fdffdd 100644
--- a/drivers/staging/wilc1000/wilc_wlan.h
+++ b/drivers/staging/wilc1000/wilc_wlan.h
@@ -282,7 +282,7 @@ int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
u32 buffer_size, wilc_tx_complete_func_t func);
void wilc_chip_sleep_manually(struct wilc *wilc);

-void wilc_enable_tcp_ack_filter(bool value);
+void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value);
int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc);
netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *dev);

--
2.7.4

2018-09-04 11:03:32

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 01/26] staging: wilc1000: move 'wilc_enable_ps' global variable into 'wilc' struct

Instead of having 'wilc_enable_ps' as global variable moved it to 'wilc'
structure. Rename 'wilc_enable_ps' to 'enable_ps' as its already part of
'wilc' structure

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/linux_wlan.c | 5 ++---
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 10 +++++-----
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 1 +
drivers/staging/wilc1000/wilc_wlan.h | 1 -
4 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 01cf4bd..57e3176 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -12,8 +12,6 @@

#include "wilc_wfi_cfgoperations.h"

-bool wilc_enable_ps = true;
-
static int dev_state_ev_handler(struct notifier_block *this,
unsigned long event, void *ptr)
{
@@ -54,7 +52,7 @@ static int dev_state_ev_handler(struct notifier_block *this,
del_timer(&wilc_during_ip_timer);
}

- if (wilc_enable_ps)
+ if (vif->wilc->enable_ps)
wilc_set_power_mgmt(vif, 1, 0);

netdev_dbg(dev, "[%s] Up IP\n", dev_iface->ifa_label);
@@ -1066,6 +1064,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
*wilc = wl;
wl->io_type = io_type;
wl->hif_func = ops;
+ wl->enable_ps = true;
INIT_LIST_HEAD(&wl->txq_head.list);
INIT_LIST_HEAD(&wl->rxq_head.list);

diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 7cd0330..4727a8a 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -1732,7 +1732,7 @@ static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
if (!priv->hif_drv)
return -EIO;

- if (wilc_enable_ps)
+ if (vif->wilc->enable_ps)
wilc_set_power_mgmt(vif, enabled, timeout);

return 0;
@@ -1764,7 +1764,7 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
memset(priv->assoc_stainfo.sta_associated_bss, 0,
MAX_NUM_STA * ETH_ALEN);

- wilc_enable_ps = true;
+ wl->enable_ps = true;
wilc_set_power_mgmt(vif, 1, 0);
break;

@@ -1776,12 +1776,12 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
vif->iftype = CLIENT_MODE;
wilc_set_operation_mode(vif, STATION_MODE);

- wilc_enable_ps = false;
+ wl->enable_ps = false;
wilc_set_power_mgmt(vif, 0, 0);
break;

case NL80211_IFTYPE_AP:
- wilc_enable_ps = false;
+ wl->enable_ps = false;
dev->ieee80211_ptr->iftype = type;
priv->wdev->iftype = type;
vif->iftype = AP_MODE;
@@ -1803,7 +1803,7 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
priv->wdev->iftype = type;
vif->iftype = GO_MODE;

- wilc_enable_ps = false;
+ wl->enable_ps = false;
wilc_set_power_mgmt(vif, 0, 0);
break;

diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index b7eee77..8b74d61 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -166,6 +166,7 @@ struct wilc {
bool suspend_event;

struct rf_info dummy_statistics;
+ bool enable_ps;
};

struct wilc_wfi_mon_priv {
diff --git a/drivers/staging/wilc1000/wilc_wlan.h b/drivers/staging/wilc1000/wilc_wlan.h
index 7467188..1f874d1 100644
--- a/drivers/staging/wilc1000/wilc_wlan.h
+++ b/drivers/staging/wilc1000/wilc_wlan.h
@@ -289,7 +289,6 @@ netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *dev);
void wilc_wfi_p2p_rx(struct net_device *dev, u8 *buff, u32 size);
void host_wakeup_notify(struct wilc *wilc);
void host_sleep_notify(struct wilc *wilc);
-extern bool wilc_enable_ps;
void chip_allow_sleep(struct wilc *wilc);
void chip_wakeup(struct wilc *wilc);
int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
--
2.7.4

2018-09-04 11:04:21

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 15/26] staging: wilc1000: refactor tcp_process() to avoid extra leading tabs

Refactor tcp_process() to avoid unnecessary leading tabs in the
function.

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

diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index 6787b6e..bf45b4c 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -162,42 +162,46 @@ static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
unsigned long flags;
struct wilc_vif *vif = netdev_priv(dev);
struct wilc *wilc = vif->wilc;
+ const struct iphdr *ip_hdr_ptr;
+ const struct tcphdr *tcp_hdr_ptr;
+ u32 IHL, total_length, data_offset;

spin_lock_irqsave(&wilc->txq_spinlock, flags);

- if (eth_hdr_ptr->h_proto == htons(ETH_P_IP)) {
- const struct iphdr *ip_hdr_ptr = buffer + ETH_HLEN;
+ if (eth_hdr_ptr->h_proto != htons(ETH_P_IP))
+ goto out;

- if (ip_hdr_ptr->protocol == IPPROTO_TCP) {
- const struct tcphdr *tcp_hdr_ptr;
- u32 IHL, total_length, data_offset;
+ ip_hdr_ptr = buffer + ETH_HLEN;

- IHL = ip_hdr_ptr->ihl << 2;
- tcp_hdr_ptr = buffer + ETH_HLEN + IHL;
- total_length = ntohs(ip_hdr_ptr->tot_len);
+ if (ip_hdr_ptr->protocol != IPPROTO_TCP)
+ goto out;

- data_offset = tcp_hdr_ptr->doff << 2;
- if (total_length == (IHL + data_offset)) {
- u32 seq_no, ack_no;
+ IHL = ip_hdr_ptr->ihl << 2;
+ tcp_hdr_ptr = buffer + ETH_HLEN + IHL;
+ total_length = ntohs(ip_hdr_ptr->tot_len);

- seq_no = ntohl(tcp_hdr_ptr->seq);
- ack_no = ntohl(tcp_hdr_ptr->ack_seq);
- for (i = 0; i < tcp_session; i++) {
- u32 j = ack_session_info[i].seq_num;
+ data_offset = tcp_hdr_ptr->doff << 2;
+ if (total_length == (IHL + data_offset)) {
+ u32 seq_no, ack_no;

- if (i < 2 * MAX_TCP_SESSION &&
- j == seq_no) {
- update_tcp_session(i, ack_no);
- break;
- }
- }
- if (i == tcp_session)
- add_tcp_session(0, 0, seq_no);
+ seq_no = ntohl(tcp_hdr_ptr->seq);
+ ack_no = ntohl(tcp_hdr_ptr->ack_seq);
+ for (i = 0; i < tcp_session; i++) {
+ u32 j = ack_session_info[i].seq_num;

- add_tcp_pending_ack(ack_no, i, tqe);
+ if (i < 2 * MAX_TCP_SESSION &&
+ j == seq_no) {
+ update_tcp_session(i, ack_no);
+ break;
}
}
+ if (i == tcp_session)
+ add_tcp_session(0, 0, seq_no);
+
+ add_tcp_pending_ack(ack_no, i, tqe);
}
+
+out:
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
}

--
2.7.4

2018-09-04 11:03:50

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 06/26] staging: wilc1000: move during_ip_timer & wilc_optaining_ip to 'wilc_vif' struct

Move global variable 'wilc_during_ip_timer' and 'wilc_optaining_ip' to
'wilc_vif' structure.

Rename these variables like below

wilc_during_ip_timer -> during_ip_timer
wilc_optaining_ip -> obtaining_ip.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 15 +++++++-------
drivers/staging/wilc1000/host_interface.h | 2 --
drivers/staging/wilc1000/linux_wlan.c | 6 +++---
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 24 +++++++++++------------
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 2 ++
5 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 42d8acc..11eb632 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -186,7 +186,6 @@ struct join_bss_param {
};

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_driver_comp;
@@ -791,7 +790,7 @@ static void handle_scan(struct work_struct *work)
goto error;
}

- if (wilc_optaining_ip || wilc_connecting) {
+ if (vif->obtaining_ip || wilc_connecting) {
netdev_err(vif->ndev, "Don't do obss scan\n");
result = -EBUSY;
goto error;
@@ -1562,8 +1561,8 @@ static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,

hif_drv->hif_state = HOST_IF_CONNECTED;

- wilc_optaining_ip = true;
- mod_timer(&wilc_during_ip_timer,
+ vif->obtaining_ip = true;
+ mod_timer(&vif->during_ip_timer,
jiffies + msecs_to_jiffies(10000));
} else {
hif_drv->hif_state = HOST_IF_IDLE;
@@ -1595,7 +1594,7 @@ static inline void host_int_handle_disconnect(struct wilc_vif *vif)
disconn_info.ie_len = 0;

if (conn_result) {
- wilc_optaining_ip = false;
+ vif->obtaining_ip = false;
wilc_set_power_mgmt(vif, 0, 0);

conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL, 0,
@@ -1942,7 +1941,7 @@ static void handle_disconnect(struct work_struct *work)
wid.val = (s8 *)&dummy_reason_code;
wid.size = sizeof(char);

- wilc_optaining_ip = false;
+ vif->obtaining_ip = false;
wilc_set_power_mgmt(vif, 0, 0);

eth_zero_addr(wilc_connected_ssid);
@@ -2397,7 +2396,7 @@ static int handle_remain_on_chan(struct wilc_vif *vif,
goto error;
}

- if (wilc_optaining_ip || wilc_connecting) {
+ if (vif->obtaining_ip || wilc_connecting) {
result = -EBUSY;
goto error;
}
@@ -3455,7 +3454,7 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
break;
}

- wilc_optaining_ip = false;
+ vif->obtaining_ip = false;

if (clients_count == 0) {
init_completion(&hif_driver_comp);
diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h
index 84866a6..d026f44 100644
--- a/drivers/staging/wilc1000/host_interface.h
+++ b/drivers/staging/wilc1000/host_interface.h
@@ -361,11 +361,9 @@ int wilc_get_vif_idx(struct wilc_vif *vif);
int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power);
int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power);

-extern bool wilc_optaining_ip;
extern u8 wilc_connected_ssid[6];
extern u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];

extern int wilc_connecting;
-extern struct timer_list wilc_during_ip_timer;

#endif
diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 57e3176..283bb74 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -48,8 +48,8 @@ static int dev_state_ev_handler(struct notifier_block *this,
case NETDEV_UP:
if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) {
hif_drv->ifc_up = 1;
- wilc_optaining_ip = false;
- del_timer(&wilc_during_ip_timer);
+ vif->obtaining_ip = false;
+ del_timer(&vif->during_ip_timer);
}

if (vif->wilc->enable_ps)
@@ -68,7 +68,7 @@ static int dev_state_ev_handler(struct notifier_block *this,
case NETDEV_DOWN:
if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) {
hif_drv->ifc_up = 0;
- wilc_optaining_ip = false;
+ vif->obtaining_ip = false;
}

if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 1eac244..1690890 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -82,7 +82,6 @@ static const struct wiphy_wowlan_support wowlan_support = {
.flags = WIPHY_WOWLAN_ANY
};

-struct timer_list wilc_during_ip_timer;
static u8 op_ifcs;

#define CHAN2G(_channel, _freq, _flags) { \
@@ -261,9 +260,11 @@ static void remove_network_from_shadow(struct timer_list *t)
jiffies + msecs_to_jiffies(AGING_TIME));
}

-static void clear_during_ip(struct timer_list *unused)
+static void clear_during_ip(struct timer_list *t)
{
- wilc_optaining_ip = false;
+ struct wilc_vif *vif = from_timer(vif, t, during_ip_timer);
+
+ vif->obtaining_ip = false;
}

static int is_network_in_shadow(struct network_info *nw_info,
@@ -518,7 +519,7 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt,
conn_info->resp_ies_len, connect_status,
GFP_KERNEL);
} else if (conn_disconn_evt == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
- wilc_optaining_ip = false;
+ vif->obtaining_ip = false;
p2p_local_random = 0x01;
p2p_recv_random = 0x00;
wilc_ie = false;
@@ -1743,8 +1744,8 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
p2p_local_random = 0x01;
p2p_recv_random = 0x00;
wilc_ie = false;
- wilc_optaining_ip = false;
- del_timer(&wilc_during_ip_timer);
+ vif->obtaining_ip = false;
+ del_timer(&vif->during_ip_timer);

switch (type) {
case NL80211_IFTYPE_STATION:
@@ -1789,8 +1790,8 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
break;

case NL80211_IFTYPE_P2P_GO:
- wilc_optaining_ip = true;
- mod_timer(&wilc_during_ip_timer,
+ vif->obtaining_ip = true;
+ mod_timer(&vif->during_ip_timer,
jiffies + msecs_to_jiffies(DURING_IP_TIME_OUT));
wilc_set_operation_mode(vif, AP_MODE);
dev->ieee80211_ptr->iftype = type;
@@ -2159,10 +2160,10 @@ int wilc_init_host_int(struct net_device *net)
{
int ret;
struct wilc_priv *priv = wdev_priv(net->ieee80211_ptr);
+ struct wilc_vif *vif = netdev_priv(priv->dev);

timer_setup(&priv->aging_timer, remove_network_from_shadow, 0);
- if (op_ifcs == 0)
- timer_setup(&wilc_during_ip_timer, clear_during_ip, 0);
+ timer_setup(&vif->during_ip_timer, clear_during_ip, 0);
op_ifcs++;

priv->p2p_listen_state = false;
@@ -2190,8 +2191,7 @@ int wilc_deinit_host_int(struct net_device *net)

del_timer_sync(&priv->aging_timer);
clear_shadow_scan(priv);
- if (op_ifcs == 0)
- del_timer_sync(&wilc_during_ip_timer);
+ del_timer_sync(&vif->during_ip_timer);

if (ret)
netdev_err(net, "Error while deinitializing host interface\n");
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 3767e31..8e56a28 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -118,6 +118,8 @@ struct wilc_vif {
struct net_device *ndev;
u8 mode;
u8 ifc_id;
+ struct timer_list during_ip_timer;
+ bool obtaining_ip;
};

struct wilc {
--
2.7.4

2018-09-04 11:03:43

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 04/26] staging: wilc1000: remove unnecessary NULL check in clear_shadow_scan()

Cleanup patch to remove the unnecessary NULL check before freeing up ies
information in clear_shadow_scan().

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

diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index ede9134..00a167b 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -165,10 +165,8 @@ static void clear_shadow_scan(void)
return;

for (i = 0; i < last_scanned_cnt; i++) {
- if (last_scanned_shadow[i].ies) {
- kfree(last_scanned_shadow[i].ies);
- last_scanned_shadow[i].ies = NULL;
- }
+ kfree(last_scanned_shadow[i].ies);
+ last_scanned_shadow[i].ies = NULL;

kfree(last_scanned_shadow[i].join_params);
last_scanned_shadow[i].join_params = NULL;
--
2.7.4

2018-09-04 11:04:56

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 25/26] staging: wilc1000: refactor wilc_netdev_init() to handle memory free in error path

Refactor the wilc_netdev_init() to cleanup the memory for error
scenario and remove unnecessary 'dev' pointer check.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/linux_wlan.c | 36 ++++++++++++++++-------
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 6 +++-
2 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index d7d43fd..91a45a7 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -1073,10 +1073,8 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
INIT_LIST_HEAD(&wl->rxq_head.list);

wl->hif_workqueue = create_singlethread_workqueue("WILC_wq");
- if (!wl->hif_workqueue) {
- kfree(wl);
- return -ENOMEM;
- }
+ if (!wl->hif_workqueue)
+ goto free_wl;

register_inetaddr_notifier(&g_dev_notifier);

@@ -1085,7 +1083,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,

ndev = alloc_etherdev(sizeof(struct wilc_vif));
if (!ndev)
- return -ENOMEM;
+ goto free_ndev;

vif = netdev_priv(ndev);
memset(vif, 0, sizeof(struct wilc_vif));
@@ -1106,15 +1104,13 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
ndev->netdev_ops = &wilc_netdev_ops;

wdev = wilc_create_wiphy(ndev, dev);
-
- if (dev)
- SET_NETDEV_DEV(ndev, dev);
-
if (!wdev) {
netdev_err(ndev, "Can't register WILC Wiphy\n");
- return -1;
+ goto free_ndev;
}

+ SET_NETDEV_DEV(ndev, dev);
+
vif->ndev->ieee80211_ptr = wdev;
vif->ndev->ml_priv = vif;
wdev->netdev = vif->ndev;
@@ -1125,11 +1121,29 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,

ret = register_netdev(ndev);
if (ret)
- return ret;
+ goto free_ndev;

vif->iftype = STATION_MODE;
vif->mac_opened = 0;
}

return 0;
+
+free_ndev:
+ for (; i >= 0; i--) {
+ if (wl->vif[i]) {
+ if (wl->vif[i]->iftype == STATION_MODE)
+ unregister_netdev(wl->vif[i]->ndev);
+
+ if (wl->vif[i]->ndev) {
+ wilc_free_wiphy(wl->vif[i]->ndev);
+ free_netdev(wl->vif[i]->ndev);
+ }
+ }
+ }
+ unregister_inetaddr_notifier(&g_dev_notifier);
+ destroy_workqueue(wl->hif_workqueue);
+free_wl:
+ kfree(wl);
+ return -ENOMEM;
}
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index d103dce2..37c26d4 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -2145,8 +2145,12 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net,
set_wiphy_dev(wdev->wiphy, dev);

ret = wiphy_register(wdev->wiphy);
- if (ret)
+ if (ret) {
netdev_err(net, "Cannot register wiphy device\n");
+ wiphy_free(wdev->wiphy);
+ kfree(wdev);
+ return NULL;
+ }

priv->dev = net;
return wdev;
--
2.7.4

2018-09-04 11:04:14

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 13/26] staging: wilc1000: rename 'dummy_statistics' variable to 'periodic_stat'

Cleanup patch to use appropriate variable name to fetch the periodic
statistics.

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

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index e79ef6c..18448fa 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -3430,7 +3430,7 @@ static void get_periodic_rssi(struct timer_list *t)
}

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

mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
}
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index c103a07..f20a2e3 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -121,7 +121,7 @@ struct wilc_vif {
struct timer_list during_ip_timer;
bool obtaining_ip;
struct timer_list periodic_rssi;
- struct rf_info dummy_statistics;
+ struct rf_info periodic_stat;
};

struct wilc {
--
2.7.4

2018-09-04 11:04:42

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 20/26] staging: wilc1000: remove unused code to set and get IP address

Cleanup code to remove the variables related to setting and getting IP
address as this case was not handled from firmware side.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 105 ------------------------------
drivers/staging/wilc1000/host_interface.h | 3 -
drivers/staging/wilc1000/linux_wlan.c | 3 -
3 files changed, 111 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index b5d5b8e..14dfa61 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -191,11 +191,6 @@ static u8 p2p_listen_state;
static struct completion hif_driver_comp;
static struct mutex hif_deinit_lock;

-static u8 set_ip[2][4];
-static u8 get_ip[2][4];
-
-static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
-
/* '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 *),
@@ -348,64 +343,6 @@ static void handle_set_operation_mode(struct work_struct *work)
kfree(msg);
}

-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;
- struct wid wid;
- char firmware_ip_addr[4] = {0};
-
- if (ip_addr[0] < 192)
- ip_addr[0] = 0;
-
- memcpy(set_ip[idx], ip_addr, IP_ALEN);
-
- wid.id = WID_IP_ADDRESS;
- wid.type = WID_STR;
- wid.val = ip_addr;
- wid.size = IP_ALEN;
-
- ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
- wilc_get_vif_idx(vif));
-
- host_int_get_ipaddress(vif, firmware_ip_addr, idx);
-
- if (ret)
- netdev_err(vif->ndev, "Failed to set IP address\n");
- kfree(msg);
-}
-
-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;
- struct wid wid;
-
- wid.id = WID_IP_ADDRESS;
- wid.type = WID_STR;
- wid.val = kmalloc(IP_ALEN, GFP_KERNEL);
- wid.size = IP_ALEN;
-
- ret = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
- wilc_get_vif_idx(vif));
-
- memcpy(get_ip[idx], wid.val, IP_ALEN);
-
- kfree(wid.val);
-
- if (memcmp(get_ip[idx], set_ip[idx], IP_ALEN) != 0)
- wilc_setup_ipaddress(vif, set_ip[idx], idx);
-
- if (ret)
- netdev_err(vif->ndev, "Failed to get IP address\n");
- kfree(msg);
-}
-
static void handle_get_mac_address(struct work_struct *work)
{
struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
@@ -4008,48 +3945,6 @@ int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, u32 count,
return result;
}

-int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
-{
- int result;
- struct host_if_msg *msg;
-
- msg = wilc_alloc_work(vif, handle_set_ip_address, false);
- if (IS_ERR(msg))
- return PTR_ERR(msg);
-
- msg->body.ip_info.ip_addr = ip_addr;
- msg->body.ip_info.idx = idx;
-
- result = wilc_enqueue_work(msg);
- if (result) {
- netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
- kfree(msg);
- }
-
- return result;
-}
-
-static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
-{
- int result;
- struct host_if_msg *msg;
-
- msg = wilc_alloc_work(vif, handle_get_ip_address, false);
- if (IS_ERR(msg))
- return PTR_ERR(msg);
-
- msg->body.ip_info.ip_addr = ip_addr;
- msg->body.ip_info.idx = idx;
-
- result = wilc_enqueue_work(msg);
- if (result) {
- netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
- kfree(msg);
- }
-
- return result;
-}
-
int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
{
int ret;
diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h
index 12dec47..6006769 100644
--- a/drivers/staging/wilc1000/host_interface.h
+++ b/drivers/staging/wilc1000/host_interface.h
@@ -9,8 +9,6 @@
#include <linux/ieee80211.h>
#include "coreconfigurator.h"

-#define IP_ALEN 4
-
#define IDLE_MODE 0x00
#define AP_MODE 0x01
#define STATION_MODE 0x02
@@ -344,7 +342,6 @@ int wilc_edit_station(struct wilc_vif *vif,
int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout);
int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, u32 count,
u8 *mc_list);
-int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
u32 duration, u16 chan,
wilc_remain_on_chan_expired expired,
diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 1cea065..1300318 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -61,7 +61,6 @@ static int dev_state_ev_handler(struct notifier_block *this,
netdev_dbg(dev, "IP add=%d:%d:%d:%d\n",
ip_addr_buf[0], ip_addr_buf[1],
ip_addr_buf[2], ip_addr_buf[3]);
- wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx);

break;

@@ -83,8 +82,6 @@ static int dev_state_ev_handler(struct notifier_block *this,
ip_addr_buf[0], ip_addr_buf[1],
ip_addr_buf[2], ip_addr_buf[3]);

- wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx);
-
break;

default:
--
2.7.4

2018-09-04 11:04:01

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 09/26] staging: wilc1000: move static variable clients_count to 'wilc' structure

Avoid use of static variable 'clients_count' and move it part of 'wilc'
structure.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 9 ++++-----
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 1 +
2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 6225e67..d930f06 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -199,7 +199,6 @@ static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];

static u8 set_ip[2][4];
static u8 get_ip[2][4];
-static u32 clients_count;

static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);

@@ -3456,7 +3455,7 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)

vif->obtaining_ip = false;

- if (clients_count == 0) {
+ if (wilc->clients_count == 0) {
init_completion(&hif_driver_comp);
mutex_init(&hif_deinit_lock);

@@ -3490,7 +3489,7 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)

mutex_unlock(&hif_drv->cfg_values_lock);

- clients_count++;
+ wilc->clients_count++;

return 0;
}
@@ -3526,7 +3525,7 @@ int wilc_deinit(struct wilc_vif *vif)

hif_drv->hif_state = HOST_IF_IDLE;

- if (clients_count == 1) {
+ if (vif->wilc->clients_count == 1) {
struct host_if_msg *msg;

msg = wilc_alloc_work(vif, handle_hif_exit_work, true);
@@ -3544,7 +3543,7 @@ int wilc_deinit(struct wilc_vif *vif)

kfree(hif_drv);

- clients_count--;
+ vif->wilc->clients_count--;
terminated_handle = NULL;
mutex_unlock(&hif_deinit_lock);
return result;
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 8e56a28..8cccbbc 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -171,6 +171,7 @@ struct wilc {

struct rf_info dummy_statistics;
bool enable_ps;
+ int clients_count;
};

struct wilc_wfi_mon_priv {
--
2.7.4

2018-09-04 11:03:57

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 08/26] staging: wilc1000: avoid use of extra 'if' condition in wilc_init()

Cleanup patch to avoid the avoid extra 'if' condition and clubbed the
same condition in single 'if' block.

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

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 11eb632..6225e67 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -3459,9 +3459,7 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
if (clients_count == 0) {
init_completion(&hif_driver_comp);
mutex_init(&hif_deinit_lock);
- }

- if (clients_count == 0) {
hif_workqueue = create_singlethread_workqueue("WILC_wq");
if (!hif_workqueue) {
netdev_err(vif->ndev, "Failed to create workqueue\n");
--
2.7.4

2018-09-04 11:04:04

by Ajay Singh

[permalink] [raw]
Subject: [PATCH v2 10/26] staging: wilc1000: refactor code to avoid use of wilc_set_multicast_list global

Refactor the code to avoid use of 'wilc_set_multicast_list' global
variable. Allocate the memory required to keep the multicast mac address
and pass it to the worker thread.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 13 +++++++------
drivers/staging/wilc1000/host_interface.h | 5 ++---
drivers/staging/wilc1000/linux_wlan.c | 28 ++++++++++++++++------------
3 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index d930f06..f5617ac 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -90,6 +90,7 @@ struct beacon_attr {
struct set_multicast {
bool enabled;
u32 cnt;
+ u8 *mc_list;
};

struct del_all_sta {
@@ -193,8 +194,6 @@ static struct mutex hif_deinit_lock;
static struct timer_list periodic_rssi;
static struct wilc_vif *periodic_rssi_vif;

-u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
-
static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];

static u8 set_ip[2][4];
@@ -2587,8 +2586,8 @@ static void handle_set_mcast_filter(struct work_struct *work)
*cur_byte++ = ((hif_set_mc->cnt >> 16) & 0xFF);
*cur_byte++ = ((hif_set_mc->cnt >> 24) & 0xFF);

- if (hif_set_mc->cnt > 0)
- memcpy(cur_byte, wilc_multicast_mac_addr_list,
+ if (hif_set_mc->cnt > 0 && hif_set_mc->mc_list)
+ memcpy(cur_byte, hif_set_mc->mc_list,
((hif_set_mc->cnt) * ETH_ALEN));

result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
@@ -2597,6 +2596,7 @@ static void handle_set_mcast_filter(struct work_struct *work)
netdev_err(vif->ndev, "Failed to send setup multicast\n");

error:
+ kfree(hif_set_mc->mc_list);
kfree(wid.val);
kfree(msg);
}
@@ -3988,8 +3988,8 @@ int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
return result;
}

-int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled,
- u32 count)
+int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, u32 count,
+ u8 *mc_list)
{
int result;
struct host_if_msg *msg;
@@ -4000,6 +4000,7 @@ int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled,

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

result = wilc_enqueue_work(msg);
if (result) {
diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h
index d026f44..4dd8510 100644
--- a/drivers/staging/wilc1000/host_interface.h
+++ b/drivers/staging/wilc1000/host_interface.h
@@ -341,8 +341,8 @@ int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr);
int wilc_edit_station(struct wilc_vif *vif,
struct add_sta_param *sta_param);
int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout);
-int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled,
- u32 count);
+int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, u32 count,
+ u8 *mc_list);
int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
u32 duration, u16 chan,
@@ -362,7 +362,6 @@ int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power);
int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power);

extern u8 wilc_connected_ssid[6];
-extern u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];

extern int wilc_connecting;

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 283bb74..1cea065 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -806,34 +806,38 @@ static void wilc_set_multicast_list(struct net_device *dev)
struct netdev_hw_addr *ha;
struct wilc_vif *vif = netdev_priv(dev);
int i = 0;
+ u8 *mc_list;
+ int res;

if (dev->flags & IFF_PROMISC)
return;

if (dev->flags & IFF_ALLMULTI ||
dev->mc.count > WILC_MULTICAST_TABLE_SIZE) {
- wilc_setup_multicast_filter(vif, false, 0);
+ wilc_setup_multicast_filter(vif, false, 0, NULL);
return;
}

if (dev->mc.count == 0) {
- wilc_setup_multicast_filter(vif, true, 0);
+ wilc_setup_multicast_filter(vif, true, 0, NULL);
return;
}

+ mc_list = kmalloc(dev->mc.count * ETH_ALEN, GFP_KERNEL);
+ if (!mc_list)
+ return;
+
netdev_for_each_mc_addr(ha, dev) {
- memcpy(wilc_multicast_mac_addr_list[i], ha->addr, ETH_ALEN);
- netdev_dbg(dev, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
- wilc_multicast_mac_addr_list[i][0],
- wilc_multicast_mac_addr_list[i][1],
- wilc_multicast_mac_addr_list[i][2],
- wilc_multicast_mac_addr_list[i][3],
- wilc_multicast_mac_addr_list[i][4],
- wilc_multicast_mac_addr_list[i][5]);
- i++;
+ memcpy(mc_list + i, ha->addr, ETH_ALEN);
+ netdev_dbg(dev, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i/ETH_ALEN,
+ mc_list[i], mc_list[i + 1], mc_list[i + 2],
+ mc_list[i + 3], mc_list[i + 4], mc_list[i + 5]);
+ i += ETH_ALEN;
}

- wilc_setup_multicast_filter(vif, true, (dev->mc.count));
+ res = wilc_setup_multicast_filter(vif, true, dev->mc.count, mc_list);
+ if (res)
+ kfree(mc_list);
}

static void linux_wlan_tx_complete(void *priv, int status)
--
2.7.4