HID: core: de-duplicate some code in hid_input_field()
I had to go twice through the history to get a grasp at this code. De-duplicate the various tests in one common helper to make it more explicit. Note that the `HID_UP_KEYBOARD + 1` condition is tested through https://gitlab.freedesktop.org/libevdev/hid-tools/-/merge_requests/121 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>
This commit is contained in:
parent
1c1813a743
commit
74acc277b6
|
@ -1525,6 +1525,24 @@ static void hid_process_event(struct hid_device *hid, struct hid_field *field,
|
||||||
hid->hiddev_hid_event(hid, field, usage, value);
|
hid->hiddev_hid_event(hid, field, usage, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checks if the given value is valid within this field
|
||||||
|
*/
|
||||||
|
static inline int hid_array_value_is_valid(struct hid_field *field,
|
||||||
|
__s32 value)
|
||||||
|
{
|
||||||
|
__s32 min = field->logical_minimum;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Value needs to be between logical min and max, and
|
||||||
|
* (value - min) is used as an index in the usage array.
|
||||||
|
* This array is of size field->maxusage
|
||||||
|
*/
|
||||||
|
return value >= min &&
|
||||||
|
value <= field->logical_maximum &&
|
||||||
|
value - min < field->maxusage;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Analyse a received field, and fetch the data from it. The field
|
* Analyse a received field, and fetch the data from it. The field
|
||||||
* content is stored for next report processing (we do differential
|
* content is stored for next report processing (we do differential
|
||||||
|
@ -1539,7 +1557,6 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
|
||||||
unsigned offset = field->report_offset;
|
unsigned offset = field->report_offset;
|
||||||
unsigned size = field->report_size;
|
unsigned size = field->report_size;
|
||||||
__s32 min = field->logical_minimum;
|
__s32 min = field->logical_minimum;
|
||||||
__s32 max = field->logical_maximum;
|
|
||||||
__s32 *value;
|
__s32 *value;
|
||||||
|
|
||||||
value = field->new_value;
|
value = field->new_value;
|
||||||
|
@ -1554,8 +1571,7 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
|
||||||
|
|
||||||
/* Ignore report if ErrorRollOver */
|
/* Ignore report if ErrorRollOver */
|
||||||
if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
|
if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
|
||||||
value[n] >= min && value[n] <= max &&
|
hid_array_value_is_valid(field, value[n]) &&
|
||||||
value[n] - min < field->maxusage &&
|
|
||||||
field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
|
field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1563,21 +1579,29 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
|
||||||
for (n = 0; n < count; n++) {
|
for (n = 0; n < count; n++) {
|
||||||
|
|
||||||
if (HID_MAIN_ITEM_VARIABLE & field->flags) {
|
if (HID_MAIN_ITEM_VARIABLE & field->flags) {
|
||||||
hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
|
hid_process_event(hid,
|
||||||
|
field,
|
||||||
|
&field->usage[n],
|
||||||
|
value[n],
|
||||||
|
interrupt);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field->value[n] >= min && field->value[n] <= max
|
if (hid_array_value_is_valid(field, field->value[n]) &&
|
||||||
&& field->value[n] - min < field->maxusage
|
search(value, field->value[n], count))
|
||||||
&& field->usage[field->value[n] - min].hid
|
hid_process_event(hid,
|
||||||
&& search(value, field->value[n], count))
|
field,
|
||||||
hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
|
&field->usage[field->value[n] - min],
|
||||||
|
0,
|
||||||
|
interrupt);
|
||||||
|
|
||||||
if (value[n] >= min && value[n] <= max
|
if (hid_array_value_is_valid(field, value[n]) &&
|
||||||
&& value[n] - min < field->maxusage
|
search(field->value, value[n], count))
|
||||||
&& field->usage[value[n] - min].hid
|
hid_process_event(hid,
|
||||||
&& search(field->value, value[n], count))
|
field,
|
||||||
hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
|
&field->usage[value[n] - min],
|
||||||
|
1,
|
||||||
|
interrupt);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(field->value, value, count * sizeof(__s32));
|
memcpy(field->value, value, count * sizeof(__s32));
|
||||||
|
|
Loading…
Reference in New Issue