From patchwork Thu Jun 19 13:12:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 4383161 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 445A7BEEAA for ; Thu, 19 Jun 2014 13:13:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4FC952034F for ; Thu, 19 Jun 2014 13:13:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3621E20340 for ; Thu, 19 Jun 2014 13:13:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752927AbaFSNNO (ORCPT ); Thu, 19 Jun 2014 09:13:14 -0400 Received: from mail-wg0-f41.google.com ([74.125.82.41]:63046 "EHLO mail-wg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751570AbaFSNNO (ORCPT ); Thu, 19 Jun 2014 09:13:14 -0400 Received: by mail-wg0-f41.google.com with SMTP id a1so2233860wgh.0 for ; Thu, 19 Jun 2014 06:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=3oIuwOFe/F0afYzOS20+4jcJZ2cC5pB9ESV+HJYvV80=; b=lQbssP/D3odbFaVOy5V6UShRlAPSQ/XMe+l1gVpFSOwb7KV8OMzU/ZLYiimQLSVoPF oMstiBJ0gohoxYb64QBX5+QLS1GFnm8ww8akrQyA8PiwyAmsp/c5uNGyes6TjcuZc7GG jtnxRdFwUjjctIMyeP1Eo4OqYWq7yfCj42zkxHH82m8tT9BeMacPihyv/DC7O8tQLu0T 7+GiF/Nfv7dlONvALZs5S562UHd3gBTTFj2iP6Wd2irfoU3ATp+Z/38kyjaUDU71HKwR 8uH9/2zM/7uUkWHbDvdvKlZEQ9sHp90elw/+osZRqj2hLrUobMq9Jj6TmDdSlXTN4CYc TygA== X-Received: by 10.194.85.225 with SMTP id k1mr4831698wjz.49.1403183591959; Thu, 19 Jun 2014 06:13:11 -0700 (PDT) Received: from david-tp.localdomain (stgt-4d02ee43.pool.mediaWays.net. [77.2.238.67]) by mx.google.com with ESMTPSA id gi15sm8694492wjc.20.2014.06.19.06.13.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Jun 2014 06:13:11 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: Dmitry Torokhov , Peter Hutterer , Benjamin Tissoires , David Herrmann Subject: [PATCH] Input: uinput - uinput_validate_absbits() cleanup Date: Thu, 19 Jun 2014 15:12:59 +0200 Message-Id: <1403183579-15680-1-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.0.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This moves basic checks and setup from uinput_setup_device() into uinput_validate_absbits() to make it easier to use. This way, we can call it from other places without copying the boilerplate code. Signed-off-by: David Herrmann Reviewed-by: Peter Hutterer --- drivers/input/misc/uinput.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 8569362..615324c 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -311,7 +311,13 @@ static int uinput_open(struct inode *inode, struct file *file) static int uinput_validate_absbits(struct input_dev *dev) { unsigned int cnt; - int retval = 0; + int nslot; + + if (!test_bit(EV_ABS, dev->evbit)) + return 0; + + /* check if absmin/absmax/absfuzz/absflat are filled as + * told in Documentation/input/input-programming.txt */ for (cnt = 0; cnt < ABS_CNT; cnt++) { int min, max; @@ -327,8 +333,7 @@ static int uinput_validate_absbits(struct input_dev *dev) UINPUT_NAME, cnt, input_abs_get_min(dev, cnt), input_abs_get_max(dev, cnt)); - retval = -EINVAL; - break; + return -EINVAL; } if (input_abs_get_flat(dev, cnt) > @@ -340,11 +345,18 @@ static int uinput_validate_absbits(struct input_dev *dev) input_abs_get_flat(dev, cnt), input_abs_get_min(dev, cnt), input_abs_get_max(dev, cnt)); - retval = -EINVAL; - break; + return -EINVAL; } } - return retval; + + if (test_bit(ABS_MT_SLOT, dev->absbit)) { + nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1; + input_mt_init_slots(dev, nslot, 0); + } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) { + input_set_events_per_packet(dev, 60); + } + + return 0; } static int uinput_allocate_device(struct uinput_device *udev) @@ -410,19 +422,9 @@ static int uinput_setup_device(struct uinput_device *udev, input_abs_set_flat(dev, i, user_dev->absflat[i]); } - /* check if absmin/absmax/absfuzz/absflat are filled as - * told in Documentation/input/input-programming.txt */ - if (test_bit(EV_ABS, dev->evbit)) { - retval = uinput_validate_absbits(dev); - if (retval < 0) - goto exit; - if (test_bit(ABS_MT_SLOT, dev->absbit)) { - int nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1; - input_mt_init_slots(dev, nslot, 0); - } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) { - input_set_events_per_packet(dev, 60); - } - } + retval = uinput_validate_absbits(dev); + if (retval < 0) + goto exit; udev->state = UIST_SETUP_COMPLETE; retval = count;