From patchwork Fri Jun 17 14:49:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 891842 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 p5HEsZCl010597 for ; Fri, 17 Jun 2011 14:54:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932561Ab1FQOye (ORCPT ); Fri, 17 Jun 2011 10:54:34 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:45267 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759232Ab1FQOuU (ORCPT ); Fri, 17 Jun 2011 10:50:20 -0400 Received: by fxm17 with SMTP id 17so1796143fxm.19 for ; Fri, 17 Jun 2011 07:50:19 -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=1P3vpynPR/GMv4n6+KMs+rXWl1lyIjaNdwupuem2oRo=; b=Lz3l1RM2QP1aLtHivy0BttRR6H/ZnsS6HiHqTpvdKxiwkrsSW10NHz+iia7KlQ+Iu4 9hI/5wg2iZ8WtJWzJNZbxtYv/PfapIlvAXw9DtGbUERGiR665vIlhqx4AKv0F4E/igs2 vP8cMrKTvx/3kth7295OrYFF8DvO4i0R1DRUA= 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=SqM4a6zY/vjEVuGefCUwvQP8VSTXjO1GWmatrs/QaZk5WW9anXA6J0s0RyR4Nk1I96 OTux0XLc/8QISxPm23FqJ3w9CMkXWU0TrO5dEHYC/jhwJ1cpBh+c/GxUJtbBNQgeQR0L w+e8G2/IEd1xPvsUMfRv952Z96KbW8f4Hmfn4= Received: by 10.223.100.15 with SMTP id w15mr2651340fan.11.1308322219529; Fri, 17 Jun 2011 07:50:19 -0700 (PDT) Received: from localhost.localdomain (stgt-4d039afc.pool.mediaWays.net [77.3.154.252]) by mx.google.com with ESMTPS id o10sm1378710fah.31.2011.06.17.07.50.18 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 17 Jun 2011 07:50:18 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: padovan@profusion.mobi, jkosina@suse.cz, oliver@neukum.org, dh.herrmann@googlemail.com Subject: [PATCH 05/12 v2] HID: wiimote: Synchronize wiimote input and hid event handling Date: Fri, 17 Jun 2011 16:49:15 +0200 Message-Id: <1308322162-13953-5-git-send-email-dh.herrmann@googlemail.com> X-Mailer: git-send-email 1.7.5.2 In-Reply-To: <1308322162-13953-1-git-send-email-dh.herrmann@googlemail.com> References: <1308322162-13953-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]); Fri, 17 Jun 2011 14:54:37 +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 --- V2: Add memory barriers to guarantee data consistency. drivers/hid/hid-wiimote.c | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c index deaf232..afae0e9 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,24 @@ 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(); + 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(); + if (size < 1) return -EINVAL; @@ -103,6 +117,8 @@ static int wiimote_hid_probe(struct hid_device *hdev, goto err_stop; } + smp_wmb(); + atomic_set(&wdata->ready, 1); hid_info(hdev, "New device registered\n"); return 0;