From patchwork Tue Jul 5 11:45:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 944562 X-Patchwork-Delegate: jikos@jikos.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p65BjfU0002557 for ; Tue, 5 Jul 2011 11:45:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755657Ab1GELph (ORCPT ); Tue, 5 Jul 2011 07:45:37 -0400 Received: from mail-fx0-f52.google.com ([209.85.161.52]:59515 "EHLO mail-fx0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756084Ab1GELpf (ORCPT ); Tue, 5 Jul 2011 07:45:35 -0400 Received: by mail-fx0-f52.google.com with SMTP id 18so6110854fxd.11 for ; Tue, 05 Jul 2011 04:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=GrWNadrmmp4YGE9t3xWLMnOUzaRysdPaTL8arZyc63c=; b=QNyAK8LH2FoSxUPz/Myf4euH2abV4vjBxAWBmWhQ+QK04LlWN0q4/MauvVGh9678Cl TXQkq55T5NEVRAnkJ7V8nV15Qqy9tQAn+rgchFv/Z2pFfM6awUccuCi8UG1CPffjKr0F 0J9jDsj3zViFGChuSLFI78/LhGZV4x6sEdelI= Received: by 10.223.21.141 with SMTP id j13mr5259123fab.79.1309866334632; Tue, 05 Jul 2011 04:45:34 -0700 (PDT) Received: from localhost.localdomain (u-084-c056.eap.uni-tuebingen.de [134.2.84.56]) by mx.google.com with ESMTPS id r10sm5238461fah.2.2011.07.05.04.45.33 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jul 2011 04:45:33 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: jkosina@suse.cz, padovan@profusion.mobi, David Herrmann Subject: [PATCH 03/12] HID: wiimote: Add wiimote device structure Date: Tue, 5 Jul 2011 13:45:10 +0200 Message-Id: <1309866319-12899-3-git-send-email-dh.herrmann@googlemail.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1309866319-12899-1-git-send-email-dh.herrmann@googlemail.com> References: <1309866319-12899-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 (demeter2.kernel.org [140.211.167.43]); Tue, 05 Jul 2011 11:45:42 +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 | 41 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c index ed4fe18..ff7cf12 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,64 @@ 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 void wiimote_destroy(struct wiimote_data *wdata) +{ + kfree(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: + wiimote_destroy(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); + wiimote_destroy(wdata); } static const struct hid_device_id wiimote_hid_devices[] = {