Skip to content

Commit aabf6f8

Browse files
Szymon JancGustavo F. Padovan
authored andcommitted
Bluetooth: Use kthread API in hidp
kernel_thread() is a low-level implementation detail and EXPORT_SYMBOL(kernel_thread) is scheduled for removal. Use the <linux/kthread.h> API instead. Signed-off-by: Szymon Janc <szymon.janc@tieto.com> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
1 parent a88a965 commit aabf6f8

2 files changed

Lines changed: 25 additions & 30 deletions

File tree

‎net/bluetooth/hidp/core.c‎

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
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

470470
static 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,
968954
int 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,
10561058
err_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

10621063
unlink:
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;

‎net/bluetooth/hidp/hidp.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ struct hidp_session {
142142
uint ctrl_mtu;
143143
uint intr_mtu;
144144

145-
atomic_t terminate;
145+
struct task_struct *task;
146146

147147
unsigned char keys[8];
148148
unsigned char leds;

0 commit comments

Comments
 (0)