From patchwork Mon Jun 27 14:30:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 920992 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 p5REV8XS016430 for ; Mon, 27 Jun 2011 14:31:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752792Ab1F0Oa5 (ORCPT ); Mon, 27 Jun 2011 10:30:57 -0400 Received: from mail-fx0-f52.google.com ([209.85.161.52]:46203 "EHLO mail-fx0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752608Ab1F0Oax (ORCPT ); Mon, 27 Jun 2011 10:30:53 -0400 Received: by fxd18 with SMTP id 18so1868791fxd.11 for ; Mon, 27 Jun 2011 07:30:52 -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=3z7aOIBahI3MUh7HaxvERSBHUTp3sGok/Vnap+D9eVE=; b=tHLATqAAx9TjiSjDi8LE6N4xfYqm5disA/iNnNs4Xrp6UEqtyA2dPs3zDAy/h+9rRO VY0fKLgxYTHj+bwilJxZtT3wmqBgo89Ib8SjDEK8G1+jzEzKpZxmFG16rGaEdyYGA5fg Gi9KBhiBJ93qwBdaa5t3vv6DSkyahGBakjZ8I= 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=tFHYiMPypsybyGyZtRB9ZfyxAwUmASefxpy3lQxIRQX6zJ0B9MNkHM3w7FV/RaiYrp Nrhgbf1QAc0/zw1Ezmmm6fr7vquJyH1+N/OYXgcWUZn3UK0tf+kkhM2eFeKzQmEQNwYy QqxTOWsnlKfTY9fSUy937OXJ13M4JejWkv+D4= Received: by 10.223.97.196 with SMTP id m4mr8985150fan.55.1309185052526; Mon, 27 Jun 2011 07:30:52 -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.51 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 27 Jun 2011 07:30:51 -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 03/12] HID: wiimote: Add wiimote device structure Date: Mon, 27 Jun 2011 16:30:04 +0200 Message-Id: <1309185013-484-3-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 (demeter2.kernel.org [140.211.167.43]); Mon, 27 Jun 2011 14:31:09 +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[] = {