[PATCH] staging/wilc1000: Convert timers to use timer_setup()

2017-10-16 Thread Kees Cook
As part of removing the timer_list.data field, this converts the wilc1000
driver to using from_timer and an explicit per-timer data field, since
there doesn't appear to be a way to sanely resolve vif from hif_drv.

Cc: Aditya Shankar 
Cc: Ganesh Krishna 
Cc: Greg Kroah-Hartman 
Cc: linux-wireless@vger.kernel.org
Cc: de...@driverdev.osuosl.org
Signed-off-by: Kees Cook 
---
 drivers/staging/wilc1000/host_interface.c | 39 +--
 drivers/staging/wilc1000/host_interface.h |  5 +++
 drivers/staging/wilc1000/wilc_wfi_cfgoperations.c |  4 +--
 3 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c 
b/drivers/staging/wilc1000/host_interface.c
index 7b620658ec38..c16f96308a97 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -238,6 +238,7 @@ static struct completion hif_driver_comp;
 static struct completion hif_wait_response;
 static struct mutex hif_deinit_lock;
 static struct timer_list periodic_rssi;
+static struct wilc_vif *periodic_rssi_vif;
 
 u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
 
@@ -2272,7 +2273,7 @@ static int Handle_RemainOnChan(struct wilc_vif *vif,
 ERRORHANDLER:
{
P2P_LISTEN_STATE = 1;
-   hif_drv->remain_on_ch_timer.data = (unsigned long)vif;
+   hif_drv->remain_on_ch_timer_vif = vif;
mod_timer(_drv->remain_on_ch_timer,
  jiffies +
  msecs_to_jiffies(pstrHostIfRemainOnChan->duration));
@@ -2360,11 +2361,13 @@ static u32 Handle_ListenStateExpired(struct wilc_vif 
*vif,
return result;
 }
 
-static void ListenTimerCB(unsigned long arg)
+static void ListenTimerCB(struct timer_list *t)
 {
+   struct host_if_drv *hif_drv = from_timer(hif_drv, t,
+ remain_on_ch_timer);
+   struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
s32 result = 0;
struct host_if_msg msg;
-   struct wilc_vif *vif = (struct wilc_vif *)arg;
 
del_timer(>hif_drv->remain_on_ch_timer);
 
@@ -2643,9 +2646,10 @@ static void host_if_work(struct work_struct *work)
complete(_thread_comp);
 }
 
-static void TimerCB_Scan(unsigned long arg)
+static void TimerCB_Scan(struct timer_list *t)
 {
-   struct wilc_vif *vif = (struct wilc_vif *)arg;
+   struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
+   struct wilc_vif *vif = hif_drv->scan_timer_vif;
struct host_if_msg msg;
 
memset(, 0, sizeof(struct host_if_msg));
@@ -2655,9 +2659,11 @@ static void TimerCB_Scan(unsigned long arg)
wilc_enqueue_cmd();
 }
 
-static void TimerCB_Connect(unsigned long arg)
+static void TimerCB_Connect(struct timer_list *t)
 {
-   struct wilc_vif *vif = (struct wilc_vif *)arg;
+   struct host_if_drv *hif_drv = from_timer(hif_drv, t,
+ connect_timer);
+   struct wilc_vif *vif = hif_drv->connect_timer_vif;
struct host_if_msg msg;
 
memset(, 0, sizeof(struct host_if_msg));
@@ -3040,7 +3046,7 @@ int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, 
const u8 *ssid,
return -EFAULT;
}
 
-   hif_drv->connect_timer.data = (unsigned long)vif;
+   hif_drv->connect_timer_vif = vif;
mod_timer(_drv->connect_timer,
  jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT));
 
@@ -3283,7 +3289,7 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 
scan_type,
return -EINVAL;
}
 
-   hif_drv->scan_timer.data = (unsigned long)vif;
+   hif_drv->scan_timer_vif = vif;
mod_timer(_drv->scan_timer,
  jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT));
 
@@ -3309,9 +3315,9 @@ int wilc_hif_set_cfg(struct wilc_vif *vif,
return wilc_enqueue_cmd();
 }
 
-static void GetPeriodicRSSI(unsigned long arg)
+static void GetPeriodicRSSI(struct timer_list *unused)
 {
-   struct wilc_vif *vif = (struct wilc_vif *)arg;
+   struct wilc_vif *vif = periodic_rssi_vif;
 
if (!vif->hif_drv) {
netdev_err(vif->ndev, "Driver handler is NULL\n");
@@ -3321,7 +3327,6 @@ static void GetPeriodicRSSI(unsigned long arg)
if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
wilc_get_statistics(vif, >wilc->dummy_statistics);
 
-   periodic_rssi.data = (unsigned long)vif;
mod_timer(_rssi, jiffies + msecs_to_jiffies(5000));
 }
 
@@ -3374,14 +3379,14 @@ int wilc_init(struct net_device *dev, struct 
host_if_drv **hif_drv_handler)
goto _fail_;
}
 
-   setup_timer(_rssi, GetPeriodicRSSI,
-   (unsigned long)vif);
+   periodic_rssi_vif = 

[PATCH] staging/wilc1000: Convert timers to use timer_setup()

2017-10-04 Thread Kees Cook
As part of removing the timer_list.data field, this converts the wilc1000
driver to using from_timer and an explicit per-timer data field, since
there doesn't appear to be a way to sanely resolve vif from hif_drv.

Cc: Aditya Shankar 
Cc: Ganesh Krishna 
Cc: Greg Kroah-Hartman 
Cc: linux-wireless@vger.kernel.org
Cc: de...@driverdev.osuosl.org
Cc: Thomas Gleixner 
Signed-off-by: Kees Cook 
---
This requires commit 686fef928bba ("timer: Prepare to change timer
callback argument type") in v4.14-rc3, but should be otherwise
stand-alone.
---
 drivers/staging/wilc1000/host_interface.c | 39 +--
 drivers/staging/wilc1000/host_interface.h |  5 
 2 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c 
b/drivers/staging/wilc1000/host_interface.c
index 7b620658ec38..c16f96308a97 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -238,6 +238,7 @@ static struct completion hif_driver_comp;
 static struct completion hif_wait_response;
 static struct mutex hif_deinit_lock;
 static struct timer_list periodic_rssi;
+static struct wilc_vif *periodic_rssi_vif;
 
 u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
 
@@ -2272,7 +2273,7 @@ static int Handle_RemainOnChan(struct wilc_vif *vif,
 ERRORHANDLER:
{
P2P_LISTEN_STATE = 1;
-   hif_drv->remain_on_ch_timer.data = (unsigned long)vif;
+   hif_drv->remain_on_ch_timer_vif = vif;
mod_timer(_drv->remain_on_ch_timer,
  jiffies +
  msecs_to_jiffies(pstrHostIfRemainOnChan->duration));
@@ -2360,11 +2361,13 @@ static u32 Handle_ListenStateExpired(struct wilc_vif 
*vif,
return result;
 }
 
-static void ListenTimerCB(unsigned long arg)
+static void ListenTimerCB(struct timer_list *t)
 {
+   struct host_if_drv *hif_drv = from_timer(hif_drv, t,
+ remain_on_ch_timer);
+   struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
s32 result = 0;
struct host_if_msg msg;
-   struct wilc_vif *vif = (struct wilc_vif *)arg;
 
del_timer(>hif_drv->remain_on_ch_timer);
 
@@ -2643,9 +2646,10 @@ static void host_if_work(struct work_struct *work)
complete(_thread_comp);
 }
 
-static void TimerCB_Scan(unsigned long arg)
+static void TimerCB_Scan(struct timer_list *t)
 {
-   struct wilc_vif *vif = (struct wilc_vif *)arg;
+   struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
+   struct wilc_vif *vif = hif_drv->scan_timer_vif;
struct host_if_msg msg;
 
memset(, 0, sizeof(struct host_if_msg));
@@ -2655,9 +2659,11 @@ static void TimerCB_Scan(unsigned long arg)
wilc_enqueue_cmd();
 }
 
-static void TimerCB_Connect(unsigned long arg)
+static void TimerCB_Connect(struct timer_list *t)
 {
-   struct wilc_vif *vif = (struct wilc_vif *)arg;
+   struct host_if_drv *hif_drv = from_timer(hif_drv, t,
+ connect_timer);
+   struct wilc_vif *vif = hif_drv->connect_timer_vif;
struct host_if_msg msg;
 
memset(, 0, sizeof(struct host_if_msg));
@@ -3040,7 +3046,7 @@ int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, 
const u8 *ssid,
return -EFAULT;
}
 
-   hif_drv->connect_timer.data = (unsigned long)vif;
+   hif_drv->connect_timer_vif = vif;
mod_timer(_drv->connect_timer,
  jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT));
 
@@ -3283,7 +3289,7 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 
scan_type,
return -EINVAL;
}
 
-   hif_drv->scan_timer.data = (unsigned long)vif;
+   hif_drv->scan_timer_vif = vif;
mod_timer(_drv->scan_timer,
  jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT));
 
@@ -3309,9 +3315,9 @@ int wilc_hif_set_cfg(struct wilc_vif *vif,
return wilc_enqueue_cmd();
 }
 
-static void GetPeriodicRSSI(unsigned long arg)
+static void GetPeriodicRSSI(struct timer_list *unused)
 {
-   struct wilc_vif *vif = (struct wilc_vif *)arg;
+   struct wilc_vif *vif = periodic_rssi_vif;
 
if (!vif->hif_drv) {
netdev_err(vif->ndev, "Driver handler is NULL\n");
@@ -3321,7 +3327,6 @@ static void GetPeriodicRSSI(unsigned long arg)
if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
wilc_get_statistics(vif, >wilc->dummy_statistics);
 
-   periodic_rssi.data = (unsigned long)vif;
mod_timer(_rssi, jiffies + msecs_to_jiffies(5000));
 }
 
@@ -3374,14 +3379,14 @@ int wilc_init(struct net_device *dev, struct 
host_if_drv **hif_drv_handler)
goto _fail_;
}
 
-