Skip to content

Commit 0f69dca

Browse files
signal11Jiri Kosina
authored andcommitted
HID: bt: Move hid_add_device() call to after hidp_session() has started.
Move the call to hid_add_device() (which calls a device's probe() function) to after the kernel_thread() call which starts the hidp_session() thread. This ensures the Bluetooth receive socket is fully running by the time a device's probe() function is called. This way, a device can communicate (send and receive) with the Bluetooth device from its probe() function. Signed-off-by: Alan Ott <alan@signal11.us> Acked-by: Gustavo F. Padovan <padovan@profusion.mobi> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 581548d commit 0f69dca

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

net/bluetooth/hidp/core.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@ static int hidp_session(void *arg)
563563
init_waitqueue_entry(&intr_wait, current);
564564
add_wait_queue(sk_sleep(ctrl_sk), &ctrl_wait);
565565
add_wait_queue(sk_sleep(intr_sk), &intr_wait);
566+
session->waiting_for_startup = 0;
567+
wake_up_interruptible(&session->startup_queue);
566568
while (!atomic_read(&session->terminate)) {
567569
set_current_state(TASK_INTERRUPTIBLE);
568570

@@ -754,6 +756,8 @@ static struct hid_ll_driver hidp_hid_driver = {
754756
.hidinput_input_event = hidp_hidinput_event,
755757
};
756758

759+
/* This function sets up the hid device. It does not add it
760+
to the HID system. That is done in hidp_add_connection(). */
757761
static int hidp_setup_hid(struct hidp_session *session,
758762
struct hidp_connadd_req *req)
759763
{
@@ -795,16 +799,8 @@ static int hidp_setup_hid(struct hidp_session *session,
795799

796800
hid->hid_output_raw_report = hidp_output_raw_report;
797801

798-
err = hid_add_device(hid);
799-
if (err < 0)
800-
goto failed;
801-
802802
return 0;
803803

804-
failed:
805-
hid_destroy_device(hid);
806-
session->hid = NULL;
807-
808804
fault:
809805
kfree(session->rd_data);
810806
session->rd_data = NULL;
@@ -853,6 +849,8 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock,
853849
skb_queue_head_init(&session->ctrl_transmit);
854850
skb_queue_head_init(&session->intr_transmit);
855851

852+
init_waitqueue_head(&session->startup_queue);
853+
session->waiting_for_startup = 1;
856854
session->flags = req->flags & (1 << HIDP_BLUETOOTH_VENDOR_ID);
857855
session->idle_to = req->idle_to;
858856

@@ -875,6 +873,14 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock,
875873
err = kernel_thread(hidp_session, session, CLONE_KERNEL);
876874
if (err < 0)
877875
goto unlink;
876+
while (session->waiting_for_startup) {
877+
wait_event_interruptible(session->startup_queue,
878+
!session->waiting_for_startup);
879+
}
880+
881+
err = hid_add_device(session->hid);
882+
if (err < 0)
883+
goto err_add_device;
878884

879885
if (session->input) {
880886
hidp_send_ctrl_message(session,
@@ -888,6 +894,12 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock,
888894
up_write(&hidp_session_sem);
889895
return 0;
890896

897+
err_add_device:
898+
hid_destroy_device(session->hid);
899+
session->hid = NULL;
900+
atomic_inc(&session->terminate);
901+
hidp_schedule(session);
902+
891903
unlink:
892904
hidp_del_timer(session);
893905

net/bluetooth/hidp/hidp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ struct hidp_session {
157157
/* Report descriptor */
158158
__u8 *rd_data;
159159
uint rd_size;
160+
161+
wait_queue_head_t startup_queue;
162+
int waiting_for_startup;
160163
};
161164

162165
static inline void hidp_schedule(struct hidp_session *session)

0 commit comments

Comments
 (0)