From patchwork Fri Nov 23 15:31:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 1796211 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 085E73FC23 for ; Fri, 23 Nov 2012 15:34:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753476Ab2KWPdo (ORCPT ); Fri, 23 Nov 2012 10:33:44 -0500 Received: from mail-wi0-f170.google.com ([209.85.212.170]:35522 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752951Ab2KWPbp (ORCPT ); Fri, 23 Nov 2012 10:31:45 -0500 Received: by mail-wi0-f170.google.com with SMTP id hq7so1468427wib.1 for ; Fri, 23 Nov 2012 07:31:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; bh=ceySQwTwABaCqfASndo/plBjVFRdvhTFbiatu10zOIQ=; b=H7SG1TxPJRU0/q9neR1NlPbAHfBE4BsNhZIB6qv6/EFi2FwmilvDAqcInSqa0N1dsd K3zEmVEiAYipJIhNOEZ8YvVAHHG1BBGYLU26Wo68pOZuJTSBTpIjc3Co6F8pAnvpSN5U 6mYb+xusSYVnC5R5bUPWc2mgyJW0MhYtZrf1H8oPXYzIjXQz9uAyBvnYKNN/uPpeNkO1 2zHS3b7irEPsoDivKP0/rDittT2Zz18Cyfere1X+r/XhWd0nKZzW9NFbo+rOepnopgFh 6DEvjwEbShIoXL+vWC3GRqPYgU6DcjOjfNrKAcT5eK7B7lOYXx1MPvq1U1PGL3q8Nnv9 KFZg== Received: by 10.180.99.36 with SMTP id en4mr6811758wib.20.1353684704179; Fri, 23 Nov 2012 07:31:44 -0800 (PST) Received: from localhost.localdomain.com (lan31-8-82-247-176-67.fbx.proxad.net. [82.247.176.67]) by mx.google.com with ESMTPS id y3sm8996809wix.6.2012.11.23.07.31.42 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 23 Nov 2012 07:31:43 -0800 (PST) From: Benjamin Tissoires To: Benjamin Tissoires , Dmitry Torokhov , Henrik Rydberg , Jiri Kosina , Stephane Chatty , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/11] HID: hid-input factorize hid_input allocation Date: Fri, 23 Nov 2012 16:31:24 +0100 Message-Id: <1353684694-5723-2-git-send-email-benjamin.tissoires@gmail.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1353684694-5723-1-git-send-email-benjamin.tissoires@gmail.com> References: <1353684694-5723-1-git-send-email-benjamin.tissoires@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This just refactors the allocation of hid_input. No semantic changes. Signed-off-by: Benjamin Tissoires --- drivers/hid/hid-input.c | 61 +++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 7015080..47f98a3 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -1163,6 +1163,38 @@ static void report_features(struct hid_device *hid) } } +static struct hid_input *hidinput_allocate(struct hid_device *hid) +{ + struct hid_input *hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL); + struct input_dev *input_dev = input_allocate_device(); + if (!hidinput || !input_dev) { + kfree(hidinput); + input_free_device(input_dev); + hid_err(hid, "Out of memory during hid input probe\n"); + return NULL; + } + + input_set_drvdata(input_dev, hid); + input_dev->event = hid->ll_driver->hidinput_input_event; + input_dev->open = hidinput_open; + input_dev->close = hidinput_close; + input_dev->setkeycode = hidinput_setkeycode; + input_dev->getkeycode = hidinput_getkeycode; + + input_dev->name = hid->name; + input_dev->phys = hid->phys; + input_dev->uniq = hid->uniq; + input_dev->id.bustype = hid->bus; + input_dev->id.vendor = hid->vendor; + input_dev->id.product = hid->product; + input_dev->id.version = hid->version; + input_dev->dev.parent = hid->dev.parent; + hidinput->input = input_dev; + list_add_tail(&hidinput->list, &hid->inputs); + + return hidinput; +} + /* * Register the input device; print a message. * Configure the input layer interface @@ -1174,7 +1206,6 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) struct hid_driver *drv = hid->driver; struct hid_report *report; struct hid_input *hidinput = NULL; - struct input_dev *input_dev; int i, j, k; INIT_LIST_HEAD(&hid->inputs); @@ -1205,33 +1236,9 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) continue; if (!hidinput) { - hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL); - input_dev = input_allocate_device(); - if (!hidinput || !input_dev) { - kfree(hidinput); - input_free_device(input_dev); - hid_err(hid, "Out of memory during hid input probe\n"); + hidinput = hidinput_allocate(hid); + if (!hidinput) goto out_unwind; - } - - input_set_drvdata(input_dev, hid); - input_dev->event = - hid->ll_driver->hidinput_input_event; - input_dev->open = hidinput_open; - input_dev->close = hidinput_close; - input_dev->setkeycode = hidinput_setkeycode; - input_dev->getkeycode = hidinput_getkeycode; - - input_dev->name = hid->name; - input_dev->phys = hid->phys; - input_dev->uniq = hid->uniq; - input_dev->id.bustype = hid->bus; - input_dev->id.vendor = hid->vendor; - input_dev->id.product = hid->product; - input_dev->id.version = hid->version; - input_dev->dev.parent = hid->dev.parent; - hidinput->input = input_dev; - list_add_tail(&hidinput->list, &hid->inputs); } for (i = 0; i < report->maxfield; i++)