linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anshul Garg <aksgarg1989@gmail.com>
To: dmitry.torokhov@gmail.com, dtor@mail.ru, linux-input@vger.kernel.org
Cc: aksgarg1989@gmail.com, anshul.g@samsung.com
Subject: [PATCH] Input : Optimize joydev_connect function
Date: Tue, 10 Mar 2015 11:36:17 -0700	[thread overview]
Message-ID: <1426012577-921-1-git-send-email-aksgarg1989@gmail.com> (raw)
In-Reply-To: <aksgarg1989@gmail.com>

From: Anshul Garg <aksgarg1989@gmail.com>

In joydev_connect function added check for event type before
setting properties for that event. This will avoid dummy
loop iterations which checks for event code even if event type
is not set.

Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
---
 drivers/input/joydev.c |   44 ++++++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index f362883..a37a26c 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -797,27 +797,31 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
 	joydev->handle.name = dev_name(&joydev->dev);
 	joydev->handle.handler = handler;
 	joydev->handle.private = joydev;
+
+	if (test_bit(EV_ABS, dev->evbit)) {
+		for (i = 0; i < ABS_CNT; i++)
+			if (test_bit(i, dev->absbit)) {
+				joydev->absmap[i] = joydev->nabs;
+				joydev->abspam[joydev->nabs] = i;
+				joydev->nabs++;
+			}
+	}
 
-	for (i = 0; i < ABS_CNT; i++)
-		if (test_bit(i, dev->absbit)) {
-			joydev->absmap[i] = joydev->nabs;
-			joydev->abspam[joydev->nabs] = i;
-			joydev->nabs++;
-		}
-
-	for (i = BTN_JOYSTICK - BTN_MISC; i < KEY_MAX - BTN_MISC + 1; i++)
-		if (test_bit(i + BTN_MISC, dev->keybit)) {
-			joydev->keymap[i] = joydev->nkey;
-			joydev->keypam[joydev->nkey] = i + BTN_MISC;
-			joydev->nkey++;
-		}
-
-	for (i = 0; i < BTN_JOYSTICK - BTN_MISC; i++)
-		if (test_bit(i + BTN_MISC, dev->keybit)) {
-			joydev->keymap[i] = joydev->nkey;
-			joydev->keypam[joydev->nkey] = i + BTN_MISC;
-			joydev->nkey++;
-		}
+	if (test_bit(EV_KEY, dev->evbit)) {
+		for (i = BTN_JOYSTICK - BTN_MISC; i < KEY_MAX - BTN_MISC + 1; i++)
+			if (test_bit(i + BTN_MISC, dev->keybit)) {
+				joydev->keymap[i] = joydev->nkey;
+				joydev->keypam[joydev->nkey] = i + BTN_MISC;
+				joydev->nkey++;
+			}
+
+		for (i = 0; i < BTN_JOYSTICK - BTN_MISC; i++)
+			if (test_bit(i + BTN_MISC, dev->keybit)) {
+				joydev->keymap[i] = joydev->nkey;
+				joydev->keypam[joydev->nkey] = i + BTN_MISC;
+				joydev->nkey++;
+			}
+	}
 
 	for (i = 0; i < joydev->nabs; i++) {
 		j = joydev->abspam[i];
-- 
1.7.9.5


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com


             reply	other threads:[~2015-03-10 18:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-10 18:36 Anshul Garg [this message]
2015-03-11  1:44 ` [PATCH] Input : Optimize joydev_connect function Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426012577-921-1-git-send-email-aksgarg1989@gmail.com \
    --to=aksgarg1989@gmail.com \
    --cc=anshul.g@samsung.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=dtor@mail.ru \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).