From patchwork Sat Jul 19 13:10:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 4589431 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8F0C29F1D6 for ; Sat, 19 Jul 2014 13:11:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A1824201C0 for ; Sat, 19 Jul 2014 13:11:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A9954201BA for ; Sat, 19 Jul 2014 13:11:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752943AbaGSNLD (ORCPT ); Sat, 19 Jul 2014 09:11:03 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:33338 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754772AbaGSNLC (ORCPT ); Sat, 19 Jul 2014 09:11:02 -0400 Received: by mail-we0-f174.google.com with SMTP id x48so5664695wes.19 for ; Sat, 19 Jul 2014 06:11:01 -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:in-reply-to:references; bh=j4gjeh0tuETpt33mCIABTaN0Qtfxf2UCi7ZuNfnFP2U=; b=wvAj2LtZkecdqv+WJoMpH8CFMJrX1eh7ZxahrXr7IXnaxh1BuP7wos9LH4ctjwkjom niF/ZrpBuUCddS5hTw3Xwl6vXRmSORZiUIdwbIE6l7vSSR1TvAJNhv10NMQnTEDyUhhY sGsVePrjsB5NuM9OzgY4kqEIwkLVhGXUdiPk/e+zBQdqxdKfuLYosuRI/tefmTrhoa4Y GOtnQ2QMak3iIjS2aXfAjBObtAu8A3ItOfyhROLhnZKN2NI+KyAerNS7ctfBY+/JAW9s 1taYaP3+3uuROhupMo4v6dORJ7TaIj6pHhe+FxOZx4QdR0ZlvSjzU4J2tSmH7Osyx5v0 19XA== X-Received: by 10.180.21.235 with SMTP id y11mr16068541wie.75.1405775461096; Sat, 19 Jul 2014 06:11:01 -0700 (PDT) Received: from david-tp.localdomain (stgt-5f72b883.pool.mediaWays.net. [95.114.184.131]) by mx.google.com with ESMTPSA id ek3sm21919229wjd.17.2014.07.19.06.10.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 19 Jul 2014 06:11:00 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: Peter Hutterer , Dmitry Torokhov , Dmitry Torokhov , David Herrmann Subject: [PATCH RESEND 2/5] Input: uinput - uinput_validate_absbits() cleanup Date: Sat, 19 Jul 2014 15:10:42 +0200 Message-Id: <1405775445-4454-3-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.0.2 In-Reply-To: <1405775445-4454-1-git-send-email-dh.herrmann@gmail.com> References: <1405775445-4454-1-git-send-email-dh.herrmann@gmail.com> 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, RP_MATCHES_RCVD, T_DKIM_INVALID, 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. Reviewed-by: Peter Hutterer Signed-off-by: David Herrmann --- 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;