3737#include <linux/init.h>
3838#include <linux/wait.h>
3939#include <linux/mutex.h>
40+ #include <linux/kthread.h>
4041#include <net/sock.h>
4142
4243#include <linux/input.h>
@@ -463,8 +464,7 @@ static void hidp_idle_timeout(unsigned long arg)
463464{
464465 struct hidp_session * session = (struct hidp_session * ) arg ;
465466
466- atomic_inc (& session -> terminate );
467- hidp_schedule (session );
467+ kthread_stop (session -> task );
468468}
469469
470470static void hidp_set_timer (struct hidp_session * session )
@@ -535,9 +535,7 @@ static void hidp_process_hid_control(struct hidp_session *session,
535535 skb_queue_purge (& session -> ctrl_transmit );
536536 skb_queue_purge (& session -> intr_transmit );
537537
538- /* Kill session thread */
539- atomic_inc (& session -> terminate );
540- hidp_schedule (session );
538+ kthread_stop (session -> task );
541539 }
542540}
543541
@@ -696,22 +694,10 @@ static int hidp_session(void *arg)
696694 struct sock * ctrl_sk = session -> ctrl_sock -> sk ;
697695 struct sock * intr_sk = session -> intr_sock -> sk ;
698696 struct sk_buff * skb ;
699- int vendor = 0x0000 , product = 0x0000 ;
700697 wait_queue_t ctrl_wait , intr_wait ;
701698
702699 BT_DBG ("session %p" , session );
703700
704- if (session -> input ) {
705- vendor = session -> input -> id .vendor ;
706- product = session -> input -> id .product ;
707- }
708-
709- if (session -> hid ) {
710- vendor = session -> hid -> vendor ;
711- product = session -> hid -> product ;
712- }
713-
714- daemonize ("khidpd_%04x%04x" , vendor , product );
715701 set_user_nice (current , -15 );
716702
717703 init_waitqueue_entry (& ctrl_wait , current );
@@ -720,7 +706,7 @@ static int hidp_session(void *arg)
720706 add_wait_queue (sk_sleep (intr_sk ), & intr_wait );
721707 session -> waiting_for_startup = 0 ;
722708 wake_up_interruptible (& session -> startup_queue );
723- while (!atomic_read ( & session -> terminate )) {
709+ while (!kthread_should_stop ( )) {
724710 set_current_state (TASK_INTERRUPTIBLE );
725711
726712 if (ctrl_sk -> sk_state != BT_CONNECTED ||
@@ -968,6 +954,7 @@ static int hidp_setup_hid(struct hidp_session *session,
968954int hidp_add_connection (struct hidp_connadd_req * req , struct socket * ctrl_sock , struct socket * intr_sock )
969955{
970956 struct hidp_session * session , * s ;
957+ int vendor , product ;
971958 int err ;
972959
973960 BT_DBG ("" );
@@ -1029,9 +1016,24 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock,
10291016
10301017 hidp_set_timer (session );
10311018
1032- err = kernel_thread (hidp_session , session , CLONE_KERNEL );
1033- if (err < 0 )
1019+ if (session -> hid ) {
1020+ vendor = session -> hid -> vendor ;
1021+ product = session -> hid -> product ;
1022+ } else if (session -> input ) {
1023+ vendor = session -> input -> id .vendor ;
1024+ product = session -> input -> id .product ;
1025+ } else {
1026+ vendor = 0x0000 ;
1027+ product = 0x0000 ;
1028+ }
1029+
1030+ session -> task = kthread_run (hidp_session , session , "khidpd_%04x%04x" ,
1031+ vendor , product );
1032+ if (IS_ERR (session -> task )) {
1033+ err = PTR_ERR (session -> task );
10341034 goto unlink ;
1035+ }
1036+
10351037 while (session -> waiting_for_startup ) {
10361038 wait_event_interruptible (session -> startup_queue ,
10371039 !session -> waiting_for_startup );
@@ -1056,8 +1058,7 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock,
10561058err_add_device :
10571059 hid_destroy_device (session -> hid );
10581060 session -> hid = NULL ;
1059- atomic_inc (& session -> terminate );
1060- hidp_schedule (session );
1061+ kthread_stop (session -> task );
10611062
10621063unlink :
10631064 hidp_del_timer (session );
@@ -1108,13 +1109,7 @@ int hidp_del_connection(struct hidp_conndel_req *req)
11081109 skb_queue_purge (& session -> ctrl_transmit );
11091110 skb_queue_purge (& session -> intr_transmit );
11101111
1111- /* Wakeup user-space polling for socket errors */
1112- session -> intr_sock -> sk -> sk_err = EUNATCH ;
1113- session -> ctrl_sock -> sk -> sk_err = EUNATCH ;
1114-
1115- /* Kill session thread */
1116- atomic_inc (& session -> terminate );
1117- hidp_schedule (session );
1112+ kthread_stop (session -> task );
11181113 }
11191114 } else
11201115 err = - ENOENT ;
0 commit comments