@@ -929,6 +929,15 @@ exit:
kfree(value);
}
+static unsigned int hid_field_length(struct hid_field *field)
+{
+ unsigned count = field->report_count;
+ unsigned offset = field->report_offset;
+ unsigned size = field->report_size;
+
+ return offset + count * size;
+}
+
/*
* Output the field into the report.
*/
@@ -938,13 +947,8 @@ static void hid_output_field(struct hid_field *field, __u8 *data)
unsigned count = field->report_count;
unsigned offset = field->report_offset;
unsigned size = field->report_size;
- unsigned bitsused = offset + count * size;
unsigned n;
- /* make sure the unused bits in the last byte are zeros */
- if (count > 0 && size > 0 && (bitsused % 8) != 0)
- data[(bitsused-1)/8] &= (1 << (bitsused % 8)) - 1;
-
for (n = 0; n < count; n++) {
if (field->logical_minimum < 0) /* signed values */
implement(data, offset + n * size, size, s32ton(field->value[n], size));
@@ -960,10 +964,19 @@ static void hid_output_field(struct hid_field *field, __u8 *data)
void hid_output_report(struct hid_report *report, __u8 *data)
{
unsigned n;
+ unsigned length, bitsused;
if (report->id > 0)
*data++ = report->id;
+ length = 0;
+ for (n = 0; n < report->maxfield; n++) {
+ bitsused = hid_field_length(report->field[n]);
+ if (bitsused > length)
+ length = bitsused;
+ }
+ memset(data, 0, (length + 7) / 8);
+
for (n = 0; n < report->maxfield; n++)
hid_output_field(report->field[n], data);
}