Skip to contentSkip to conversation

*** rtl8188eu: Replace semaphores with mutexes or completions ***

PATCH Superseded Binoy Jayan 3 participants 17 messages Jun 3, 2016 – Jun 6, 2016 Staging

lore
Share & tools
lore
#0 lore raw

cover *** rtl8188eu: Replace semaphores with mutexes or completions ***

Hi,

These are a set of patches which removes semaphores from:

drivers/staging/rtl8188eu

These are part of a bigger effort to eliminate all semaphores from the linux kernel.

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

"Realtek RTL8188EU Wireless LAN NIC driver"

Thanks,
Binoy

Binoy Jayan (4):
irtl8188eu: Replace semaphore cmd_queue_sema with completion
rtl8188eu: Replace semaphore terminate_cmdthread_sema with completion
rtl8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex
rtl8188eu: Remove unused semaphores

 drivers/staging/rtl8188eu/core/rtw_cmd.c          | 12 ++++++------
 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c      | 20 ++++++++++----------
 drivers/staging/rtl8188eu/core/rtw_xmit.c         |  4 ----
 drivers/staging/rtl8188eu/include/osdep_service.h |  4 +---
 drivers/staging/rtl8188eu/include/rtw_cmd.h       |  4 ++--
 drivers/staging/rtl8188eu/include/rtw_event.h     |  2 +-
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h   | 17 +----------------
 drivers/staging/rtl8188eu/include/rtw_xmit.h      |  3 ---
 drivers/staging/rtl8188eu/os_dep/os_intfs.c       |  6 +++---
 drivers/staging/rtl8188eu/os_dep/osdep_service.c  |  7 -------
 drivers/staging/rtl8188eu/os_dep/usb_intf.c       |  8 ++++----
 11 files changed, 28 insertions(+), 59 deletions(-)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

PATCH 1/4 irtl8188eu: Replace semaphore cmd_queue_sema with completion

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

---
 drivers/staging/rtl8188eu/core/rtw_cmd.c    | 6 +++---
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/os_intfs.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/rtl8188eu/core/rtw_cmd.c +3 -3
index 7748523..a2937e7 100644
@@ -27,7 +27,7 @@ No irqsave is necessary.
 
 int rtw_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);
 
 	_rtw_init_queue(&(pcmdpriv->cmd_queue));
@@ -122,7 +122,7 @@ u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
 	res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj);
 
 	if (res == _SUCCESS)
-		up(&pcmdpriv->cmd_queue_sema);
+		complete(&pcmdpriv->cmd_queue_comp);
 
 exit:
 
@@ -167,7 +167,7 @@ int rtw_cmd_thread(void *context)
 	RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("start r871x rtw_cmd_thread !!!!\n"));
 
 	while (1) {
-		if (_rtw_down_sema(&pcmdpriv->cmd_queue_sema) == _FAIL)
+		if (wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp))
 			break;
 
 		if (padapter->bDriverStopped ||
drivers/staging/rtl8188eu/include/rtw_cmd.h +1 -1
index 08ca592..3532dd1 100644
@@ -39,7 +39,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 cmdthd_running;
drivers/staging/rtl8188eu/os_dep/os_intfs.c +1 -1
index ae2caff..a696d2b 100644
@@ -772,7 +772,7 @@ void rtw_stop_drv_threads(struct adapter *padapter)
 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_stop_drv_threads\n"));
 
 	/* Below is to terminate rtw_cmd_thread & event_thread... */
-	up(&padapter->cmdpriv.cmd_queue_sema);
+	complete(&padapter->cmdpriv.cmd_queue_comp);
 	if (padapter->cmdThread)
 		_rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#4 lore raw

PATCH 3/4 rtl8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex

In reply to Binoy Jayan

The semaphore 'lock' in pwrctrl_priv is a simple mutex, so it should be written as one. Semaphores are going away in the future. Also, remove the now unused wrappers _init_pwrlock, _enter_pwrlock, _exit_pwrlock and _rtw_down_sema.

---
This patch depends on the following patch:
rtl8188eu: Replace semaphore terminate_cmdthread_sema with completion

 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c      | 20 ++++++++++----------
 drivers/staging/rtl8188eu/include/osdep_service.h |  3 +--
 drivers/staging/rtl8188eu/include/rtw_event.h     |  1 +
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h   | 17 +----------------
 drivers/staging/rtl8188eu/os_dep/osdep_service.c  |  7 -------
 drivers/staging/rtl8188eu/os_dep/usb_intf.c       |  8 ++++----
 6 files changed, 17 insertions(+), 39 deletions(-)
drivers/staging/rtl8188eu/core/rtw_pwrctrl.c +10 -10
index 59c6d8a..0b70fe7 100644
@@ -38,7 +38,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
 	LeaveAllPowerSaveMode(padapter);
 
 	DBG_88E("==> rtw_hw_suspend\n");
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	pwrpriv->bips_processing = true;
 	/* s1. */
 	if (pnetdev) {
@@ -73,7 +73,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
 	pwrpriv->rf_pwrstate = rf_off;
 	pwrpriv->bips_processing = false;
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 	return 0;
 
@@ -90,12 +90,12 @@ static int rtw_hw_resume(struct adapter *padapter)
 
 	/* system resume */
 	DBG_88E("==> rtw_hw_resume\n");
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	pwrpriv->bips_processing = true;
 	rtw_reset_drv_sw(padapter);
 
 	if (pm_netdev_open(pnetdev, false) != 0) {
-		_exit_pwrlock(&pwrpriv->lock);
+		mutex_unlock(&pwrpriv->mutex_lock);
 		goto error_exit;
 	}
 
@@ -113,7 +113,7 @@ static int rtw_hw_resume(struct adapter *padapter)
 	pwrpriv->rf_pwrstate = rf_on;
 	pwrpriv->bips_processing = false;
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 
 	return 0;
@@ -138,7 +138,7 @@ void ips_enter(struct adapter *padapter)
 		return;
 	}
 
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 
 	pwrpriv->bips_processing = true;
 
@@ -159,7 +159,7 @@ void ips_enter(struct adapter *padapter)
 	}
 	pwrpriv->bips_processing = false;
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 }
 
 int ips_leave(struct adapter *padapter)
@@ -171,7 +171,7 @@ int ips_leave(struct adapter *padapter)
 	int keyid;
 
 
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 
 	if ((pwrpriv->rf_pwrstate == rf_off) && (!pwrpriv->bips_processing)) {
 		pwrpriv->bips_processing = true;
@@ -205,7 +205,7 @@ int ips_leave(struct adapter *padapter)
 		pwrpriv->bpower_saving = false;
 	}
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 	return result;
 }
@@ -504,7 +504,7 @@ void rtw_init_pwrctrl_priv(struct adapter *padapter)
 {
 	struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
 
-	_init_pwrlock(&pwrctrlpriv->lock);
+	mutex_init(&pwrctrlpriv->mutex_lock);
 	pwrctrlpriv->rf_pwrstate = rf_on;
 	pwrctrlpriv->ips_enter_cnts = 0;
 	pwrctrlpriv->ips_leave_cnts = 0;
drivers/staging/rtl8188eu/include/osdep_service.h +1 -2
index 5475956..c53c9ea 100644
@@ -36,6 +36,7 @@
 #include <linux/atomic.h>
 #include <linux/io.h>
 #include <linux/semaphore.h>
+#include <linux/mutex.h>
 #include <linux/sem.h>
 #include <linux/sched.h>
 #include <linux/etherdevice.h>
@@ -78,8 +79,6 @@ u8 *_rtw_malloc(u32 sz);
 
 void *rtw_malloc2d(int h, int w, int size);
 
-u32  _rtw_down_sema(struct semaphore *sema);
-
 void _rtw_init_queue(struct __queue *pqueue);
 
 struct rtw_netdev_priv_indicator {
drivers/staging/rtl8188eu/include/rtw_event.h +1 -0
index 5c34e56..0dc63f2 100644
@@ -19,6 +19,7 @@
 
 #include <wlan_bssdef.h>
 #include <linux/semaphore.h>
+#include <linux/mutex.h>
 #include <linux/sem.h>
 
 /*
drivers/staging/rtl8188eu/include/rtw_pwrctrl.h +1 -16
index 9680e2e..18a9e74 100644
@@ -92,21 +92,6 @@ struct reportpwrstate_parm {
 	unsigned short rsvd;
 };
 
-static inline void _init_pwrlock(struct semaphore  *plock)
-{
-	sema_init(plock, 1);
-}
-
-static inline void _enter_pwrlock(struct semaphore  *plock)
-{
-	_rtw_down_sema(plock);
-}
-
-static inline void _exit_pwrlock(struct semaphore  *plock)
-{
-	up(plock);
-}
-
 #define LPS_DELAY_TIME	1*HZ /*  1 sec */
 
 #define EXE_PWR_NONE	0x01
@@ -157,7 +142,7 @@ enum { /*  for ips_mode */
 };
 
 struct pwrctrl_priv {
-	struct semaphore lock;
+	struct mutex mutex_lock;
 	volatile u8 rpwm; /*  requested power state for fw */
 	volatile u8 cpwm; /*  fw current power state. updated when
 			   * 1. read from HCPWM 2. driver lowers power level */
drivers/staging/rtl8188eu/os_dep/osdep_service.c +0 -7
index 764250b..24d1774 100644
@@ -55,13 +55,6 @@ void *rtw_malloc2d(int h, int w, int size)
 	return a;
 }
 
-u32 _rtw_down_sema(struct semaphore *sema)
-{
-	if (down_interruptible(sema))
-		return _FAIL;
-	return _SUCCESS;
-}
-
 void	_rtw_init_queue(struct __queue *pqueue)
 {
 	INIT_LIST_HEAD(&(pqueue->queue));
drivers/staging/rtl8188eu/os_dep/usb_intf.c +4 -4
index 11d51a3..a5ba1e4 100644
@@ -238,7 +238,7 @@ static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
 	rtw_cancel_all_timer(padapter);
 	LeaveAllPowerSaveMode(padapter);
 
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	/* s1. */
 	if (pnetdev) {
 		netif_carrier_off(pnetdev);
@@ -267,7 +267,7 @@ static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
 	rtw_free_network_queue(padapter, true);
 
 	rtw_dev_unload(padapter);
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 	if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
 		rtw_indicate_scan_done(padapter, 1);
@@ -298,7 +298,7 @@ static int rtw_resume_process(struct adapter *padapter)
 		goto exit;
 	}
 
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	rtw_reset_drv_sw(padapter);
 	pwrpriv->bkeepfwalive = false;
 
@@ -309,7 +309,7 @@ static int rtw_resume_process(struct adapter *padapter)
 	netif_device_attach(pnetdev);
 	netif_carrier_on(pnetdev);
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 	rtw_roaming(padapter, NULL);
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#5 lore raw

PATCH 4/4 rtl8188eu: Remove unused semaphores

In reply to Binoy Jayan

The semaphores xmit_sema, terminate_xmitthread_sema and tx_retevt have no users, hence remove all references to them.

---
This patch depends on the following patch:
rtl8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex

 drivers/staging/rtl8188eu/core/rtw_xmit.c         | 4 ----
 drivers/staging/rtl8188eu/include/osdep_service.h | 1 -
 drivers/staging/rtl8188eu/include/rtw_event.h     | 1 -
 drivers/staging/rtl8188eu/include/rtw_xmit.h      | 3 ---
 4 files changed, 9 deletions(-)
drivers/staging/rtl8188eu/core/rtw_xmit.c +0 -4
index e0a5567..1e1b6d8 100644
@@ -57,8 +57,6 @@ s32	_rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
 	/*  We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */
 
 	spin_lock_init(&pxmitpriv->lock);
-	sema_init(&pxmitpriv->xmit_sema, 0);
-	sema_init(&pxmitpriv->terminate_xmitthread_sema, 0);
 
 	/*
 	Please insert all the queue initializaiton using _rtw_init_queue below
@@ -199,8 +197,6 @@ s32	_rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
 
 	pxmitpriv->txirp_cnt = 1;
 
-	sema_init(&(pxmitpriv->tx_retevt), 0);
-
 	/* per AC pending irp */
 	pxmitpriv->beq_cnt = 0;
 	pxmitpriv->bkq_cnt = 0;
drivers/staging/rtl8188eu/include/osdep_service.h +0 -1
index c53c9ea..6f6a8f8 100644
@@ -35,7 +35,6 @@
 #include <asm/byteorder.h>
 #include <linux/atomic.h>
 #include <linux/io.h>
-#include <linux/semaphore.h>
 #include <linux/mutex.h>
 #include <linux/sem.h>
 #include <linux/sched.h>
drivers/staging/rtl8188eu/include/rtw_event.h +0 -1
index 0dc63f2..2a45581 100644
@@ -18,7 +18,6 @@
 #include <osdep_service.h>
 
 #include <wlan_bssdef.h>
-#include <linux/semaphore.h>
 #include <linux/mutex.h>
 #include <linux/sem.h>
 
drivers/staging/rtl8188eu/include/rtw_xmit.h +0 -3
index a0853ba..7895008 100644
@@ -263,8 +263,6 @@ struct agg_pkt_info {
 
 struct	xmit_priv {
 	spinlock_t lock;
-	struct semaphore xmit_sema;
-	struct semaphore terminate_xmitthread_sema;
 	struct __queue be_pending;
 	struct __queue bk_pending;
 	struct __queue vi_pending;
@@ -289,7 +287,6 @@ struct	xmit_priv {
 	u8	wmm_para_seq[4];/* sequence for wmm ac parameter strength
 				 * from large to small. it's value is 0->vo,
 				 * 1->vi, 2->be, 3->bk. */
-	struct semaphore tx_retevt;/* all tx return event; */
 	u8		txirp_cnt;/*  */
 	struct tasklet_struct xmit_tasklet;
 	/* per AC pending irp */
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#3 lore raw

PATCH 2/4 rtl8188eu: Replace semaphore terminate_cmdthread_sema with completion

In reply to Binoy Jayan

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

---
This patch depends on the following patch:
irtl8188eu: Replace semaphore cmd_queue_sema with completion

 drivers/staging/rtl8188eu/core/rtw_cmd.c    | 6 +++---
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/os_intfs.c | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8188eu/core/rtw_cmd.c +3 -3
index a2937e7..9e12588 100644
@@ -28,7 +28,7 @@ No irqsave is necessary.
 int rtw_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);
 
 	_rtw_init_queue(&(pcmdpriv->cmd_queue));
 	return _SUCCESS;
@@ -162,7 +162,7 @@ int rtw_cmd_thread(void *context)
 	allow_signal(SIGTERM);
 
 	pcmdpriv->cmdthd_running = true;
-	up(&pcmdpriv->terminate_cmdthread_sema);
+	complete(&pcmdpriv->terminate_cmdthread_comp);
 
 	RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("start r871x rtw_cmd_thread !!!!\n"));
 
@@ -234,7 +234,7 @@ _next:
 		rtw_free_cmd_obj(pcmd);
 	}
 
-	up(&pcmdpriv->terminate_cmdthread_sema);
+	complete(&pcmdpriv->terminate_cmdthread_comp);
 
 
 	complete_and_exit(NULL, 0);
drivers/staging/rtl8188eu/include/rtw_cmd.h +1 -1
index 3532dd1..2b53f58 100644
@@ -40,7 +40,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 cmdthd_running;
 	struct adapter *padapter;
drivers/staging/rtl8188eu/os_dep/os_intfs.c +2 -2
index a696d2b..c494845 100644
@@ -762,7 +762,7 @@ static int rtw_start_drv_threads(struct adapter *padapter)
 		err = PTR_ERR(padapter->cmdThread);
 	else
 		/* wait for cmd_thread to run */
-		_rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+		wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 
 	return err;
 }
@@ -774,7 +774,7 @@ void rtw_stop_drv_threads(struct adapter *padapter)
 	/* Below is to terminate rtw_cmd_thread & event_thread... */
 	complete(&padapter->cmdpriv.cmd_queue_comp);
 	if (padapter->cmdThread)
-		_rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+		wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 
 }
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
Reviewed-by on the v1 series
#6 lore raw
In reply to Binoy Jayan
Quoted 5 lines · CEST Binoy Jayan

These are a set of patches which removes semaphores from:

drivers/staging/rtl8188eu

Quoted 9 lines

These are part of a bigger effort to eliminate all semaphores from the linux kernel.

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

"Realtek RTL8188EU Wireless LAN NIC driver"

The patches all look good to me. Patch three again could use some information describing that it replaces an interruptible semaphore with an uninterruptible mutex, fixing a bug in the process.

BTW, there is no need to list the dependencies in each patch when posting a series, as the default assumption is that they need to be applied in sequence.

Acked-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] irtl8188eu: Replace semaphore cmd_queue_sema with completion

In reply to Binoy Jayan
Quoted 4 lines · Binoy Jayan

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

The subject for this patch has a misplaced "i" at the beginning courtesy of vi.

One other point, it is customary to start the patch subject with "staging: rtl8188eu: ..." for drivers in staging. I also prefer using r8188eu rather than rtl8188eu as the former is the actual name of the driver, but either will work.

I have tested all 4 of these patches with no problems, thus

As you may have noted, my testing of the modified driver has resulted in some additional fixes for various problems including a system panic caused by an ill-advised and untested change.

Larry

#7 lore raw

v2 cover *** rtl8188eu: Replace semaphores with mutexes or completions ***

In reply to Binoy Jayan

Hi,

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

drivers/staging/rtl8188eu

These are part of a bigger effort to eliminate all semaphores from the linux kernel.

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

"Realtek RTL8188EU Wireless LAN NIC driver"

Incorporated changes w.r.t. review comments:
- Changed changelog in patch 3/4

Thanks,
Binoy

Binoy Jayan (4):
irtl8188eu: Replace semaphore cmd_queue_sema with completion
rtl8188eu: Replace semaphore terminate_cmdthread_sema with completion
rtl8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex
rtl8188eu: Remove unused semaphores

 drivers/staging/rtl8188eu/core/rtw_cmd.c          | 12 ++++++------
 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c      | 20 ++++++++++----------
 drivers/staging/rtl8188eu/core/rtw_xmit.c         |  4 ----
 drivers/staging/rtl8188eu/include/osdep_service.h |  4 +---
 drivers/staging/rtl8188eu/include/rtw_cmd.h       |  4 ++--
 drivers/staging/rtl8188eu/include/rtw_event.h     |  2 +-
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h   | 17 +----------------
 drivers/staging/rtl8188eu/include/rtw_xmit.h      |  3 ---
 drivers/staging/rtl8188eu/os_dep/os_intfs.c       |  6 +++---
 drivers/staging/rtl8188eu/os_dep/osdep_service.c  |  7 -------
 drivers/staging/rtl8188eu/os_dep/usb_intf.c       |  8 ++++----
 11 files changed, 28 insertions(+), 59 deletions(-)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#8 lore raw

PATCH v2 1/4 irtl8188eu: Replace semaphore cmd_queue_sema with completion

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

---
 drivers/staging/rtl8188eu/core/rtw_cmd.c    | 6 +++---
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/os_intfs.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/rtl8188eu/core/rtw_cmd.c +3 -3
index 7748523..a2937e7 100644
@@ -27,7 +27,7 @@ No irqsave is necessary.
 
 int rtw_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);
 
 	_rtw_init_queue(&(pcmdpriv->cmd_queue));
@@ -122,7 +122,7 @@ u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
 	res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj);
 
 	if (res == _SUCCESS)
-		up(&pcmdpriv->cmd_queue_sema);
+		complete(&pcmdpriv->cmd_queue_comp);
 
 exit:
 
@@ -167,7 +167,7 @@ int rtw_cmd_thread(void *context)
 	RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("start r871x rtw_cmd_thread !!!!\n"));
 
 	while (1) {
-		if (_rtw_down_sema(&pcmdpriv->cmd_queue_sema) == _FAIL)
+		if (wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp))
 			break;
 
 		if (padapter->bDriverStopped ||
drivers/staging/rtl8188eu/include/rtw_cmd.h +1 -1
index 08ca592..3532dd1 100644
@@ -39,7 +39,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 cmdthd_running;
drivers/staging/rtl8188eu/os_dep/os_intfs.c +1 -1
index ae2caff..a696d2b 100644
@@ -772,7 +772,7 @@ void rtw_stop_drv_threads(struct adapter *padapter)
 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_stop_drv_threads\n"));
 
 	/* Below is to terminate rtw_cmd_thread & event_thread... */
-	up(&padapter->cmdpriv.cmd_queue_sema);
+	complete(&padapter->cmdpriv.cmd_queue_comp);
 	if (padapter->cmdThread)
 		_rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#9 lore raw

PATCH v2 2/4 rtl8188eu: Replace semaphore terminate_cmdthread_sema with completion

In reply to Binoy Jayan

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

---
 drivers/staging/rtl8188eu/core/rtw_cmd.c    | 6 +++---
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/os_intfs.c | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8188eu/core/rtw_cmd.c +3 -3
index a2937e7..9e12588 100644
@@ -28,7 +28,7 @@ No irqsave is necessary.
 int rtw_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);
 
 	_rtw_init_queue(&(pcmdpriv->cmd_queue));
 	return _SUCCESS;
@@ -162,7 +162,7 @@ int rtw_cmd_thread(void *context)
 	allow_signal(SIGTERM);
 
 	pcmdpriv->cmdthd_running = true;
-	up(&pcmdpriv->terminate_cmdthread_sema);
+	complete(&pcmdpriv->terminate_cmdthread_comp);
 
 	RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("start r871x rtw_cmd_thread !!!!\n"));
 
@@ -234,7 +234,7 @@ _next:
 		rtw_free_cmd_obj(pcmd);
 	}
 
-	up(&pcmdpriv->terminate_cmdthread_sema);
+	complete(&pcmdpriv->terminate_cmdthread_comp);
 
 
 	complete_and_exit(NULL, 0);
drivers/staging/rtl8188eu/include/rtw_cmd.h +1 -1
index 3532dd1..2b53f58 100644
@@ -40,7 +40,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 cmdthd_running;
 	struct adapter *padapter;
drivers/staging/rtl8188eu/os_dep/os_intfs.c +2 -2
index a696d2b..c494845 100644
@@ -762,7 +762,7 @@ static int rtw_start_drv_threads(struct adapter *padapter)
 		err = PTR_ERR(padapter->cmdThread);
 	else
 		/* wait for cmd_thread to run */
-		_rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+		wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 
 	return err;
 }
@@ -774,7 +774,7 @@ void rtw_stop_drv_threads(struct adapter *padapter)
 	/* Below is to terminate rtw_cmd_thread & event_thread... */
 	complete(&padapter->cmdpriv.cmd_queue_comp);
 	if (padapter->cmdThread)
-		_rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+		wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 
 }
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#11 lore raw

PATCH v2 4/4 rtl8188eu: Remove unused semaphores

In reply to Binoy Jayan

The semaphores xmit_sema, terminate_xmitthread_sema and tx_retevt have no users, hence remove all references to them.

---
 drivers/staging/rtl8188eu/core/rtw_xmit.c         | 4 ----
 drivers/staging/rtl8188eu/include/osdep_service.h | 1 -
 drivers/staging/rtl8188eu/include/rtw_event.h     | 1 -
 drivers/staging/rtl8188eu/include/rtw_xmit.h      | 3 ---
 4 files changed, 9 deletions(-)
drivers/staging/rtl8188eu/core/rtw_xmit.c +0 -4
index e0a5567..1e1b6d8 100644
@@ -57,8 +57,6 @@ s32	_rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
 	/*  We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */
 
 	spin_lock_init(&pxmitpriv->lock);
-	sema_init(&pxmitpriv->xmit_sema, 0);
-	sema_init(&pxmitpriv->terminate_xmitthread_sema, 0);
 
 	/*
 	Please insert all the queue initializaiton using _rtw_init_queue below
@@ -199,8 +197,6 @@ s32	_rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
 
 	pxmitpriv->txirp_cnt = 1;
 
-	sema_init(&(pxmitpriv->tx_retevt), 0);
-
 	/* per AC pending irp */
 	pxmitpriv->beq_cnt = 0;
 	pxmitpriv->bkq_cnt = 0;
drivers/staging/rtl8188eu/include/osdep_service.h +0 -1
index c53c9ea..6f6a8f8 100644
@@ -35,7 +35,6 @@
 #include <asm/byteorder.h>
 #include <linux/atomic.h>
 #include <linux/io.h>
-#include <linux/semaphore.h>
 #include <linux/mutex.h>
 #include <linux/sem.h>
 #include <linux/sched.h>
drivers/staging/rtl8188eu/include/rtw_event.h +0 -1
index 0dc63f2..2a45581 100644
@@ -18,7 +18,6 @@
 #include <osdep_service.h>
 
 #include <wlan_bssdef.h>
-#include <linux/semaphore.h>
 #include <linux/mutex.h>
 #include <linux/sem.h>
 
drivers/staging/rtl8188eu/include/rtw_xmit.h +0 -3
index a0853ba..7895008 100644
@@ -263,8 +263,6 @@ struct agg_pkt_info {
 
 struct	xmit_priv {
 	spinlock_t lock;
-	struct semaphore xmit_sema;
-	struct semaphore terminate_xmitthread_sema;
 	struct __queue be_pending;
 	struct __queue bk_pending;
 	struct __queue vi_pending;
@@ -289,7 +287,6 @@ struct	xmit_priv {
 	u8	wmm_para_seq[4];/* sequence for wmm ac parameter strength
 				 * from large to small. it's value is 0->vo,
 				 * 1->vi, 2->be, 3->bk. */
-	struct semaphore tx_retevt;/* all tx return event; */
 	u8		txirp_cnt;/*  */
 	struct tasklet_struct xmit_tasklet;
 	/* per AC pending irp */
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#10 lore raw

PATCH v2 3/4 rtl8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex

In reply to Binoy Jayan

The semaphore 'lock' in pwrctrl_priv is 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. Also, remove the now unused wrappers _init_pwrlock, _enter_pwrlock, _exit_pwrlock and _rtw_down_sema.

---
 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c      | 20 ++++++++++----------
 drivers/staging/rtl8188eu/include/osdep_service.h |  3 +--
 drivers/staging/rtl8188eu/include/rtw_event.h     |  1 +
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h   | 17 +----------------
 drivers/staging/rtl8188eu/os_dep/osdep_service.c  |  7 -------
 drivers/staging/rtl8188eu/os_dep/usb_intf.c       |  8 ++++----
 6 files changed, 17 insertions(+), 39 deletions(-)
drivers/staging/rtl8188eu/core/rtw_pwrctrl.c +10 -10
index 59c6d8a..0b70fe7 100644
@@ -38,7 +38,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
 	LeaveAllPowerSaveMode(padapter);
 
 	DBG_88E("==> rtw_hw_suspend\n");
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	pwrpriv->bips_processing = true;
 	/* s1. */
 	if (pnetdev) {
@@ -73,7 +73,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
 	pwrpriv->rf_pwrstate = rf_off;
 	pwrpriv->bips_processing = false;
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 	return 0;
 
@@ -90,12 +90,12 @@ static int rtw_hw_resume(struct adapter *padapter)
 
 	/* system resume */
 	DBG_88E("==> rtw_hw_resume\n");
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	pwrpriv->bips_processing = true;
 	rtw_reset_drv_sw(padapter);
 
 	if (pm_netdev_open(pnetdev, false) != 0) {
-		_exit_pwrlock(&pwrpriv->lock);
+		mutex_unlock(&pwrpriv->mutex_lock);
 		goto error_exit;
 	}
 
@@ -113,7 +113,7 @@ static int rtw_hw_resume(struct adapter *padapter)
 	pwrpriv->rf_pwrstate = rf_on;
 	pwrpriv->bips_processing = false;
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 
 	return 0;
@@ -138,7 +138,7 @@ void ips_enter(struct adapter *padapter)
 		return;
 	}
 
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 
 	pwrpriv->bips_processing = true;
 
@@ -159,7 +159,7 @@ void ips_enter(struct adapter *padapter)
 	}
 	pwrpriv->bips_processing = false;
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 }
 
 int ips_leave(struct adapter *padapter)
@@ -171,7 +171,7 @@ int ips_leave(struct adapter *padapter)
 	int keyid;
 
 
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 
 	if ((pwrpriv->rf_pwrstate == rf_off) && (!pwrpriv->bips_processing)) {
 		pwrpriv->bips_processing = true;
@@ -205,7 +205,7 @@ int ips_leave(struct adapter *padapter)
 		pwrpriv->bpower_saving = false;
 	}
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 	return result;
 }
@@ -504,7 +504,7 @@ void rtw_init_pwrctrl_priv(struct adapter *padapter)
 {
 	struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
 
-	_init_pwrlock(&pwrctrlpriv->lock);
+	mutex_init(&pwrctrlpriv->mutex_lock);
 	pwrctrlpriv->rf_pwrstate = rf_on;
 	pwrctrlpriv->ips_enter_cnts = 0;
 	pwrctrlpriv->ips_leave_cnts = 0;
drivers/staging/rtl8188eu/include/osdep_service.h +1 -2
index 5475956..c53c9ea 100644
@@ -36,6 +36,7 @@
 #include <linux/atomic.h>
 #include <linux/io.h>
 #include <linux/semaphore.h>
+#include <linux/mutex.h>
 #include <linux/sem.h>
 #include <linux/sched.h>
 #include <linux/etherdevice.h>
@@ -78,8 +79,6 @@ u8 *_rtw_malloc(u32 sz);
 
 void *rtw_malloc2d(int h, int w, int size);
 
-u32  _rtw_down_sema(struct semaphore *sema);
-
 void _rtw_init_queue(struct __queue *pqueue);
 
 struct rtw_netdev_priv_indicator {
drivers/staging/rtl8188eu/include/rtw_event.h +1 -0
index 5c34e56..0dc63f2 100644
@@ -19,6 +19,7 @@
 
 #include <wlan_bssdef.h>
 #include <linux/semaphore.h>
+#include <linux/mutex.h>
 #include <linux/sem.h>
 
 /*
drivers/staging/rtl8188eu/include/rtw_pwrctrl.h +1 -16
index 9680e2e..18a9e74 100644
@@ -92,21 +92,6 @@ struct reportpwrstate_parm {
 	unsigned short rsvd;
 };
 
-static inline void _init_pwrlock(struct semaphore  *plock)
-{
-	sema_init(plock, 1);
-}
-
-static inline void _enter_pwrlock(struct semaphore  *plock)
-{
-	_rtw_down_sema(plock);
-}
-
-static inline void _exit_pwrlock(struct semaphore  *plock)
-{
-	up(plock);
-}
-
 #define LPS_DELAY_TIME	1*HZ /*  1 sec */
 
 #define EXE_PWR_NONE	0x01
@@ -157,7 +142,7 @@ enum { /*  for ips_mode */
 };
 
 struct pwrctrl_priv {
-	struct semaphore lock;
+	struct mutex mutex_lock;
 	volatile u8 rpwm; /*  requested power state for fw */
 	volatile u8 cpwm; /*  fw current power state. updated when
 			   * 1. read from HCPWM 2. driver lowers power level */
drivers/staging/rtl8188eu/os_dep/osdep_service.c +0 -7
index 764250b..24d1774 100644
@@ -55,13 +55,6 @@ void *rtw_malloc2d(int h, int w, int size)
 	return a;
 }
 
-u32 _rtw_down_sema(struct semaphore *sema)
-{
-	if (down_interruptible(sema))
-		return _FAIL;
-	return _SUCCESS;
-}
-
 void	_rtw_init_queue(struct __queue *pqueue)
 {
 	INIT_LIST_HEAD(&(pqueue->queue));
drivers/staging/rtl8188eu/os_dep/usb_intf.c +4 -4
index 11d51a3..a5ba1e4 100644
@@ -238,7 +238,7 @@ static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
 	rtw_cancel_all_timer(padapter);
 	LeaveAllPowerSaveMode(padapter);
 
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	/* s1. */
 	if (pnetdev) {
 		netif_carrier_off(pnetdev);
@@ -267,7 +267,7 @@ static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
 	rtw_free_network_queue(padapter, true);
 
 	rtw_dev_unload(padapter);
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 	if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
 		rtw_indicate_scan_done(padapter, 1);
@@ -298,7 +298,7 @@ static int rtw_resume_process(struct adapter *padapter)
 		goto exit;
 	}
 
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	rtw_reset_drv_sw(padapter);
 	pwrpriv->bkeepfwalive = false;
 
@@ -309,7 +309,7 @@ static int rtw_resume_process(struct adapter *padapter)
 	netif_device_attach(pnetdev);
 	netif_carrier_on(pnetdev);
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 	rtw_roaming(padapter, NULL);
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#12 lore raw

v3 cover *** staging: r8188eu: Replace semaphores with mutexes or completions ***

In reply to Binoy Jayan

Hi,

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

drivers/staging/rtl8188eu

These are part of a bigger effort to eliminate all semaphores from the linux kernel.

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

"Realtek RTL8188EU Wireless LAN NIC driver"

Incorporated changes w.r.t. review comments
- Changed changelog in patch 3/4
- Changed subject line to have driver name r8188eu
- Removed misplaced 'i' in subject of patch 1/4

Thanks,
Binoy

Binoy Jayan (4):
staging: r8188eu: Replace semaphore cmd_queue_sema with completion
staging: r8188eu: Replace semaphore terminate_cmdthread_sema with
completion
staging: r8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex
staging: r8188eu: Remove unused semaphores

 drivers/staging/rtl8188eu/core/rtw_cmd.c          | 12 ++++++------
 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c      | 20 ++++++++++----------
 drivers/staging/rtl8188eu/core/rtw_xmit.c         |  4 ----
 drivers/staging/rtl8188eu/include/osdep_service.h |  4 +---
 drivers/staging/rtl8188eu/include/rtw_cmd.h       |  4 ++--
 drivers/staging/rtl8188eu/include/rtw_event.h     |  2 +-
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h   | 17 +----------------
 drivers/staging/rtl8188eu/include/rtw_xmit.h      |  3 ---
 drivers/staging/rtl8188eu/os_dep/os_intfs.c       |  6 +++---
 drivers/staging/rtl8188eu/os_dep/osdep_service.c  |  7 -------
 drivers/staging/rtl8188eu/os_dep/usb_intf.c       |  8 ++++----
 11 files changed, 28 insertions(+), 59 deletions(-)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#13 lore raw

PATCH v3 1/4 staging: r8188eu: Replace semaphore cmd_queue_sema with completion

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

---
 drivers/staging/rtl8188eu/core/rtw_cmd.c    | 6 +++---
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/os_intfs.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/rtl8188eu/core/rtw_cmd.c +3 -3
index 7748523..a2937e7 100644
@@ -27,7 +27,7 @@ No irqsave is necessary.
 
 int rtw_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);
 
 	_rtw_init_queue(&(pcmdpriv->cmd_queue));
@@ -122,7 +122,7 @@ u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
 	res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj);
 
 	if (res == _SUCCESS)
-		up(&pcmdpriv->cmd_queue_sema);
+		complete(&pcmdpriv->cmd_queue_comp);
 
 exit:
 
@@ -167,7 +167,7 @@ int rtw_cmd_thread(void *context)
 	RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("start r871x rtw_cmd_thread !!!!\n"));
 
 	while (1) {
-		if (_rtw_down_sema(&pcmdpriv->cmd_queue_sema) == _FAIL)
+		if (wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp))
 			break;
 
 		if (padapter->bDriverStopped ||
drivers/staging/rtl8188eu/include/rtw_cmd.h +1 -1
index 08ca592..3532dd1 100644
@@ -39,7 +39,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 cmdthd_running;
drivers/staging/rtl8188eu/os_dep/os_intfs.c +1 -1
index ae2caff..a696d2b 100644
@@ -772,7 +772,7 @@ void rtw_stop_drv_threads(struct adapter *padapter)
 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_stop_drv_threads\n"));
 
 	/* Below is to terminate rtw_cmd_thread & event_thread... */
-	up(&padapter->cmdpriv.cmd_queue_sema);
+	complete(&padapter->cmdpriv.cmd_queue_comp);
 	if (padapter->cmdThread)
 		_rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#15 lore raw

PATCH v3 3/4 staging: r8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex

In reply to Binoy Jayan

The semaphore 'lock' in pwrctrl_priv is 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. Also, remove the now unused wrappers _init_pwrlock, _enter_pwrlock, _exit_pwrlock and _rtw_down_sema.

---
 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c      | 20 ++++++++++----------
 drivers/staging/rtl8188eu/include/osdep_service.h |  3 +--
 drivers/staging/rtl8188eu/include/rtw_event.h     |  1 +
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h   | 17 +----------------
 drivers/staging/rtl8188eu/os_dep/osdep_service.c  |  7 -------
 drivers/staging/rtl8188eu/os_dep/usb_intf.c       |  8 ++++----
 6 files changed, 17 insertions(+), 39 deletions(-)
drivers/staging/rtl8188eu/core/rtw_pwrctrl.c +10 -10
index 59c6d8a..0b70fe7 100644
@@ -38,7 +38,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
 	LeaveAllPowerSaveMode(padapter);
 
 	DBG_88E("==> rtw_hw_suspend\n");
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	pwrpriv->bips_processing = true;
 	/* s1. */
 	if (pnetdev) {
@@ -73,7 +73,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
 	pwrpriv->rf_pwrstate = rf_off;
 	pwrpriv->bips_processing = false;
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 	return 0;
 
@@ -90,12 +90,12 @@ static int rtw_hw_resume(struct adapter *padapter)
 
 	/* system resume */
 	DBG_88E("==> rtw_hw_resume\n");
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	pwrpriv->bips_processing = true;
 	rtw_reset_drv_sw(padapter);
 
 	if (pm_netdev_open(pnetdev, false) != 0) {
-		_exit_pwrlock(&pwrpriv->lock);
+		mutex_unlock(&pwrpriv->mutex_lock);
 		goto error_exit;
 	}
 
@@ -113,7 +113,7 @@ static int rtw_hw_resume(struct adapter *padapter)
 	pwrpriv->rf_pwrstate = rf_on;
 	pwrpriv->bips_processing = false;
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 
 	return 0;
@@ -138,7 +138,7 @@ void ips_enter(struct adapter *padapter)
 		return;
 	}
 
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 
 	pwrpriv->bips_processing = true;
 
@@ -159,7 +159,7 @@ void ips_enter(struct adapter *padapter)
 	}
 	pwrpriv->bips_processing = false;
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 }
 
 int ips_leave(struct adapter *padapter)
@@ -171,7 +171,7 @@ int ips_leave(struct adapter *padapter)
 	int keyid;
 
 
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 
 	if ((pwrpriv->rf_pwrstate == rf_off) && (!pwrpriv->bips_processing)) {
 		pwrpriv->bips_processing = true;
@@ -205,7 +205,7 @@ int ips_leave(struct adapter *padapter)
 		pwrpriv->bpower_saving = false;
 	}
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 	return result;
 }
@@ -504,7 +504,7 @@ void rtw_init_pwrctrl_priv(struct adapter *padapter)
 {
 	struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
 
-	_init_pwrlock(&pwrctrlpriv->lock);
+	mutex_init(&pwrctrlpriv->mutex_lock);
 	pwrctrlpriv->rf_pwrstate = rf_on;
 	pwrctrlpriv->ips_enter_cnts = 0;
 	pwrctrlpriv->ips_leave_cnts = 0;
drivers/staging/rtl8188eu/include/osdep_service.h +1 -2
index 5475956..c53c9ea 100644
@@ -36,6 +36,7 @@
 #include <linux/atomic.h>
 #include <linux/io.h>
 #include <linux/semaphore.h>
+#include <linux/mutex.h>
 #include <linux/sem.h>
 #include <linux/sched.h>
 #include <linux/etherdevice.h>
@@ -78,8 +79,6 @@ u8 *_rtw_malloc(u32 sz);
 
 void *rtw_malloc2d(int h, int w, int size);
 
-u32  _rtw_down_sema(struct semaphore *sema);
-
 void _rtw_init_queue(struct __queue *pqueue);
 
 struct rtw_netdev_priv_indicator {
drivers/staging/rtl8188eu/include/rtw_event.h +1 -0
index 5c34e56..0dc63f2 100644
@@ -19,6 +19,7 @@
 
 #include <wlan_bssdef.h>
 #include <linux/semaphore.h>
+#include <linux/mutex.h>
 #include <linux/sem.h>
 
 /*
drivers/staging/rtl8188eu/include/rtw_pwrctrl.h +1 -16
index 9680e2e..18a9e74 100644
@@ -92,21 +92,6 @@ struct reportpwrstate_parm {
 	unsigned short rsvd;
 };
 
-static inline void _init_pwrlock(struct semaphore  *plock)
-{
-	sema_init(plock, 1);
-}
-
-static inline void _enter_pwrlock(struct semaphore  *plock)
-{
-	_rtw_down_sema(plock);
-}
-
-static inline void _exit_pwrlock(struct semaphore  *plock)
-{
-	up(plock);
-}
-
 #define LPS_DELAY_TIME	1*HZ /*  1 sec */
 
 #define EXE_PWR_NONE	0x01
@@ -157,7 +142,7 @@ enum { /*  for ips_mode */
 };
 
 struct pwrctrl_priv {
-	struct semaphore lock;
+	struct mutex mutex_lock;
 	volatile u8 rpwm; /*  requested power state for fw */
 	volatile u8 cpwm; /*  fw current power state. updated when
 			   * 1. read from HCPWM 2. driver lowers power level */
drivers/staging/rtl8188eu/os_dep/osdep_service.c +0 -7
index 764250b..24d1774 100644
@@ -55,13 +55,6 @@ void *rtw_malloc2d(int h, int w, int size)
 	return a;
 }
 
-u32 _rtw_down_sema(struct semaphore *sema)
-{
-	if (down_interruptible(sema))
-		return _FAIL;
-	return _SUCCESS;
-}
-
 void	_rtw_init_queue(struct __queue *pqueue)
 {
 	INIT_LIST_HEAD(&(pqueue->queue));
drivers/staging/rtl8188eu/os_dep/usb_intf.c +4 -4
index 11d51a3..a5ba1e4 100644
@@ -238,7 +238,7 @@ static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
 	rtw_cancel_all_timer(padapter);
 	LeaveAllPowerSaveMode(padapter);
 
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	/* s1. */
 	if (pnetdev) {
 		netif_carrier_off(pnetdev);
@@ -267,7 +267,7 @@ static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
 	rtw_free_network_queue(padapter, true);
 
 	rtw_dev_unload(padapter);
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 	if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
 		rtw_indicate_scan_done(padapter, 1);
@@ -298,7 +298,7 @@ static int rtw_resume_process(struct adapter *padapter)
 		goto exit;
 	}
 
-	_enter_pwrlock(&pwrpriv->lock);
+	mutex_lock(&pwrpriv->mutex_lock);
 	rtw_reset_drv_sw(padapter);
 	pwrpriv->bkeepfwalive = false;
 
@@ -309,7 +309,7 @@ static int rtw_resume_process(struct adapter *padapter)
 	netif_device_attach(pnetdev);
 	netif_carrier_on(pnetdev);
 
-	_exit_pwrlock(&pwrpriv->lock);
+	mutex_unlock(&pwrpriv->mutex_lock);
 
 	rtw_roaming(padapter, NULL);
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#16 lore raw

PATCH v3 4/4 staging: r8188eu: Remove unused semaphores

In reply to Binoy Jayan

The semaphores xmit_sema, terminate_xmitthread_sema and tx_retevt have no users, hence remove all references to them.

---
 drivers/staging/rtl8188eu/core/rtw_xmit.c         | 4 ----
 drivers/staging/rtl8188eu/include/osdep_service.h | 1 -
 drivers/staging/rtl8188eu/include/rtw_event.h     | 1 -
 drivers/staging/rtl8188eu/include/rtw_xmit.h      | 3 ---
 4 files changed, 9 deletions(-)
drivers/staging/rtl8188eu/core/rtw_xmit.c +0 -4
index e0a5567..1e1b6d8 100644
@@ -57,8 +57,6 @@ s32	_rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
 	/*  We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */
 
 	spin_lock_init(&pxmitpriv->lock);
-	sema_init(&pxmitpriv->xmit_sema, 0);
-	sema_init(&pxmitpriv->terminate_xmitthread_sema, 0);
 
 	/*
 	Please insert all the queue initializaiton using _rtw_init_queue below
@@ -199,8 +197,6 @@ s32	_rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
 
 	pxmitpriv->txirp_cnt = 1;
 
-	sema_init(&(pxmitpriv->tx_retevt), 0);
-
 	/* per AC pending irp */
 	pxmitpriv->beq_cnt = 0;
 	pxmitpriv->bkq_cnt = 0;
drivers/staging/rtl8188eu/include/osdep_service.h +0 -1
index c53c9ea..6f6a8f8 100644
@@ -35,7 +35,6 @@
 #include <asm/byteorder.h>
 #include <linux/atomic.h>
 #include <linux/io.h>
-#include <linux/semaphore.h>
 #include <linux/mutex.h>
 #include <linux/sem.h>
 #include <linux/sched.h>
drivers/staging/rtl8188eu/include/rtw_event.h +0 -1
index 0dc63f2..2a45581 100644
@@ -18,7 +18,6 @@
 #include <osdep_service.h>
 
 #include <wlan_bssdef.h>
-#include <linux/semaphore.h>
 #include <linux/mutex.h>
 #include <linux/sem.h>
 
drivers/staging/rtl8188eu/include/rtw_xmit.h +0 -3
index a0853ba..7895008 100644
@@ -263,8 +263,6 @@ struct agg_pkt_info {
 
 struct	xmit_priv {
 	spinlock_t lock;
-	struct semaphore xmit_sema;
-	struct semaphore terminate_xmitthread_sema;
 	struct __queue be_pending;
 	struct __queue bk_pending;
 	struct __queue vi_pending;
@@ -289,7 +287,6 @@ struct	xmit_priv {
 	u8	wmm_para_seq[4];/* sequence for wmm ac parameter strength
 				 * from large to small. it's value is 0->vo,
 				 * 1->vi, 2->be, 3->bk. */
-	struct semaphore tx_retevt;/* all tx return event; */
 	u8		txirp_cnt;/*  */
 	struct tasklet_struct xmit_tasklet;
 	/* per AC pending irp */
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#14 lore raw

PATCH v3 2/4 staging: r8188eu: Replace semaphore terminate_cmdthread_sema with completion

In reply to Binoy Jayan

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

---
 drivers/staging/rtl8188eu/core/rtw_cmd.c    | 6 +++---
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/os_intfs.c | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8188eu/core/rtw_cmd.c +3 -3
index a2937e7..9e12588 100644
@@ -28,7 +28,7 @@ No irqsave is necessary.
 int rtw_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);
 
 	_rtw_init_queue(&(pcmdpriv->cmd_queue));
 	return _SUCCESS;
@@ -162,7 +162,7 @@ int rtw_cmd_thread(void *context)
 	allow_signal(SIGTERM);
 
 	pcmdpriv->cmdthd_running = true;
-	up(&pcmdpriv->terminate_cmdthread_sema);
+	complete(&pcmdpriv->terminate_cmdthread_comp);
 
 	RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("start r871x rtw_cmd_thread !!!!\n"));
 
@@ -234,7 +234,7 @@ _next:
 		rtw_free_cmd_obj(pcmd);
 	}
 
-	up(&pcmdpriv->terminate_cmdthread_sema);
+	complete(&pcmdpriv->terminate_cmdthread_comp);
 
 
 	complete_and_exit(NULL, 0);
drivers/staging/rtl8188eu/include/rtw_cmd.h +1 -1
index 3532dd1..2b53f58 100644
@@ -40,7 +40,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 cmdthd_running;
 	struct adapter *padapter;
drivers/staging/rtl8188eu/os_dep/os_intfs.c +2 -2
index a696d2b..c494845 100644
@@ -762,7 +762,7 @@ static int rtw_start_drv_threads(struct adapter *padapter)
 		err = PTR_ERR(padapter->cmdThread);
 	else
 		/* wait for cmd_thread to run */
-		_rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+		wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 
 	return err;
 }
@@ -774,7 +774,7 @@ void rtw_stop_drv_threads(struct adapter *padapter)
 	/* Below is to terminate rtw_cmd_thread & event_thread... */
 	complete(&padapter->cmdpriv.cmd_queue_comp);
 	if (padapter->cmdThread)
-		_rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+		wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 
 }
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project