[PATCH 5/6] staging: brcm80211: remove kernel_thread() for wl_iscan_thread and wl_event_thread.

Jason Cooper jason at lakedaemon.net
Fri Oct 8 21:44:28 UTC 2010


Replace kernel_thread() with kthread_run().  Replace pid with tsk,
and exited with kthread_stop()/kthread_should_stop().

event_tsk, and tsk are NULL when not in use, -ENOMEM on error, otherwise,
in use.

Signed-off-by: Jason Cooper <jason at lakedaemon.net>
---
 drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c |   42 +++++++++++----------
 drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h |    6 +--
 2 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
index 9006d31..24d7bb0 100644
--- a/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
+++ b/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
@@ -35,6 +35,7 @@
 #include <dhd.h>
 
 #include <linux/kernel.h>
+#include <linux/kthread.h>
 #include <linux/netdevice.h>
 #include <linux/sched.h>
 #include <linux/etherdevice.h>
@@ -2795,21 +2796,20 @@ static void wl_deinit_priv_mem(struct wl_priv *wl)
 static s32 wl_create_event_handler(struct wl_priv *wl)
 {
 	sema_init(&wl->event_sync, 0);
-	init_completion(&wl->event_exit);
-	wl->event_pid = kernel_thread(wl_event_handler, wl, 0);
-	if (unlikely(wl->event_pid < 0)) {
+	wl->event_tsk = kthread_run(wl_event_handler, wl, "wl_event_handler");
+	if (IS_ERR(wl->event_tsk)) {
+		wl->event_tsk = NULL;
 		WL_ERR(("failed to create event thread\n"));
 		return -ENOMEM;
 	}
-	WL_DBG(("pid %d\n", wl->event_pid));
 	return 0;
 }
 
 static void wl_destroy_event_handler(struct wl_priv *wl)
 {
-	if (wl->event_pid >= 0) {
-		KILL_PROC(wl->event_pid, SIGTERM);
-		wait_for_completion(&wl->event_exit);
+	if (wl->event_tsk && !IS_ERR(wl->event_tsk)) {
+		kthread_stop(wl->event_tsk);
+		wl->event_tsk = NULL;
 	}
 }
 
@@ -2817,11 +2817,10 @@ static void wl_term_iscan(struct wl_priv *wl)
 {
 	struct wl_iscan_ctrl *iscan = wl_to_iscan(wl);
 
-	if (wl->iscan_on && iscan->pid >= 0) {
+	if (wl->iscan_on && iscan->tsk && !IS_ERR(iscan->tsk)) {
 		iscan->state = WL_ISCAN_STATE_IDLE;
-		KILL_PROC(iscan->pid, SIGTERM);
-		wait_for_completion(&iscan->exited);
-		iscan->pid = -1;
+		kthread_stop(iscan->tsk);
+		iscan->tsk = NULL;
 	}
 }
 
@@ -2954,6 +2953,8 @@ static s32 wl_iscan_thread(void *data)
 	sched_setscheduler(current, SCHED_FIFO, &param);
 	status = WL_SCAN_RESULTS_PARTIAL;
 	while (likely(!down_interruptible(&iscan->sync))) {
+		if (kthread_should_stop())
+			break;
 		if (iscan->timer_on) {
 			del_timer_sync(&iscan->timer);
 			iscan->timer_on = 0;
@@ -2971,7 +2972,6 @@ static s32 wl_iscan_thread(void *data)
 		del_timer_sync(&iscan->timer);
 		iscan->timer_on = 0;
 	}
-	complete_and_exit(&iscan->exited, 0);
 
 	return 0;
 }
@@ -2992,13 +2992,13 @@ static s32 wl_invoke_iscan(struct wl_priv *wl)
 	struct wl_iscan_ctrl *iscan = wl_to_iscan(wl);
 	int err = 0;
 
-	if (wl->iscan_on && iscan->pid < 0) {
+	if (wl->iscan_on && !iscan->tsk) {
 		iscan->state = WL_ISCAN_STATE_IDLE;
 		sema_init(&iscan->sync, 0);
-		init_completion(&iscan->exited);
-		iscan->pid = kernel_thread(wl_iscan_thread, iscan, 0);
-		if (unlikely(iscan->pid < 0)) {
+		iscan->tsk = kthread_run(wl_iscan_thread, iscan, "wl_iscan");
+		if (IS_ERR(iscan->tsk)) {
 			WL_ERR(("Could not create iscan thread\n"));
+			iscan->tsk = NULL;
 			return -ENOMEM;
 		}
 	}
@@ -3030,10 +3030,10 @@ static s32 wl_init_iscan(struct wl_priv *wl)
 		iscan->timer.data = (unsigned long) iscan;
 		iscan->timer.function = wl_iscan_timer;
 		sema_init(&iscan->sync, 0);
-		init_completion(&iscan->exited);
-		iscan->pid = kernel_thread(wl_iscan_thread, iscan, 0);
-		if (unlikely(iscan->pid < 0)) {
+		iscan->tsk = kthread_run(wl_iscan_thread, iscan, "wl_iscan");
+		if (IS_ERR(iscan->tsk)) {
 			WL_ERR(("Could not create iscan thread\n"));
+			iscan->tsk = NULL;
 			return -ENOMEM;
 		}
 		iscan->data = wl;
@@ -3172,6 +3172,8 @@ static s32 wl_event_handler(void *data)
 
 	sched_setscheduler(current, SCHED_FIFO, &param);
 	while (likely(!down_interruptible(&wl->event_sync))) {
+		if(kthread_should_stop())
+			break;
 		e = wl_deq_event(wl);
 		if (unlikely(!e)) {
 			WL_ERR(("eqeue empty..\n"));
@@ -3186,7 +3188,7 @@ static s32 wl_event_handler(void *data)
 		}
 		wl_put_event(e);
 	}
-	complete_and_exit(&wl->event_exit, 0);
+	return 0;
 }
 
 void
diff --git a/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h
index ef8a5f1..d125d90 100644
--- a/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h
+++ b/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h
@@ -247,9 +247,8 @@ struct wl_iscan_ctrl {
 	u32 timer_ms;
 	u32 timer_on;
 	s32 state;
-	s32 pid;
+	struct task_struct *tsk;
 	struct semaphore sync;
-	struct completion exited;
 	struct wl_iscan_eloop el;
 	void *data;
 	s8 ioctl_buf[WLC_IOCTL_SMLEN];
@@ -307,7 +306,6 @@ struct wl_priv {
 	struct ether_addr bssid;	/* bssid of currently engaged network */
 	struct semaphore event_sync;	/* for synchronization of main event
 					 thread */
-	struct completion event_exit;
 	struct wl_profile *profile;	/* holding dongle profile */
 	struct wl_iscan_ctrl *iscan;	/* iscan controller */
 	struct wl_connect_info conn_info;	/* association information
@@ -315,7 +313,7 @@ struct wl_priv {
 	struct wl_fw_ctrl *fw;	/* control firwmare / nvram paramter
 				 downloading */
 	struct wl_pmk_list *pmk_list;	/* wpa2 pmk list */
-	s32 event_pid;	/* pid of main event handler thread */
+	struct task_struct *event_tsk;	/* task of main event handler thread */
 	unsigned long status;		/* current dongle status */
 	void *pub;
 	u32 channel;		/* current channel */
-- 
1.6.3.3




More information about the devel mailing list