From patchwork Mon Jun 27 14:30:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 921062 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.4) with ESMTP id p5REVWnP011365 for ; Mon, 27 Jun 2011 14:31:48 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751909Ab1F0Obq (ORCPT ); Mon, 27 Jun 2011 10:31:46 -0400 Received: from mail-fx0-f52.google.com ([209.85.161.52]:63675 "EHLO mail-fx0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751539Ab1F0Obq (ORCPT ); Mon, 27 Jun 2011 10:31:46 -0400 Received: by fxd18 with SMTP id 18so1869571fxd.11 for ; Mon, 27 Jun 2011 07:31:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=l0uNA81fxhhWpFdEdxo7hoDTxfvThUvmXMZbWPPFCcM=; b=o+Rl6gfs+Ms82tjaq6wfG6S55T5lp+Fu8w2Q6l1DSHHOmOB4Dk0OPLcpuRj2Kq79X9 lfgImohorf/rQj+EJknVGK3EiQRw/dlVco9hkCCS3LxodN3Ko4qG2OGK58PA+LZN0LZ2 F/Wqqny7hFgJ8BsDGM+moS5Og9t0wbMinzV9M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=SKIOfxkM1tdf1BCh1XQN/hxcjOqiQxSpIEHulwtSnvKkydtxN4foyHgKocAQya4Pdn p35kBc3H+5GK6Ey1n95/4+PebJ6RqC8Ah84TnjvLjcAjPR4G7ErTZm0w7eGxI1zgRhtM 9YcK9f/EXJ1D3JW4e8EZQSw48rab4BO5HtKUE= Received: by 10.223.43.1 with SMTP id u1mr2427589fae.38.1309185057183; Mon, 27 Jun 2011 07:30:57 -0700 (PDT) Received: from localhost.localdomain (stgt-5f73b179.pool.mediaWays.net [95.115.177.121]) by mx.google.com with ESMTPS id f3sm3570523faa.6.2011.06.27.07.30.55 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 27 Jun 2011 07:30:56 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: padovan@profusion.mobi, jkosina@suse.cz, oliver@neukum.org, David Herrmann Subject: [PATCH 05/12] HID: wiimote: Synchronize wiimote input and hid event handling Date: Mon, 27 Jun 2011 16:30:06 +0200 Message-Id: <1309185013-484-5-git-send-email-dh.herrmann@googlemail.com> X-Mailer: git-send-email 1.7.5.2 In-Reply-To: <1309185013-484-1-git-send-email-dh.herrmann@googlemail.com> References: <1309185013-484-1-git-send-email-dh.herrmann@googlemail.com> 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]); Mon, 27 Jun 2011 14:31:48 +0000 (UTC) The wiimote first starts HID hardware and then registers the input device. We need to synchronize the startup so no event handler will start parsing events when the wiimote device is not ready, yet. Signed-off-by: David Herrmann --- drivers/hid/hid-wiimote.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c index deaf232..3416f69 100644 --- a/drivers/hid/hid-wiimote.c +++ b/drivers/hid/hid-wiimote.c @@ -10,6 +10,7 @@ * any later version. */ +#include #include #include #include @@ -20,6 +21,7 @@ #define WIIMOTE_NAME "Nintendo Wii Remote" struct wiimote_data { + atomic_t ready; struct hid_device *hdev; struct input_dev *input; }; @@ -27,12 +29,26 @@ struct wiimote_data { static int wiimote_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) { + struct wiimote_data *wdata = input_get_drvdata(dev); + + if (!atomic_read(&wdata->ready)) + return -EBUSY; + /* smp_rmb: Make sure wdata->xy is available when wdata->ready is 1 */ + smp_rmb(); + return 0; } static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, u8 *raw_data, int size) { + struct wiimote_data *wdata = hid_get_drvdata(hdev); + + if (!atomic_read(&wdata->ready)) + return -EBUSY; + /* smp_rmb: Make sure wdata->xy is available when wdata->ready is 1 */ + smp_rmb(); + if (size < 1) return -EINVAL; @@ -103,6 +119,9 @@ static int wiimote_hid_probe(struct hid_device *hdev, goto err_stop; } + /* smp_wmb: Write wdata->xy first before wdata->ready is set to 1 */ + smp_wmb(); + atomic_set(&wdata->ready, 1); hid_info(hdev, "New device registered\n"); return 0;