linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: "Jiri Kosina" <jikos@kernel.org>,
	"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Ahelenia Ziemiańska" <nabijaczleweli@nabijaczleweli.xyz>,
	"Ping Cheng" <pinglinux@gmail.com>,
	"Aaron Armstrong Skomra" <skomra@gmail.com>,
	"Jason Gerecke" <killertofu@gmail.com>,
	"Peter Hutterer" <peter.hutterer@who-t.net>
Cc: linux-input@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>
Subject: [PATCH v2 05/12] HID: input: rework spaghetti code with switch statements
Date: Thu,  3 Feb 2022 15:32:19 +0100	[thread overview]
Message-ID: <20220203143226.4023622-6-benjamin.tissoires@redhat.com> (raw)
In-Reply-To: <20220203143226.4023622-1-benjamin.tissoires@redhat.com>

Instead of using multiple `if (a == b)`, use the switch statement
which has been done exactly for that.

There should be no functional change (I don't expect moving down
HID_QUIRK_{X|Y}_INVERT having any impact.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-input.c | 80 ++++++++++++++++++++++-------------------
 1 file changed, 43 insertions(+), 37 deletions(-)

diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index d2562497a726..54b3e9c5ccc4 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -1354,12 +1354,6 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
 
 	input = field->hidinput->input;
 
-	if (usage->type == EV_ABS &&
-	    (((*quirks & HID_QUIRK_X_INVERT) && usage->code == ABS_X) ||
-	     ((*quirks & HID_QUIRK_Y_INVERT) && usage->code == ABS_Y))) {
-		value = field->logical_maximum - value;
-	}
-
 	if (usage->hat_min < usage->hat_max || usage->hat_dir) {
 		int hat_dir = usage->hat_dir;
 		if (!hat_dir)
@@ -1370,12 +1364,12 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
 		return;
 	}
 
-	if (usage->hid == HID_DG_INVERT) {
+	switch (usage->hid) {
+	case HID_DG_INVERT:
 		*quirks = value ? (*quirks | HID_QUIRK_INVERT) : (*quirks & ~HID_QUIRK_INVERT);
 		return;
-	}
 
-	if (usage->hid == HID_DG_INRANGE) {
+	case HID_DG_INRANGE:
 		if (value) {
 			input_event(input, usage->type, (*quirks & HID_QUIRK_INVERT) ? BTN_TOOL_RUBBER : usage->code, 1);
 			return;
@@ -1383,46 +1377,58 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
 		input_event(input, usage->type, usage->code, 0);
 		input_event(input, usage->type, BTN_TOOL_RUBBER, 0);
 		return;
-	}
 
-	if (usage->hid == HID_DG_TIPPRESSURE && (*quirks & HID_QUIRK_NOTOUCH)) {
-		int a = field->logical_minimum;
-		int b = field->logical_maximum;
-		input_event(input, EV_KEY, BTN_TOUCH, value > a + ((b - a) >> 3));
-	}
+	case HID_DG_TIPPRESSURE:
+		if (*quirks & HID_QUIRK_NOTOUCH) {
+			int a = field->logical_minimum;
+			int b = field->logical_maximum;
+
+			input_event(input, EV_KEY, BTN_TOUCH, value > a + ((b - a) >> 3));
+		}
+		break;
 
-	if (usage->hid == (HID_UP_PID | 0x83UL)) { /* Simultaneous Effects Max */
+	case HID_UP_PID | 0x83UL: /* Simultaneous Effects Max */
 		dbg_hid("Maximum Effects - %d\n",value);
 		return;
-	}
 
-	if (usage->hid == (HID_UP_PID | 0x7fUL)) {
+	case HID_UP_PID | 0x7fUL:
 		dbg_hid("PID Pool Report\n");
 		return;
 	}
 
-	if ((usage->type == EV_KEY) && (usage->code == 0)) /* Key 0 is "unassigned", not KEY_UNKNOWN */
-		return;
+	switch (usage->type) {
+	case EV_KEY:
+		if (usage->code == 0) /* Key 0 is "unassigned", not KEY_UNKNOWN */
+			return;
+		break;
 
-	if ((usage->type == EV_REL) && (usage->code == REL_WHEEL_HI_RES ||
-					usage->code == REL_HWHEEL_HI_RES)) {
-		hidinput_handle_scroll(usage, input, value);
-		return;
-	}
+	case EV_REL:
+		if (usage->code == REL_WHEEL_HI_RES ||
+		    usage->code == REL_HWHEEL_HI_RES) {
+			hidinput_handle_scroll(usage, input, value);
+			return;
+		}
+		break;
 
-	if ((usage->type == EV_ABS) && (field->flags & HID_MAIN_ITEM_RELATIVE) &&
-			(usage->code == ABS_VOLUME)) {
-		int count = abs(value);
-		int direction = value > 0 ? KEY_VOLUMEUP : KEY_VOLUMEDOWN;
-		int i;
+	case EV_ABS:
+		if ((field->flags & HID_MAIN_ITEM_RELATIVE) &&
+		    usage->code == ABS_VOLUME) {
+			int count = abs(value);
+			int direction = value > 0 ? KEY_VOLUMEUP : KEY_VOLUMEDOWN;
+			int i;
+
+			for (i = 0; i < count; i++) {
+				input_event(input, EV_KEY, direction, 1);
+				input_sync(input);
+				input_event(input, EV_KEY, direction, 0);
+				input_sync(input);
+			}
+			return;
 
-		for (i = 0; i < count; i++) {
-			input_event(input, EV_KEY, direction, 1);
-			input_sync(input);
-			input_event(input, EV_KEY, direction, 0);
-			input_sync(input);
-		}
-		return;
+		} else if (((*quirks & HID_QUIRK_X_INVERT) && usage->code == ABS_X) ||
+			   ((*quirks & HID_QUIRK_Y_INVERT) && usage->code == ABS_Y))
+			value = field->logical_maximum - value;
+		break;
 	}
 
 	/*
-- 
2.33.1


  parent reply	other threads:[~2022-02-03 14:33 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 14:32 [PATCH v2 00/12] HID: fix for generic input processing Benjamin Tissoires
2022-02-03 14:32 ` [PATCH v2 01/12] HID: core: statically allocate read buffers Benjamin Tissoires
2022-02-03 14:32 ` [PATCH v2 02/12] HID: core: de-duplicate some code in hid_input_field() Benjamin Tissoires
2022-02-03 14:32 ` [PATCH v2 03/12] HID: core: split data fetching from processing " Benjamin Tissoires
2022-02-03 14:32 ` [PATCH v2 04/12] HID: input: tag touchscreens as such if the physical is not there Benjamin Tissoires
2022-02-03 14:32 ` Benjamin Tissoires [this message]
2022-02-03 14:32 ` [PATCH v2 06/12] HID: input: move up out-of-range processing of input values Benjamin Tissoires
2022-02-03 14:32 ` [PATCH v2 07/12] HID: compute an ordered list of input fields to process Benjamin Tissoires
2022-02-03 14:32 ` [PATCH v2 08/12] HID: core: for input reports, process the usages by priority list Benjamin Tissoires
2022-02-03 14:32 ` [PATCH v2 09/12] HID: input: enforce Invert usage to be processed before InRange Benjamin Tissoires
2022-02-03 14:32 ` [PATCH v2 10/12] HID: input: remove the need for HID_QUIRK_INVERT Benjamin Tissoires
2022-02-04  1:41   ` Ping Cheng
2022-02-10  5:21   ` Ping Cheng
2022-02-10  5:43     ` Ping Cheng
2022-02-14 10:23       ` Benjamin Tissoires
2022-02-15  2:04         ` Ping Cheng
2022-02-15  8:51           ` Benjamin Tissoires
2022-02-16 12:42             ` Benjamin Tissoires
2022-02-17  1:27               ` Ping Cheng
2022-02-03 14:32 ` [PATCH v2 11/12] HID: input: accommodate priorities for slotted devices Benjamin Tissoires
2022-02-03 14:32 ` [PATCH v2 12/12] Input: docs: add more details on the use of BTN_TOOL Benjamin Tissoires
2022-02-16  5:40   ` Peter Hutterer
2022-03-01 14:53 ` [PATCH v2 00/12] HID: fix for generic input processing Jiri Kosina

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=20220203143226.4023622-6-benjamin.tissoires@redhat.com \
    --to=benjamin.tissoires@redhat.com \
    --cc=corbet@lwn.net \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jikos@kernel.org \
    --cc=killertofu@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nabijaczleweli@nabijaczleweli.xyz \
    --cc=peter.hutterer@who-t.net \
    --cc=pinglinux@gmail.com \
    --cc=skomra@gmail.com \
    --subject='Re: [PATCH v2 05/12] HID: input: rework spaghetti code with switch statements' \
    /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

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).