From patchwork Tue Jan 18 08:04:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Ott X-Patchwork-Id: 485641 X-Patchwork-Delegate: jikos@jikos.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p0I868cK006957 for ; Tue, 18 Jan 2011 08:06:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753011Ab1ARIFL (ORCPT ); Tue, 18 Jan 2011 03:05:11 -0500 Received: from core.signal11.us ([64.251.29.136]:47838 "EHLO core.signal11.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752795Ab1ARIFJ (ORCPT ); Tue, 18 Jan 2011 03:05:09 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by core.signal11.us (Postfix) with SMTP id 3A1AB1CCABAC for ; Tue, 18 Jan 2011 03:05:09 -0500 (EST) Received: from localhost.localdomain (c-68-59-135-75.hsd1.fl.comcast.net [68.59.135.75]) by core.signal11.us (Postfix) with ESMTP id 8ACA51CCAB9E; Tue, 18 Jan 2011 03:05:06 -0500 (EST) From: Alan Ott To: Jiri Kosina , Marcel Holtmann , "Gustavo F. Padovan" , "David S. Miller" , Alan Ott , Michael Poole , Eric Dumazet , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org Cc: Alan Ott Subject: [PATCH v5 1/4] bt hidp: Move hid_add_device() call to after hidp_session() has started. Date: Tue, 18 Jan 2011 03:04:37 -0500 Message-Id: <1295337880-12452-2-git-send-email-alan@signal11.us> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1295337880-12452-1-git-send-email-alan@signal11.us> References: <1295337880-12452-1-git-send-email-alan@signal11.us> X-DSPAM-Result: Whitelisted X-DSPAM-Processed: Tue Jan 18 03:05:09 2011 X-DSPAM-Confidence: 0.9899 X-DSPAM-Probability: 0.0000 X-DSPAM-Signature: 4d3549b5166708983437428 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 18 Jan 2011 08:06:09 +0000 (UTC) diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c index 29544c2..67cc4bc 100644 --- a/net/bluetooth/hidp/core.c +++ b/net/bluetooth/hidp/core.c @@ -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); @@ -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) { @@ -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; @@ -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; @@ -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, @@ -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); diff --git a/net/bluetooth/hidp/hidp.h b/net/bluetooth/hidp/hidp.h index 8d934a1..2cc35dc 100644 --- a/net/bluetooth/hidp/hidp.h +++ b/net/bluetooth/hidp/hidp.h @@ -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)