[PATCH V2] staging/gdm72xx: use kthread APIs

From: Devendra Naga
Date: Tue Jul 17 2012 - 01:31:45 EST

From: Devendra Naga <devendra.aaru@xxxxxxxxx>

This patch modifies the kthread usage in the gdm_usb code, and tries to
use the kthread APIs better.

Actually the task_struct is taken as global as the limitation of priv.
we run the kthread before we allocate the priv.

did only compilation test, but not the insmod, check ps ax for kthread and
rmmod and see the thread is killed kind of tests.

There were no checks while kthread_run may fail, returing some error which can be seen by using PTR_ERR.

Signed-off-by: Devendra Naga <develkernel412222@xxxxxxxxx>

Sorry Greg sir, i didn't actually used the checkpatch tool, mea maxima clupa :(.

changes since V2:
removed the following checkpatch error

./scripts/checkpatch.pl 0001-staging-gdm72xx-use-kthread-APIs.patch
ERROR: trailing whitespace
#38: FILE: drivers/staging/gdm72xx/gdm_usb.c:57:
+static struct task_struct *kthread; $

NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or

but didn't solved the below warning, as it needed a new patch to remove all
printk's and convert them to pr_err, and this patch intended to do only one
specific change.

WARNING: Prefer pr_err(... to printk(KERN_ERR, ...
#58: FILE: drivers/staging/gdm72xx/gdm_usb.c:786:
+ printk(KERN_ERR "%s: can't create kernel thread\n", __func__);

drivers/staging/gdm72xx/gdm_usb.c | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/gdm72xx/gdm_usb.c b/drivers/staging/gdm72xx/gdm_usb.c
index d48d49c..5aab7eb 100644
--- a/drivers/staging/gdm72xx/gdm_usb.c
+++ b/drivers/staging/gdm72xx/gdm_usb.c
@@ -46,7 +46,6 @@ MODULE_DEVICE_TABLE(usb, id_table);
static LIST_HEAD(k_list);
static DEFINE_SPINLOCK(k_lock);
-static int k_mode_stop;

#define K_WAIT_TIME (2 * HZ / 100)

@@ -55,6 +54,7 @@ static int k_mode_stop;
static int init_usb(struct usbwm_dev *udev);
static void release_usb(struct usbwm_dev *udev);

+static struct task_struct *kthread;
/*#define DEBUG */
#ifdef DEBUG
static void hexdump(char *title, u8 *data, int len)
@@ -717,7 +717,7 @@ static int k_mode_thread(void *arg)


- while (!k_mode_stop) {
+ while (!kthread_should_stop()) {

spin_lock_irqsave(&k_lock, flags2);
while (!list_empty(&k_list)) {
@@ -778,7 +778,11 @@ static struct usb_driver gdm_usb_driver = {
static int __init usb_gdm_wimax_init(void)
- kthread_run(k_mode_thread, NULL, "WiMax_thread");
+ kthread = kthread_run(k_mode_thread, NULL, "WiMax_thread");
+ if (IS_ERR(kthread)) {
+ printk(KERN_ERR "%s: can't create kernel thread\n", __func__);
+ return PTR_ERR(kthread);
+ }
return usb_register(&gdm_usb_driver);
@@ -786,7 +790,8 @@ static int __init usb_gdm_wimax_init(void)
static void __exit usb_gdm_wimax_exit(void)
- k_mode_stop = 1;
+ if (kthread)
+ kthread_stop(kthread);

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/