Skip to contentSkip to conversation

Staging: rtl8712: Use mod_timer and setup_timer

PATCH Superseded Vaishali Thakkar 2 participants 5 messages Feb 27, 2015 – Mar 2, 2015 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Staging: rtl8712: Use mod_timer and setup_timer

This patch-set introduces the use of timer API
functions mod_timer and setup_timer instead of
driver specific functions _set_timer and
_init_timer respectively. Here, these changes
are done using Coccinelle.

Vaishali Thakkar (2):
Staging: rtl8712: Eliminate use of _set_timer
Staging: rtl8712: Eliminate use of _init_timer

 drivers/staging/rtl8712/mlme_linux.c        |  34 +--
 drivers/staging/rtl8712/os_intfs.c          |  11 +-
 drivers/staging/rtl8712/osdep_service.h     |  14 --
 drivers/staging/rtl8712/recv_linux.c        |   5 +-
 drivers/staging/rtl8712/rtl8712_led.c       | 327 +++++++++++++++-------------
 drivers/staging/rtl8712/rtl8712_recv.c      |   4 +-
 drivers/staging/rtl8712/rtl871x_cmd.c       |   9 +-
 drivers/staging/rtl8712/rtl871x_ioctl_set.c |   3 +-
 drivers/staging/rtl8712/rtl871x_mlme.c      |  14 +-
 drivers/staging/rtl8712/rtl871x_pwrctrl.c   |   4 +-
 10 files changed, 221 insertions(+), 204 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 Staging: rtl8712: Eliminate use of _set_timer

This patch introduces the use of API function mod_timer instead of driver specific function _set_timer as it is a more efficient and standard way to update the expire field of an active timer. Also, definition of function _set_timer is removed as it is no longer needed after this change.

Here, these cases are handled using Coccinelle and semantic patch used for this is as follows:

@@ expression x; expression y;@@

- _set_timer (&x, y);
+ mod_timer (&x, jiffies + msecs_to_jiffies (y));

---
v1: This patch has some line over 80 characters as limiting
them to 80 characters does not make code look good and more readable.

 drivers/staging/rtl8712/mlme_linux.c        |   7 +-
 drivers/staging/rtl8712/os_intfs.c          |   7 +-
 drivers/staging/rtl8712/osdep_service.h     |   5 -
 drivers/staging/rtl8712/rtl8712_led.c       | 324 +++++++++++++++-------------
 drivers/staging/rtl8712/rtl8712_recv.c      |   4 +-
 drivers/staging/rtl8712/rtl871x_cmd.c       |   9 +-
 drivers/staging/rtl8712/rtl871x_ioctl_set.c |   3 +-
 drivers/staging/rtl8712/rtl871x_mlme.c      |  14 +-
 8 files changed, 199 insertions(+), 174 deletions(-)
drivers/staging/rtl8712/mlme_linux.c +4 -3
index 354bd03..53999e8 100644
@@ -37,8 +37,8 @@ static void sitesurvey_ctrl_handler(void *FunctionContext)
 	struct _adapter *adapter = (struct _adapter *)FunctionContext;
 
 	_r8712_sitesurvey_ctrl_handler(adapter);
-	_set_timer(&adapter->mlmepriv.sitesurveyctrl.sitesurvey_ctrl_timer,
-		   3000);
+	mod_timer(&adapter->mlmepriv.sitesurveyctrl.sitesurvey_ctrl_timer,
+		  jiffies + msecs_to_jiffies(3000));
 }
 
 static void join_timeout_handler (void *FunctionContext)
@@ -68,7 +68,8 @@ static void wdg_timeout_handler (void *FunctionContext)
 
 	_r8712_wdg_timeout_handler(adapter);
 
-	_set_timer(&adapter->mlmepriv.wdg_timer, 2000);
+	mod_timer(&adapter->mlmepriv.wdg_timer,
+		  jiffies + msecs_to_jiffies(2000));
 }
 
 void r8712_init_mlme_timer(struct _adapter *padapter)
drivers/staging/rtl8712/os_intfs.c +4 -3
index 13debb5..64cdcee 100644
@@ -255,9 +255,10 @@ void r8712_stop_drv_threads(struct _adapter *padapter)
 
 static void start_drv_timers(struct _adapter *padapter)
 {
-	_set_timer(&padapter->mlmepriv.sitesurveyctrl.sitesurvey_ctrl_timer,
-		   5000);
-	_set_timer(&padapter->mlmepriv.wdg_timer, 2000);
+	mod_timer(&padapter->mlmepriv.sitesurveyctrl.sitesurvey_ctrl_timer,
+		  jiffies + msecs_to_jiffies(5000));
+	mod_timer(&padapter->mlmepriv.wdg_timer,
+		  jiffies + msecs_to_jiffies(2000));
 }
 
 void r8712_stop_drv_timers(struct _adapter *padapter)
drivers/staging/rtl8712/osdep_service.h +0 -5
index 36348d9..54c4c47 100644
@@ -69,11 +69,6 @@ static inline void _init_timer(struct timer_list *ptimer,
 	init_timer(ptimer);
 }
 
-static inline void _set_timer(struct timer_list *ptimer, u32 delay_time)
-{
-	mod_timer(ptimer, (jiffies+msecs_to_jiffies(delay_time)));
-}
-
 static inline void _cancel_timer(struct timer_list *ptimer, u8 *bcancelled)
 {
 	del_timer(ptimer);
drivers/staging/rtl8712/rtl8712_led.c +173 -151

803 lines not on this page · raw message

drivers/staging/rtl8712/rtl8712_recv.c +2 -2
index e4fc9e0..546414d 100644
@@ -604,8 +604,8 @@ static int recv_indicatepkt_reorder(struct _adapter *padapter,
 	 */
 	if (r8712_recv_indicatepkts_in_order(padapter, preorder_ctrl, false) ==
 	    true) {
-		_set_timer(&preorder_ctrl->reordering_ctrl_timer,
-			   REORDER_WAIT_TIME);
+		mod_timer(&preorder_ctrl->reordering_ctrl_timer,
+			  jiffies + msecs_to_jiffies(REORDER_WAIT_TIME));
 		spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql);
 	} else {
 		spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql);
drivers/staging/rtl8712/rtl871x_cmd.c +6 -3
index 939a2ec..d105ade 100644
@@ -247,7 +247,8 @@ u8 r8712_sitesurvey_cmd(struct _adapter *padapter,
 	}
 	set_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
 	r8712_enqueue_cmd(pcmdpriv, ph2c);
-	_set_timer(&pmlmepriv->scan_to_timer, SCANNING_TIMEOUT);
+	mod_timer(&pmlmepriv->scan_to_timer,
+		  jiffies + msecs_to_jiffies(SCANNING_TIMEOUT));
 	padapter->ledpriv.LedControlHandler(padapter, LED_CTL_SITE_SURVEY);
 	padapter->blnEnableRxFF0Filter = 0;
 	return _SUCCESS;
@@ -890,7 +891,8 @@ void r8712_joinbss_cmd_callback(struct _adapter *padapter, struct cmd_obj *pcmd)
 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 
 	if (pcmd->res != H2C_SUCCESS)
-		_set_timer(&pmlmepriv->assoc_timer, 1);
+		mod_timer(&pmlmepriv->assoc_timer,
+			  jiffies + msecs_to_jiffies(1));
 	r8712_free_cmd_obj(pcmd);
 }
 
@@ -907,7 +909,8 @@ void r8712_createbss_cmd_callback(struct _adapter *padapter,
 	struct wlan_network *tgt_network = &(pmlmepriv->cur_network);
 
 	if (pcmd->res != H2C_SUCCESS)
-		_set_timer(&pmlmepriv->assoc_timer, 1);
+		mod_timer(&pmlmepriv->assoc_timer,
+			  jiffies + msecs_to_jiffies(1));
 	_cancel_timer(&pmlmepriv->assoc_timer, &timer_cancelled);
 #ifdef __BIG_ENDIAN
 	/* endian_convert */
drivers/staging/rtl8712/rtl871x_ioctl_set.c +2 -1
index 6318a0e..bd1d1b7 100644
@@ -85,7 +85,8 @@ static u8 do_join(struct _adapter *padapter)
 
 		ret = r8712_select_and_join_from_scan(pmlmepriv);
 		if (ret == _SUCCESS)
-			_set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
+			mod_timer(&pmlmepriv->assoc_timer,
+				  jiffies + msecs_to_jiffies(MAX_JOIN_TIMEOUT));
 		else {
 			if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
 				/* submit r8712_createbss_cmd to change to an
drivers/staging/rtl8712/rtl871x_mlme.c +8 -6
index 977a833..bb78484 100644
@@ -596,8 +596,8 @@ void r8712_surveydone_event_callback(struct _adapter *adapter, u8 *pbuf)
 
 				if (r8712_select_and_join_from_scan(pmlmepriv)
 				    == _SUCCESS)
-					_set_timer(&pmlmepriv->assoc_timer,
-						   MAX_JOIN_TIMEOUT);
+					mod_timer(&pmlmepriv->assoc_timer, jiffies +
+						  msecs_to_jiffies(MAX_JOIN_TIMEOUT));
 				else {
 					struct wlan_bssid_ex *pdev_network =
 					  &(adapter->registrypriv.dev_network);
@@ -622,8 +622,8 @@ void r8712_surveydone_event_callback(struct _adapter *adapter, u8 *pbuf)
 			set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
 			if (r8712_select_and_join_from_scan(pmlmepriv) ==
 			    _SUCCESS)
-				_set_timer(&pmlmepriv->assoc_timer,
-					   MAX_JOIN_TIMEOUT);
+				mod_timer(&pmlmepriv->assoc_timer, jiffies +
+					  msecs_to_jiffies(MAX_JOIN_TIMEOUT));
 			else
 				_clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
 		}
@@ -679,7 +679,8 @@ void r8712_indicate_connect(struct _adapter *padapter)
 	padapter->ledpriv.LedControlHandler(padapter, LED_CTL_LINK);
 	r8712_os_indicate_connect(padapter);
 	if (padapter->registrypriv.power_mgnt > PS_MODE_ACTIVE)
-		_set_timer(&pmlmepriv->dhcp_timer, 60000);
+		mod_timer(&pmlmepriv->dhcp_timer,
+			  jiffies + msecs_to_jiffies(60000));
 }
 
 
@@ -916,7 +917,8 @@ void r8712_joinbss_event_callback(struct _adapter *adapter, u8 *pbuf)
 			goto ignore_joinbss_callback;
 	} else {
 		if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true) {
-			_set_timer(&pmlmepriv->assoc_timer, 1);
+			mod_timer(&pmlmepriv->assoc_timer,
+				  jiffies + msecs_to_jiffies(1));
 			_clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
 		}
 	}
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/2 Staging: rtl8712: Eliminate use of _init_timer

In reply to Vaishali Thakkar

This patch introduces the use of API function setup_timer instead of driver specific function _init_timer as it is the preferred and standard way to setup and set the timer. Also, definition of function _init_timer is removed as it is no longer needed after this change.

This is done using Coccinelle and semantic patch used for this is as follows:

@@ expression x, y; identifier a, b;@@

- _init_timer (&x, y, a, b);
+ setup_timer (&x, a, (unsigned long)b);

---
 drivers/staging/rtl8712/mlme_linux.c      | 27 +++++++++++++--------------
 drivers/staging/rtl8712/os_intfs.c        |  4 ++--
 drivers/staging/rtl8712/osdep_service.h   |  9 ---------
 drivers/staging/rtl8712/recv_linux.c      |  5 +++--
 drivers/staging/rtl8712/rtl8712_led.c     |  3 ++-
 drivers/staging/rtl8712/rtl871x_pwrctrl.c |  4 ++--
 6 files changed, 22 insertions(+), 30 deletions(-)
drivers/staging/rtl8712/mlme_linux.c +13 -14
index 53999e8..325c1c9 100644
@@ -76,17 +76,17 @@ void r8712_init_mlme_timer(struct _adapter *padapter)
 {
 	struct	mlme_priv *pmlmepriv = &padapter->mlmepriv;
 
-	_init_timer(&(pmlmepriv->assoc_timer), padapter->pnetdev,
-		    join_timeout_handler, (pmlmepriv->nic_hdl));
-	_init_timer(&(pmlmepriv->sitesurveyctrl.sitesurvey_ctrl_timer),
-		    padapter->pnetdev, sitesurvey_ctrl_handler,
-		    (u8 *)(pmlmepriv->nic_hdl));
-	_init_timer(&(pmlmepriv->scan_to_timer), padapter->pnetdev,
-		    _scan_timeout_handler, (pmlmepriv->nic_hdl));
-	_init_timer(&(pmlmepriv->dhcp_timer), padapter->pnetdev,
-		    dhcp_timeout_handler, (u8 *)(pmlmepriv->nic_hdl));
-	_init_timer(&(pmlmepriv->wdg_timer), padapter->pnetdev,
-		    wdg_timeout_handler, (u8 *)(pmlmepriv->nic_hdl));
+	setup_timer(&pmlmepriv->assoc_timer, join_timeout_handler,
+		    (unsigned long)padapter);
+	setup_timer(&pmlmepriv->sitesurveyctrl.sitesurvey_ctrl_timer,
+		    sitesurvey_ctrl_handler,
+		    (unsigned long)padapter);
+	setup_timer(&pmlmepriv->scan_to_timer, _scan_timeout_handler,
+		    (unsigned long)padapter);
+	setup_timer(&pmlmepriv->dhcp_timer, dhcp_timeout_handler,
+		    (unsigned long)padapter);
+	setup_timer(&pmlmepriv->wdg_timer, wdg_timeout_handler,
+		    (unsigned long)padapter);
 }
 
 void r8712_os_indicate_connect(struct _adapter *adapter)
@@ -118,9 +118,8 @@ void r8712_os_indicate_disconnect(struct _adapter *adapter)
 					   btkip_countermeasure;
 		memset((unsigned char *)&adapter->securitypriv, 0,
 			 sizeof(struct security_priv));
-		_init_timer(&(adapter->securitypriv.tkip_timer),
-			    adapter->pnetdev, r8712_use_tkipkey_handler,
-			    adapter);
+		setup_timer(&adapter->securitypriv.tkip_timer,
+			    r8712_use_tkipkey_handler, (unsigned long)adapter);
 		/* Restore the PMK information to securitypriv structure
 		 * for the following connection. */
 		memcpy(&adapter->securitypriv.PMKIDList[0],
drivers/staging/rtl8712/os_intfs.c +2 -2
index 64cdcee..ebfb29e 100644
@@ -323,8 +323,8 @@ u8 r8712_init_drv_sw(struct _adapter *padapter)
 	_r8712_init_recv_priv(&padapter->recvpriv, padapter);
 	memset((unsigned char *)&padapter->securitypriv, 0,
 	       sizeof(struct security_priv));
-	_init_timer(&(padapter->securitypriv.tkip_timer), padapter->pnetdev,
-		    r8712_use_tkipkey_handler, padapter);
+	setup_timer(&padapter->securitypriv.tkip_timer,
+		    r8712_use_tkipkey_handler, (unsigned long)padapter);
 	_r8712_init_sta_priv(&padapter->stapriv);
 	padapter->stapriv.padapter = padapter;
 	r8712_init_bcmc_stainfo(padapter);
drivers/staging/rtl8712/osdep_service.h +0 -9
index 54c4c47..c6dc362 100644
@@ -60,15 +60,6 @@ struct	__queue	{
 #define LIST_CONTAINOR(ptr, type, member) \
 	((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
 
-static inline void _init_timer(struct timer_list *ptimer,
-			       struct  net_device *padapter,
-			       void *pfunc, void *cntx)
-{
-	ptimer->function = pfunc;
-	ptimer->data = (addr_t)cntx;
-	init_timer(ptimer);
-}
-
 static inline void _cancel_timer(struct timer_list *ptimer, u8 *bcancelled)
 {
 	del_timer(ptimer);
drivers/staging/rtl8712/recv_linux.c +3 -2
index 3640dd4..754f160 100644
@@ -149,6 +149,7 @@ void r8712_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
 {
 	struct _adapter *padapter = preorder_ctrl->padapter;
 
-	_init_timer(&(preorder_ctrl->reordering_ctrl_timer), padapter->pnetdev,
-		    _r8712_reordering_ctrl_timeout_handler, preorder_ctrl);
+	setup_timer(&preorder_ctrl->reordering_ctrl_timer,
+		    _r8712_reordering_ctrl_timeout_handler,
+		    (unsigned long)preorder_ctrl);
 }
drivers/staging/rtl8712/rtl8712_led.c +2 -1
index 0c7dfee..6085689 100644
@@ -97,7 +97,8 @@ static void InitLed871x(struct _adapter *padapter, struct LED_871x *pLed,
 	pLed->bLedBlinkInProgress = false;
 	pLed->BlinkTimes = 0;
 	pLed->BlinkingLedState = LED_UNKNOWN;
-	_init_timer(&(pLed->BlinkTimer), nic, BlinkTimerCallback, pLed);
+	setup_timer(&pLed->BlinkTimer, BlinkTimerCallback,
+		    (unsigned long)pLed);
 	INIT_WORK(&pLed->BlinkWorkItem, BlinkWorkItemCallback);
 }
 
drivers/staging/rtl8712/rtl871x_pwrctrl.c +2 -2
index ed2844d..ae0675f 100644
@@ -186,8 +186,8 @@ void r8712_init_pwrctrl_priv(struct _adapter *padapter)
 	r8712_write8(padapter, 0x1025FE58, 0);
 	INIT_WORK(&pwrctrlpriv->SetPSModeWorkItem, SetPSModeWorkItemCallback);
 	INIT_WORK(&pwrctrlpriv->rpwm_workitem, rpwm_workitem_callback);
-	_init_timer(&(pwrctrlpriv->rpwm_check_timer),
-		    padapter->pnetdev, rpwm_check_handler, (u8 *)padapter);
+	setup_timer(&pwrctrlpriv->rpwm_check_timer, rpwm_check_handler,
+		    (unsigned long)padapter);
 }
 
 /*
Signature · 1 line
1.9.1
maintainer
#3 lore raw

Re: [Outreachy kernel] [PATCH 2/2] Staging: rtl8712: Eliminate use of _init_timer

Quoted 15 lines · Vaishali Thakkar

This patch introduces the use of API function setup_timer instead of driver specific function _init_timer as it is the preferred and standard way to setup and set the timer. Also, definition of function _init_timer is removed as it is no longer needed after this change.

This is done using Coccinelle and semantic patch used for this is as follows:

@@ expression x, y; identifier a, b;@@

- _init_timer (&x, y, a, b);
+ setup_timer (&x, a, (unsigned long)b);

Quoted 8 lines
---
 drivers/staging/rtl8712/mlme_linux.c      | 27 +++++++++++++--------------
 drivers/staging/rtl8712/os_intfs.c        |  4 ++--
 drivers/staging/rtl8712/osdep_service.h   |  9 ---------
 drivers/staging/rtl8712/recv_linux.c      |  5 +++--
 drivers/staging/rtl8712/rtl8712_led.c     |  3 ++-
 drivers/staging/rtl8712/rtl871x_pwrctrl.c |  4 ++--
 6 files changed, 22 insertions(+), 30 deletions(-)

This patch adds a bunch of compiler warnings, so I can't take it :(

Please fix up and resend, and be more careful in the future.

thanks,

greg k-h

#4 lore raw

Re: [Outreachy kernel] [PATCH 2/2] Staging: rtl8712: Eliminate use of _init_timer

Quoted 25 lines · Greg KH
Quoted 15 lines · Vaishali Thakkar

This patch introduces the use of API function setup_timer instead of driver specific function _init_timer as it is the preferred and standard way to setup and set the timer. Also, definition of function _init_timer is removed as it is no longer needed after this change.

This is done using Coccinelle and semantic patch used for this is as follows:

@@ expression x, y; identifier a, b;@@

- _init_timer (&x, y, a, b);
+ setup_timer (&x, a, (unsigned long)b);

Quoted 8 lines
---
 drivers/staging/rtl8712/mlme_linux.c      | 27 +++++++++++++--------------
 drivers/staging/rtl8712/os_intfs.c        |  4 ++--
 drivers/staging/rtl8712/osdep_service.h   |  9 ---------
 drivers/staging/rtl8712/recv_linux.c      |  5 +++--
 drivers/staging/rtl8712/rtl8712_led.c     |  3 ++-
 drivers/staging/rtl8712/rtl871x_pwrctrl.c |  4 ++--
 6 files changed, 22 insertions(+), 30 deletions(-)
Quoted 3 lines

This patch adds a bunch of compiler warnings, so I can't take it :(

Please fix up and resend, and be more careful in the future.

Here, again because of same gcc problem it didn't show me any errors.

Yes. I will be more careful in the future. I am sorry for this one.

Thank You.

Quoted 3 lines

thanks,

greg k-h

Signature · 1 line
Vaishali