From patchwork Fri Jun 17 14:49:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 891872 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 p5HEsftW020490 for ; Fri, 17 Jun 2011 14:54:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932553Ab1FQOyf (ORCPT ); Fri, 17 Jun 2011 10:54:35 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:63632 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759226Ab1FQOuS (ORCPT ); Fri, 17 Jun 2011 10:50:18 -0400 Received: by fxm17 with SMTP id 17so1796109fxm.19 for ; Fri, 17 Jun 2011 07:50:16 -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=+J/XUGR3Sz2bmW+3PlIpT+tsi5JNj974V0QhrX2RUyQ=; b=Yx9sSKn9GNBeIHpLN3jCrfVyRJOs5lHebz+nRu4UxIrjLn4TgQ0P5oL6pTqC/VmMj+ E7aHksTHHWx8OkGKr+qU8VkNucK1l0ZrkVmsiNmk/B6F+ckI9gpUHmMo5Q8+vGQRqaJ8 0Db2BtjGKCyHL6IbeEDEC8EWvwFNicE6pNXOk= 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=eM6XL6AZw6TH/LfI/jA1LzqeCozlvHEUT1pdQW7g+CDuDjWM6YO5LUuh4USjtj3MNn wE3JWFbQa2/ux1hnGaaiDCi4AHNhMZwv8/MJZVdI2bjTmbjGi2O4dqVsZDznQjDgm2p/ P6m/jgeOeK3curq6sC4HLT0rTZfeDmhSlgbrg= Received: by 10.223.149.70 with SMTP id s6mr2609169fav.66.1308322216797; Fri, 17 Jun 2011 07:50:16 -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.15 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 17 Jun 2011 07:50:16 -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 03/12 v2] HID: wiimote: Add wiimote device structure Date: Fri, 17 Jun 2011 16:49:13 +0200 Message-Id: <1308322162-13953-3-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 (demeter2.kernel.org [140.211.167.43]); Fri, 17 Jun 2011 14:54:41 +0000 (UTC) Allocate wiimote device structure with all wiimote related data when registering new wiimote devices. Signed-off-by: David Herrmann --- V2: Add wiimote_destroy() for symmetries sake. 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[] = {