From patchwork Tue Jun 14 23:45:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 880502 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 p5ENjw6J019029 for ; Tue, 14 Jun 2011 23:46:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752837Ab1FNXqS (ORCPT ); Tue, 14 Jun 2011 19:46:18 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:36667 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752089Ab1FNXqR (ORCPT ); Tue, 14 Jun 2011 19:46:17 -0400 Received: by mail-fx0-f46.google.com with SMTP id 17so41764fxm.19 for ; Tue, 14 Jun 2011 16:46:17 -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=IwF5mhvzIK0lYQdQZ4peGOzr0f/idT29IeVf8RieU18=; b=bq1bljXQHpG7QzkC5BjE8aZedNxeIIlnfPKSExsvQ5p8e+mKz+U1A+8mYGe/MydmXc GBNSEIgs06Re1kjsCDWAHZr7Ag7gi9Rx0ZanJidFd2h35QmCkYqimiMdR7K9zilZ1A7c J+JTyIkbwLfOY05uu7pZnSWEYzhNejzUlv/Mw= 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=WZ1fMmWwX16KrI9uZ9xnAXfXo08vtw40rYUW0br3T9V/o9x3OjQmF8o2tDRm2Ep90I EOZFKOPYKw4ymrpg5r0fEbBfSYSR5HK0ZOX0928AusrLtESAezVRb3QhEeLSH25TVRWX KzUMPjgnX+2BWAJU+fM0F/VvHSIb0rqExu4a8= Received: by 10.223.159.14 with SMTP id h14mr964873fax.20.1308095177306; Tue, 14 Jun 2011 16:46:17 -0700 (PDT) Received: from localhost.localdomain (stgt-4d0383f8.pool.mediaWays.net [77.3.131.248]) by mx.google.com with ESMTPS id g7sm2963789fac.39.2011.06.14.16.46.15 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 14 Jun 2011 16:46:16 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: jkosina@suse.cz, padovan@profusion.mobi, dh.herrmann@googlemail.com Subject: [RFC 03/12] HID: wiimote: Add wiimote device structure Date: Wed, 15 Jun 2011 01:45:48 +0200 Message-Id: <1308095157-4699-4-git-send-email-dh.herrmann@googlemail.com> X-Mailer: git-send-email 1.7.5.2 In-Reply-To: <1308095157-4699-1-git-send-email-dh.herrmann@googlemail.com> References: <1308095157-4699-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]); Tue, 14 Jun 2011 23:46:35 +0000 (UTC) Allocate wiimote device structure with all wiimote related data when registering new wiimote devices. Signed-off-by: David Herrmann --- drivers/hid/hid-wiimote.c | 36 ++++++++++++++++++++++++++++++++++-- 1 files changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c index ed4fe18..27a4261 100644 --- a/drivers/hid/hid-wiimote.c +++ b/drivers/hid/hid-wiimote.c @@ -17,6 +17,10 @@ #define WIIMOTE_VERSION "0.1" #define WIIMOTE_NAME "Nintendo Wii Remote" +struct wiimote_data { + struct hid_device *hdev; +}; + static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, u8 *raw_data, int size) { @@ -26,31 +30,59 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, return 0; } +static struct wiimote_data *wiimote_create(struct hid_device *hdev) +{ + struct wiimote_data *wdata; + + wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); + if (!wdata) + return NULL; + + wdata->hdev = hdev; + hid_set_drvdata(hdev, wdata); + + return wdata; +} + static int wiimote_hid_probe(struct hid_device *hdev, const struct hid_device_id *id) { + struct wiimote_data *wdata; int ret; + wdata = wiimote_create(hdev); + if (!wdata) { + hid_err(hdev, "Can't alloc device\n"); + return -ENOMEM; + } + ret = hid_parse(hdev); if (ret) { hid_err(hdev, "HID parse failed\n"); - return ret; + goto err; } ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); if (ret) { hid_err(hdev, "HW start failed\n"); - return ret; + goto err; } hid_info(hdev, "New device registered\n"); return 0; + +err: + kfree(wdata); + return ret; } static void wiimote_hid_remove(struct hid_device *hdev) { + struct wiimote_data *wdata = hid_get_drvdata(hdev); + hid_info(hdev, "Device removed\n"); hid_hw_stop(hdev); + kfree(wdata); } static const struct hid_device_id wiimote_hid_devices[] = {