Skip to content

Commit f2d4ddf

Browse files
bentissJiri Kosina
authored andcommitted
HID: input: rework spaghetti code with switch statements
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> Reviewed-by: Ping Cheng <ping.cheng@wacom.com> Acked-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 3c2b0db commit f2d4ddf

1 file changed

Lines changed: 43 additions & 37 deletions

File tree

drivers/hid/hid-input.c

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,12 +1354,6 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
13541354

13551355
input = field->hidinput->input;
13561356

1357-
if (usage->type == EV_ABS &&
1358-
(((*quirks & HID_QUIRK_X_INVERT) && usage->code == ABS_X) ||
1359-
((*quirks & HID_QUIRK_Y_INVERT) && usage->code == ABS_Y))) {
1360-
value = field->logical_maximum - value;
1361-
}
1362-
13631357
if (usage->hat_min < usage->hat_max || usage->hat_dir) {
13641358
int hat_dir = usage->hat_dir;
13651359
if (!hat_dir)
@@ -1370,59 +1364,71 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
13701364
return;
13711365
}
13721366

1373-
if (usage->hid == HID_DG_INVERT) {
1367+
switch (usage->hid) {
1368+
case HID_DG_INVERT:
13741369
*quirks = value ? (*quirks | HID_QUIRK_INVERT) : (*quirks & ~HID_QUIRK_INVERT);
13751370
return;
1376-
}
13771371

1378-
if (usage->hid == HID_DG_INRANGE) {
1372+
case HID_DG_INRANGE:
13791373
if (value) {
13801374
input_event(input, usage->type, (*quirks & HID_QUIRK_INVERT) ? BTN_TOOL_RUBBER : usage->code, 1);
13811375
return;
13821376
}
13831377
input_event(input, usage->type, usage->code, 0);
13841378
input_event(input, usage->type, BTN_TOOL_RUBBER, 0);
13851379
return;
1386-
}
13871380

1388-
if (usage->hid == HID_DG_TIPPRESSURE && (*quirks & HID_QUIRK_NOTOUCH)) {
1389-
int a = field->logical_minimum;
1390-
int b = field->logical_maximum;
1391-
input_event(input, EV_KEY, BTN_TOUCH, value > a + ((b - a) >> 3));
1392-
}
1381+
case HID_DG_TIPPRESSURE:
1382+
if (*quirks & HID_QUIRK_NOTOUCH) {
1383+
int a = field->logical_minimum;
1384+
int b = field->logical_maximum;
1385+
1386+
input_event(input, EV_KEY, BTN_TOUCH, value > a + ((b - a) >> 3));
1387+
}
1388+
break;
13931389

1394-
if (usage->hid == (HID_UP_PID | 0x83UL)) { /* Simultaneous Effects Max */
1390+
case HID_UP_PID | 0x83UL: /* Simultaneous Effects Max */
13951391
dbg_hid("Maximum Effects - %d\n",value);
13961392
return;
1397-
}
13981393

1399-
if (usage->hid == (HID_UP_PID | 0x7fUL)) {
1394+
case HID_UP_PID | 0x7fUL:
14001395
dbg_hid("PID Pool Report\n");
14011396
return;
14021397
}
14031398

1404-
if ((usage->type == EV_KEY) && (usage->code == 0)) /* Key 0 is "unassigned", not KEY_UNKNOWN */
1405-
return;
1399+
switch (usage->type) {
1400+
case EV_KEY:
1401+
if (usage->code == 0) /* Key 0 is "unassigned", not KEY_UNKNOWN */
1402+
return;
1403+
break;
14061404

1407-
if ((usage->type == EV_REL) && (usage->code == REL_WHEEL_HI_RES ||
1408-
usage->code == REL_HWHEEL_HI_RES)) {
1409-
hidinput_handle_scroll(usage, input, value);
1410-
return;
1411-
}
1405+
case EV_REL:
1406+
if (usage->code == REL_WHEEL_HI_RES ||
1407+
usage->code == REL_HWHEEL_HI_RES) {
1408+
hidinput_handle_scroll(usage, input, value);
1409+
return;
1410+
}
1411+
break;
14121412

1413-
if ((usage->type == EV_ABS) && (field->flags & HID_MAIN_ITEM_RELATIVE) &&
1414-
(usage->code == ABS_VOLUME)) {
1415-
int count = abs(value);
1416-
int direction = value > 0 ? KEY_VOLUMEUP : KEY_VOLUMEDOWN;
1417-
int i;
1413+
case EV_ABS:
1414+
if ((field->flags & HID_MAIN_ITEM_RELATIVE) &&
1415+
usage->code == ABS_VOLUME) {
1416+
int count = abs(value);
1417+
int direction = value > 0 ? KEY_VOLUMEUP : KEY_VOLUMEDOWN;
1418+
int i;
1419+
1420+
for (i = 0; i < count; i++) {
1421+
input_event(input, EV_KEY, direction, 1);
1422+
input_sync(input);
1423+
input_event(input, EV_KEY, direction, 0);
1424+
input_sync(input);
1425+
}
1426+
return;
14181427

1419-
for (i = 0; i < count; i++) {
1420-
input_event(input, EV_KEY, direction, 1);
1421-
input_sync(input);
1422-
input_event(input, EV_KEY, direction, 0);
1423-
input_sync(input);
1424-
}
1425-
return;
1428+
} else if (((*quirks & HID_QUIRK_X_INVERT) && usage->code == ABS_X) ||
1429+
((*quirks & HID_QUIRK_Y_INVERT) && usage->code == ABS_Y))
1430+
value = field->logical_maximum - value;
1431+
break;
14261432
}
14271433

14281434
/*

0 commit comments

Comments
 (0)