Commit 1c1813a7 authored by Benjamin Tissoires's avatar Benjamin Tissoires Committed by Jiri Kosina

HID: core: statically allocate read buffers

This is a preparation patch for rethinking the generic processing
of HID reports.

We can actually pre-allocate all of our memory instead of dynamically
allocating/freeing it whenever we parse a report.
Signed-off-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Reviewed-by: default avatarPing Cheng <ping.cheng@wacom.com>
Acked-by: default avatarPeter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent a254a9da
...@@ -101,7 +101,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned ...@@ -101,7 +101,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
field = kzalloc((sizeof(struct hid_field) + field = kzalloc((sizeof(struct hid_field) +
usages * sizeof(struct hid_usage) + usages * sizeof(struct hid_usage) +
usages * sizeof(unsigned)), GFP_KERNEL); 2 * usages * sizeof(unsigned int)), GFP_KERNEL);
if (!field) if (!field)
return NULL; return NULL;
...@@ -109,6 +109,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned ...@@ -109,6 +109,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
report->field[field->index] = field; report->field[field->index] = field;
field->usage = (struct hid_usage *)(field + 1); field->usage = (struct hid_usage *)(field + 1);
field->value = (s32 *)(field->usage + usages); field->value = (s32 *)(field->usage + usages);
field->new_value = (s32 *)(field->value + usages);
field->report = report; field->report = report;
return field; return field;
...@@ -1541,9 +1542,8 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field, ...@@ -1541,9 +1542,8 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
__s32 max = field->logical_maximum; __s32 max = field->logical_maximum;
__s32 *value; __s32 *value;
value = kmalloc_array(count, sizeof(__s32), GFP_ATOMIC); value = field->new_value;
if (!value) memset(value, 0, count * sizeof(__s32));
return;
for (n = 0; n < count; n++) { for (n = 0; n < count; n++) {
...@@ -1557,7 +1557,7 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field, ...@@ -1557,7 +1557,7 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
value[n] >= min && value[n] <= max && value[n] >= min && value[n] <= max &&
value[n] - min < field->maxusage && 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)
goto exit; return;
} }
for (n = 0; n < count; n++) { for (n = 0; n < count; n++) {
...@@ -1581,8 +1581,6 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field, ...@@ -1581,8 +1581,6 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
} }
memcpy(field->value, value, count * sizeof(__s32)); memcpy(field->value, value, count * sizeof(__s32));
exit:
kfree(value);
} }
/* /*
......
...@@ -476,6 +476,7 @@ struct hid_field { ...@@ -476,6 +476,7 @@ struct hid_field {
unsigned report_count; /* number of this field in the report */ unsigned report_count; /* number of this field in the report */
unsigned report_type; /* (input,output,feature) */ unsigned report_type; /* (input,output,feature) */
__s32 *value; /* last known value(s) */ __s32 *value; /* last known value(s) */
__s32 *new_value; /* newly read value(s) */
__s32 logical_minimum; __s32 logical_minimum;
__s32 logical_maximum; __s32 logical_maximum;
__s32 physical_minimum; __s32 physical_minimum;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment