linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions ***
@ 2016-06-02  4:24 Binoy Jayan
  2016-06-02  4:24 ` [PATCH v2 1/4] rtl8712: Replace semaphore cmd_queue_sema with completion Binoy Jayan
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Binoy Jayan @ 2016-06-02  4:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, Florian Schilhabel
  Cc: Arnd Bergmann, driverdev-devel, linux-kernel, Binoy Jayan

Hi,

These are a set of patches [v2] which removes semaphores from:

drivers/staging/rtl8712

They build correctly (individually and as a whole).
NB: I have not tested this as I do not have the following hardware:

"RealTek RTL8712U (RTL8192SU) Wireless LAN NIC driver"

Rework on comments w.r.t. PATCH v1:

 - Removed wrapper functions _wait_completion, _down_sema and _enter_pwrlock
 - Updated changelog to explain use of mutex_lock instead of
   mutex_lock_interruptible in [PATCH v2 4/4]

Binoy

Binoy Jayan (4):
  rtl8712: Replace semaphore cmd_queue_sema with completion
  rtl8712: Replace semaphore terminate_cmdthread_sema with completion
  rtl8712: intf_priv: Replace semaphore lock with completion
  rtl8712: pwrctrl_priv: Replace semaphore lock with mutex

 drivers/staging/rtl8712/os_intfs.c        |  4 ++--
 drivers/staging/rtl8712/osdep_intf.h      |  2 +-
 drivers/staging/rtl8712/osdep_service.h   |  7 -------
 drivers/staging/rtl8712/rtl8712_cmd.c     | 14 +++++++-------
 drivers/staging/rtl8712/rtl871x_cmd.c     |  8 ++++----
 drivers/staging/rtl8712/rtl871x_cmd.h     |  4 ++--
 drivers/staging/rtl8712/rtl871x_pwrctrl.c | 24 ++++++++++++------------
 drivers/staging/rtl8712/rtl871x_pwrctrl.h |  7 +------
 drivers/staging/rtl8712/usb_ops_linux.c   |  6 +++---
 9 files changed, 32 insertions(+), 44 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/4] rtl8712: Replace semaphore cmd_queue_sema with completion
  2016-06-02  4:24 [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions *** Binoy Jayan
@ 2016-06-02  4:24 ` Binoy Jayan
  2016-06-02  4:24 ` [PATCH v2 2/4] rtl8712: Replace semaphore terminate_cmdthread_sema " Binoy Jayan
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Binoy Jayan @ 2016-06-02  4:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, Florian Schilhabel
  Cc: Arnd Bergmann, driverdev-devel, linux-kernel, Binoy Jayan

The semaphore 'cmd_queue_sema' is used as completion,
so convert it to a struct completion type.

Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>
---
 drivers/staging/rtl8712/os_intfs.c        | 2 +-
 drivers/staging/rtl8712/rtl8712_cmd.c     | 2 +-
 drivers/staging/rtl8712/rtl871x_cmd.c     | 6 +++---
 drivers/staging/rtl8712/rtl871x_cmd.h     | 2 +-
 drivers/staging/rtl8712/rtl871x_pwrctrl.c | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c
index ab19112..c07bcd0 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -243,7 +243,7 @@ static u32 start_drv_threads(struct _adapter *padapter)
 void r8712_stop_drv_threads(struct _adapter *padapter)
 {
 	/*Below is to terminate r8712_cmd_thread & event_thread...*/
-	up(&padapter->cmdpriv.cmd_queue_sema);
+	complete(&padapter->cmdpriv.cmd_queue_comp);
 	if (padapter->cmdThread)
 		_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
 	padapter->cmdpriv.cmd_seq = 1;
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c b/drivers/staging/rtl8712/rtl8712_cmd.c
index 50f4002..172f51f 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -322,7 +322,7 @@ int r8712_cmd_thread(void *context)
 
 	allow_signal(SIGTERM);
 	while (1) {
-		if ((_down_sema(&(pcmdpriv->cmd_queue_sema))) == _FAIL)
+		if (wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp))
 			break;
 		if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
 			break;
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c b/drivers/staging/rtl8712/rtl871x_cmd.c
index 86136cc..69e650b 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.c
+++ b/drivers/staging/rtl8712/rtl871x_cmd.c
@@ -57,7 +57,7 @@ No irqsave is necessary.
 
 static sint _init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
-	sema_init(&(pcmdpriv->cmd_queue_sema), 0);
+	init_completion(&pcmdpriv->cmd_queue_comp);
 	sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
 
 	_init_queue(&(pcmdpriv->cmd_queue));
@@ -172,7 +172,7 @@ u32 r8712_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj)
 	if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag)
 		return _FAIL;
 	res = _enqueue_cmd(&pcmdpriv->cmd_queue, obj);
-	up(&pcmdpriv->cmd_queue_sema);
+	complete(&pcmdpriv->cmd_queue_comp);
 	return res;
 }
 
@@ -189,7 +189,7 @@ u32 r8712_enqueue_cmd_ex(struct cmd_priv *pcmdpriv, struct cmd_obj *obj)
 	spin_lock_irqsave(&queue->lock, irqL);
 	list_add_tail(&obj->list, &queue->queue);
 	spin_unlock_irqrestore(&queue->lock, irqL);
-	up(&pcmdpriv->cmd_queue_sema);
+	complete(&pcmdpriv->cmd_queue_comp);
 	return _SUCCESS;
 }
 
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h b/drivers/staging/rtl8712/rtl871x_cmd.h
index e4a2a50..1907bc9 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.h
+++ b/drivers/staging/rtl8712/rtl871x_cmd.h
@@ -50,7 +50,7 @@ struct cmd_obj {
 };
 
 struct cmd_priv {
-	struct semaphore cmd_queue_sema;
+	struct completion cmd_queue_comp;
 	struct semaphore terminate_cmdthread_sema;
 	struct  __queue	cmd_queue;
 	u8 cmd_seq;
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.c b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
index bf10d6d..98a5e74 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.c
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
@@ -107,7 +107,7 @@ void r8712_cpwm_int_hdl(struct _adapter *padapter,
 	pwrpriv->cpwm = (preportpwrstate->state) & 0xf;
 	if (pwrpriv->cpwm >= PS_STATE_S2) {
 		if (pwrpriv->alives & CMD_ALIVE)
-			up(&(pcmdpriv->cmd_queue_sema));
+			complete(&(pcmdpriv->cmd_queue_comp));
 	}
 	pwrpriv->cpwm_tog = (preportpwrstate->state) & 0x80;
 	up(&pwrpriv->lock);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/4] rtl8712: Replace semaphore terminate_cmdthread_sema with completion
  2016-06-02  4:24 [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions *** Binoy Jayan
  2016-06-02  4:24 ` [PATCH v2 1/4] rtl8712: Replace semaphore cmd_queue_sema with completion Binoy Jayan
@ 2016-06-02  4:24 ` Binoy Jayan
  2016-06-02  4:24 ` [PATCH v2 3/4] rtl8712: intf_priv: Replace semaphore lock " Binoy Jayan
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Binoy Jayan @ 2016-06-02  4:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, Florian Schilhabel
  Cc: Arnd Bergmann, driverdev-devel, linux-kernel, Binoy Jayan

The semaphore 'terminate_cmdthread_sema' is used as completion,
so convert it to a struct completion type.

Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>
---
This patch depends on the following patch:
 rtl8712: Replace semaphore cmd_queue_sema with completion

 drivers/staging/rtl8712/os_intfs.c    | 2 +-
 drivers/staging/rtl8712/rtl8712_cmd.c | 2 +-
 drivers/staging/rtl8712/rtl871x_cmd.c | 2 +-
 drivers/staging/rtl8712/rtl871x_cmd.h | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c
index c07bcd0..2396bac 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -245,7 +245,7 @@ void r8712_stop_drv_threads(struct _adapter *padapter)
 	/*Below is to terminate r8712_cmd_thread & event_thread...*/
 	complete(&padapter->cmdpriv.cmd_queue_comp);
 	if (padapter->cmdThread)
-		_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+		wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 	padapter->cmdpriv.cmd_seq = 1;
 }
 
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c b/drivers/staging/rtl8712/rtl8712_cmd.c
index 172f51f..1badc6c 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -420,7 +420,7 @@ _next:
 			break;
 		r8712_free_cmd_obj(pcmd);
 	} while (1);
-	up(&pcmdpriv->terminate_cmdthread_sema);
+	complete(&pcmdpriv->terminate_cmdthread_comp);
 	thread_exit();
 }
 
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c b/drivers/staging/rtl8712/rtl871x_cmd.c
index 69e650b..74fd928 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.c
+++ b/drivers/staging/rtl8712/rtl871x_cmd.c
@@ -58,7 +58,7 @@ No irqsave is necessary.
 static sint _init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
 	init_completion(&pcmdpriv->cmd_queue_comp);
-	sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
+	init_completion(&pcmdpriv->terminate_cmdthread_comp);
 
 	_init_queue(&(pcmdpriv->cmd_queue));
 
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h b/drivers/staging/rtl8712/rtl871x_cmd.h
index 1907bc9..ebd2e1d 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.h
+++ b/drivers/staging/rtl8712/rtl871x_cmd.h
@@ -51,7 +51,7 @@ struct cmd_obj {
 
 struct cmd_priv {
 	struct completion cmd_queue_comp;
-	struct semaphore terminate_cmdthread_sema;
+	struct completion terminate_cmdthread_comp;
 	struct  __queue	cmd_queue;
 	u8 cmd_seq;
 	u8 *cmd_buf;	/*shall be non-paged, and 4 bytes aligned*/
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/4] rtl8712: intf_priv: Replace semaphore lock with completion
  2016-06-02  4:24 [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions *** Binoy Jayan
  2016-06-02  4:24 ` [PATCH v2 1/4] rtl8712: Replace semaphore cmd_queue_sema with completion Binoy Jayan
  2016-06-02  4:24 ` [PATCH v2 2/4] rtl8712: Replace semaphore terminate_cmdthread_sema " Binoy Jayan
@ 2016-06-02  4:24 ` Binoy Jayan
  2016-06-02  4:24 ` [PATCH v2 4/4] rtl8712: pwrctrl_priv: Replace semaphore lock with mutex Binoy Jayan
  2016-06-02  7:43 ` [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions *** Arnd Bergmann
  4 siblings, 0 replies; 8+ messages in thread
From: Binoy Jayan @ 2016-06-02  4:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, Florian Schilhabel
  Cc: Arnd Bergmann, driverdev-devel, linux-kernel, Binoy Jayan

The semaphore 'lock' in 'intf_priv' is used as completion,
so convert it to a struct completion type.

Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>
---
This patch depends on the following patch:
rtl8712: Replace semaphore terminate_cmdthread_sema with completion


 drivers/staging/rtl8712/osdep_intf.h    | 2 +-
 drivers/staging/rtl8712/usb_ops_linux.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8712/osdep_intf.h b/drivers/staging/rtl8712/osdep_intf.h
index aa0ec74..5d37e1f 100644
--- a/drivers/staging/rtl8712/osdep_intf.h
+++ b/drivers/staging/rtl8712/osdep_intf.h
@@ -36,7 +36,7 @@ struct intf_priv {
 	/* when in USB, IO is through interrupt in/out endpoints */
 	struct usb_device *udev;
 	struct urb *piorw_urb;
-	struct semaphore io_retevt;
+	struct completion io_retevt_comp;
 };
 
 int r871x_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
diff --git a/drivers/staging/rtl8712/usb_ops_linux.c b/drivers/staging/rtl8712/usb_ops_linux.c
index 454cdf6..fc3f263 100644
--- a/drivers/staging/rtl8712/usb_ops_linux.c
+++ b/drivers/staging/rtl8712/usb_ops_linux.c
@@ -50,7 +50,7 @@ uint r8712_usb_init_intf_priv(struct intf_priv *pintfpriv)
 	pintfpriv->piorw_urb = usb_alloc_urb(0, GFP_ATOMIC);
 	if (!pintfpriv->piorw_urb)
 		return _FAIL;
-	sema_init(&(pintfpriv->io_retevt), 0);
+	init_completion(&pintfpriv->io_retevt_comp);
 	return _SUCCESS;
 }
 
@@ -163,7 +163,7 @@ static void usb_write_mem_complete(struct urb *purb)
 		else
 			padapter->bSurpriseRemoved = true;
 	}
-	up(&pintfpriv->io_retevt);
+	complete(&pintfpriv->io_retevt_comp);
 }
 
 void r8712_usb_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
@@ -187,7 +187,7 @@ void r8712_usb_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
 			  wmem, cnt, usb_write_mem_complete,
 			  pio_queue);
 	usb_submit_urb(piorw_urb, GFP_ATOMIC);
-	_down_sema(&pintfpriv->io_retevt);
+	wait_for_completion_interruptible(&pintfpriv->io_retevt_comp);
 }
 
 static void r8712_usb_read_port_complete(struct urb *purb)
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 4/4] rtl8712: pwrctrl_priv: Replace semaphore lock with mutex
  2016-06-02  4:24 [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions *** Binoy Jayan
                   ` (2 preceding siblings ...)
  2016-06-02  4:24 ` [PATCH v2 3/4] rtl8712: intf_priv: Replace semaphore lock " Binoy Jayan
@ 2016-06-02  4:24 ` Binoy Jayan
  2016-08-21 16:26   ` Greg Kroah-Hartman
  2016-06-02  7:43 ` [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions *** Arnd Bergmann
  4 siblings, 1 reply; 8+ messages in thread
From: Binoy Jayan @ 2016-06-02  4:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Larry Finger, Florian Schilhabel
  Cc: Arnd Bergmann, driverdev-devel, linux-kernel, Binoy Jayan

The semaphore 'lock' in 'pwrctrl_priv' is used as a simple mutex, so it
should be written as one. Semaphores are going away in the future.
_enter_pwrlock was using down_interruptible(), so the lock could be broken
by sending a signal. This could be a bug, because nothing checks the return
code here. Hence, using mutex_lock instead of the interruptible version.
Removing the now unused _enter_pwrlock and _down_sema.

Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>
---
This patch depends on the following patch:
  rtl8712: intf_priv: Replace semaphore lock with completion

 drivers/staging/rtl8712/osdep_service.h   |  7 -------
 drivers/staging/rtl8712/rtl8712_cmd.c     | 10 +++++-----
 drivers/staging/rtl8712/rtl871x_pwrctrl.c | 22 +++++++++++-----------
 drivers/staging/rtl8712/rtl871x_pwrctrl.h |  7 +------
 4 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/rtl8712/osdep_service.h b/drivers/staging/rtl8712/osdep_service.h
index 076d508..d89ae09 100644
--- a/drivers/staging/rtl8712/osdep_service.h
+++ b/drivers/staging/rtl8712/osdep_service.h
@@ -60,13 +60,6 @@ struct	__queue	{
 #define LIST_CONTAINOR(ptr, type, member) \
 	((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
 
-static inline u32 _down_sema(struct semaphore *sema)
-{
-	if (down_interruptible(sema))
-		return _FAIL;
-	return _SUCCESS;
-}
-
 static inline u32 end_of_queue_search(struct list_head *head,
 		struct list_head *plist)
 {
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c b/drivers/staging/rtl8712/rtl8712_cmd.c
index 1badc6c..9934eab 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -264,9 +264,9 @@ static struct cmd_obj *cmd_hdl_filter(struct _adapter *padapter,
 		 */
 		if (padapter->pwrctrlpriv.pwr_mode > PS_MODE_ACTIVE) {
 			padapter->pwrctrlpriv.pwr_mode = PS_MODE_ACTIVE;
-			_enter_pwrlock(&(padapter->pwrctrlpriv.lock));
+			mutex_lock(&padapter->pwrctrlpriv.mutex_lock);
 			r8712_set_rpwm(padapter, PS_STATE_S4);
-			up(&(padapter->pwrctrlpriv.lock));
+			mutex_unlock(&padapter->pwrctrlpriv.mutex_lock);
 		}
 		pcmd_r = pcmd;
 		break;
@@ -395,10 +395,10 @@ _next:
 			}
 			if (pcmd->cmdcode == GEN_CMD_CODE(_SetPwrMode)) {
 				if (padapter->pwrctrlpriv.bSleep) {
-					_enter_pwrlock(&(padapter->
-						       pwrctrlpriv.lock));
+					mutex_lock(&padapter->
+						       pwrctrlpriv.mutex_lock);
 					r8712_set_rpwm(padapter, PS_STATE_S2);
-					up(&padapter->pwrctrlpriv.lock);
+					mutex_unlock(&padapter->pwrctrlpriv.mutex_lock);
 				}
 			}
 			r8712_free_cmd_obj(pcmd);
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.c b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
index 98a5e74..8d7ead6 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.c
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
@@ -103,14 +103,14 @@ void r8712_cpwm_int_hdl(struct _adapter *padapter,
 	if (pwrpriv->cpwm_tog == ((preportpwrstate->state) & 0x80))
 		return;
 	del_timer(&padapter->pwrctrlpriv.rpwm_check_timer);
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	pwrpriv->cpwm = (preportpwrstate->state) & 0xf;
 	if (pwrpriv->cpwm >= PS_STATE_S2) {
 		if (pwrpriv->alives & CMD_ALIVE)
 			complete(&(pcmdpriv->cmd_queue_comp));
 	}
 	pwrpriv->cpwm_tog = (preportpwrstate->state) & 0x80;
-	up(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 }
 
 static inline void register_task_alive(struct pwrctrl_priv *pwrctrl, uint tag)
@@ -141,10 +141,10 @@ static void SetPSModeWorkItemCallback(struct work_struct *work)
 	struct _adapter *padapter = container_of(pwrpriv,
 				    struct _adapter, pwrctrlpriv);
 	if (!pwrpriv->bSleep) {
-		_enter_pwrlock(&pwrpriv->lock);
+		mutex_lock(&pwrpriv->mutex_lock);
 		if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
 			r8712_set_rpwm(padapter, PS_STATE_S4);
-		up(&pwrpriv->lock);
+		mutex_lock(&pwrpriv->mutex_lock);
 	}
 }
 
@@ -155,11 +155,11 @@ static void rpwm_workitem_callback(struct work_struct *work)
 	struct _adapter *padapter = container_of(pwrpriv,
 				    struct _adapter, pwrctrlpriv);
 	if (pwrpriv->cpwm != pwrpriv->rpwm) {
-		_enter_pwrlock(&pwrpriv->lock);
+		mutex_lock(&pwrpriv->mutex_lock);
 		r8712_read8(padapter, SDIO_HCPWM);
 		pwrpriv->rpwm_retry = 1;
 		r8712_set_rpwm(padapter, pwrpriv->rpwm);
-		up(&pwrpriv->lock);
+		mutex_unlock(&pwrpriv->mutex_lock);
 	}
 }
 
@@ -175,7 +175,7 @@ void r8712_init_pwrctrl_priv(struct _adapter *padapter)
 	struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
 
 	memset((unsigned char *)pwrctrlpriv, 0, sizeof(struct pwrctrl_priv));
-	sema_init(&pwrctrlpriv->lock, 1);
+	mutex_init(&pwrctrlpriv->mutex_lock);
 	pwrctrlpriv->cpwm = PS_STATE_S4;
 	pwrctrlpriv->pwr_mode = PS_MODE_ACTIVE;
 	pwrctrlpriv->smart_ps = 0;
@@ -207,13 +207,13 @@ sint r8712_register_cmd_alive(struct _adapter *padapter)
 	uint res = _SUCCESS;
 	struct pwrctrl_priv *pwrctrl = &padapter->pwrctrlpriv;
 
-	_enter_pwrlock(&pwrctrl->lock);
+	mutex_lock(&pwrctrl->mutex_lock);
 	register_task_alive(pwrctrl, CMD_ALIVE);
 	if (pwrctrl->cpwm < PS_STATE_S2) {
 		r8712_set_rpwm(padapter, PS_STATE_S3);
 		res = _FAIL;
 	}
-	up(&pwrctrl->lock);
+	mutex_unlock(&pwrctrl->mutex_lock);
 	return res;
 }
 
@@ -229,7 +229,7 @@ void r8712_unregister_cmd_alive(struct _adapter *padapter)
 {
 	struct pwrctrl_priv *pwrctrl = &padapter->pwrctrlpriv;
 
-	_enter_pwrlock(&pwrctrl->lock);
+	mutex_lock(&pwrctrl->mutex_lock);
 	unregister_task_alive(pwrctrl, CMD_ALIVE);
 	if ((pwrctrl->cpwm > PS_STATE_S2) &&
 	   (pwrctrl->pwr_mode > PS_MODE_ACTIVE)) {
@@ -239,5 +239,5 @@ void r8712_unregister_cmd_alive(struct _adapter *padapter)
 			r8712_set_rpwm(padapter, PS_STATE_S0);
 		}
 	}
-	up(&pwrctrl->lock);
+	mutex_unlock(&pwrctrl->mutex_lock);
 }
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.h b/drivers/staging/rtl8712/rtl871x_pwrctrl.h
index dbfb555..231445e 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.h
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.h
@@ -87,13 +87,8 @@ struct reportpwrstate_parm {
 	unsigned short rsvd;
 };
 
-static inline void _enter_pwrlock(struct semaphore *plock)
-{
-	_down_sema(plock);
-}
-
 struct	pwrctrl_priv {
-	struct semaphore lock;
+	struct mutex mutex_lock;
 	/*volatile*/ u8 rpwm; /* requested power state for fw */
 	/* fw current power state. updated when 1. read from HCPWM or
 	 * 2. driver lowers power level */
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions ***
  2016-06-02  4:24 [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions *** Binoy Jayan
                   ` (3 preceding siblings ...)
  2016-06-02  4:24 ` [PATCH v2 4/4] rtl8712: pwrctrl_priv: Replace semaphore lock with mutex Binoy Jayan
@ 2016-06-02  7:43 ` Arnd Bergmann
  2016-06-02 15:15   ` Larry Finger
  4 siblings, 1 reply; 8+ messages in thread
From: Arnd Bergmann @ 2016-06-02  7:43 UTC (permalink / raw)
  To: Binoy Jayan
  Cc: Greg Kroah-Hartman, Larry Finger, Florian Schilhabel,
	driverdev-devel, linux-kernel

On Thursday, June 2, 2016 9:54:06 AM CEST Binoy Jayan wrote:
> Hi,
> 
> These are a set of patches [v2] which removes semaphores from:
> 
> drivers/staging/rtl8712
> 
> They build correctly (individually and as a whole).
> NB: I have not tested this as I do not have the following hardware:
> 
> "RealTek RTL8712U (RTL8192SU) Wireless LAN NIC driver"
> 
> Rework on comments w.r.t. PATCH v1:
> 
>  - Removed wrapper functions _wait_completion, _down_sema and _enter_pwrlock
>  - Updated changelog to explain use of mutex_lock instead of
>    mutex_lock_interruptible in [PATCH v2 4/4]
> 

All four look great now,

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions ***
  2016-06-02  7:43 ` [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions *** Arnd Bergmann
@ 2016-06-02 15:15   ` Larry Finger
  0 siblings, 0 replies; 8+ messages in thread
From: Larry Finger @ 2016-06-02 15:15 UTC (permalink / raw)
  To: Arnd Bergmann, Binoy Jayan
  Cc: Greg Kroah-Hartman, Florian Schilhabel, driverdev-devel, linux-kernel

On 06/02/2016 02:43 AM, Arnd Bergmann wrote:
> On Thursday, June 2, 2016 9:54:06 AM CEST Binoy Jayan wrote:
>> Hi,
>>
>> These are a set of patches [v2] which removes semaphores from:
>>
>> drivers/staging/rtl8712
>>
>> They build correctly (individually and as a whole).
>> NB: I have not tested this as I do not have the following hardware:
>>
>> "RealTek RTL8712U (RTL8192SU) Wireless LAN NIC driver"
>>
>> Rework on comments w.r.t. PATCH v1:
>>
>>   - Removed wrapper functions _wait_completion, _down_sema and _enter_pwrlock
>>   - Updated changelog to explain use of mutex_lock instead of
>>     mutex_lock_interruptible in [PATCH v2 4/4]
>>
>
> All four look great now,
>
> Reviewed-by: Arnd Bergmann <arnd@arndb.de>


I agree.

Tested-by: Larry Finger <Larry.Finger@lwfinger.net>

Larry

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 4/4] rtl8712: pwrctrl_priv: Replace semaphore lock with mutex
  2016-06-02  4:24 ` [PATCH v2 4/4] rtl8712: pwrctrl_priv: Replace semaphore lock with mutex Binoy Jayan
@ 2016-08-21 16:26   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 8+ messages in thread
From: Greg Kroah-Hartman @ 2016-08-21 16:26 UTC (permalink / raw)
  To: Binoy Jayan
  Cc: Larry Finger, Florian Schilhabel, driverdev-devel, linux-kernel,
	Arnd Bergmann

On Thu, Jun 02, 2016 at 09:54:10AM +0530, Binoy Jayan wrote:
> The semaphore 'lock' in 'pwrctrl_priv' is used as a simple mutex, so it
> should be written as one. Semaphores are going away in the future.
> _enter_pwrlock was using down_interruptible(), so the lock could be broken
> by sending a signal. This could be a bug, because nothing checks the return
> code here. Hence, using mutex_lock instead of the interruptible version.
> Removing the now unused _enter_pwrlock and _down_sema.
> 
> Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>
> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
> Tested-by: Larry Finger <Larry.Finger@lwfinger.net>
> ---
> This patch depends on the following patch:
>   rtl8712: intf_priv: Replace semaphore lock with completion

This one patch doesn't apply to my tree for some odd reason.

Can you rebase it on my staging-testing branch and resend it?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-08-21 21:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-02  4:24 [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions *** Binoy Jayan
2016-06-02  4:24 ` [PATCH v2 1/4] rtl8712: Replace semaphore cmd_queue_sema with completion Binoy Jayan
2016-06-02  4:24 ` [PATCH v2 2/4] rtl8712: Replace semaphore terminate_cmdthread_sema " Binoy Jayan
2016-06-02  4:24 ` [PATCH v2 3/4] rtl8712: intf_priv: Replace semaphore lock " Binoy Jayan
2016-06-02  4:24 ` [PATCH v2 4/4] rtl8712: pwrctrl_priv: Replace semaphore lock with mutex Binoy Jayan
2016-08-21 16:26   ` Greg Kroah-Hartman
2016-06-02  7:43 ` [PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions *** Arnd Bergmann
2016-06-02 15:15   ` Larry Finger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).