Skip to content

Commit

Permalink
HID: bt: Move hid_add_device() call to after hidp_session() has started.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Gustavo F. Padovan <[email protected]>
Signed-off-by: Jiri Kosina <[email protected]>
  • Loading branch information
signal11 authored and Jiri Kosina committed Feb 11, 2011
1 parent 581548d commit 0f69dca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
28 changes: 20 additions & 8 deletions net/bluetooth/hidp/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ static int hidp_session(void *arg)
init_waitqueue_entry(&intr_wait, current);
add_wait_queue(sk_sleep(ctrl_sk), &ctrl_wait);
add_wait_queue(sk_sleep(intr_sk), &intr_wait);
session->waiting_for_startup = 0;
wake_up_interruptible(&session->startup_queue);
while (!atomic_read(&session->terminate)) {
set_current_state(TASK_INTERRUPTIBLE);

Expand Down Expand Up @@ -754,6 +756,8 @@ static struct hid_ll_driver hidp_hid_driver = {
.hidinput_input_event = hidp_hidinput_event,
};

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

hid->hid_output_raw_report = hidp_output_raw_report;

err = hid_add_device(hid);
if (err < 0)
goto failed;

return 0;

failed:
hid_destroy_device(hid);
session->hid = NULL;

fault:
kfree(session->rd_data);
session->rd_data = NULL;
Expand Down Expand Up @@ -853,6 +849,8 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock,
skb_queue_head_init(&session->ctrl_transmit);
skb_queue_head_init(&session->intr_transmit);

init_waitqueue_head(&session->startup_queue);
session->waiting_for_startup = 1;
session->flags = req->flags & (1 << HIDP_BLUETOOTH_VENDOR_ID);
session->idle_to = req->idle_to;

Expand All @@ -875,6 +873,14 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock,
err = kernel_thread(hidp_session, session, CLONE_KERNEL);
if (err < 0)
goto unlink;
while (session->waiting_for_startup) {
wait_event_interruptible(session->startup_queue,
!session->waiting_for_startup);
}

err = hid_add_device(session->hid);
if (err < 0)
goto err_add_device;

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

err_add_device:
hid_destroy_device(session->hid);
session->hid = NULL;
atomic_inc(&session->terminate);
hidp_schedule(session);

unlink:
hidp_del_timer(session);

Expand Down
3 changes: 3 additions & 0 deletions net/bluetooth/hidp/hidp.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ struct hidp_session {
/* Report descriptor */
__u8 *rd_data;
uint rd_size;

wait_queue_head_t startup_queue;
int waiting_for_startup;
};

static inline void hidp_schedule(struct hidp_session *session)
Expand Down

0 comments on commit 0f69dca

Please sign in to comment.