Skip to content

Commit cf5b2fb

Browse files
semihalf-czubak-angelaJiri Kosina
authored andcommitted
HID: i2c-hid: fix handling numbered reports with IDs of 15 and above
Special handling of numbered reports with IDs of 15 and above is only needed when executing what HID-I2C spec is calling "Class Specific Requests", and not when simply sending output reports. Additionally, our mangling of report ID in i2c_hid_set_or_send_report() resulted in incorrect report ID being written into SET_REPORT command payload. To solve it let's move all the report ID manipulation into __i2c_hid_command() where we form the command data structure. Signed-off-by: Angela Czubak <acz@semihalf.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Tested-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 9b57f45 commit cf5b2fb

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

drivers/hid/i2c-hid/i2c-hid-core.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ union command {
9797
__le16 reg;
9898
__u8 reportTypeID;
9999
__u8 opcode;
100+
__u8 reportID;
100101
} __packed c;
101102
};
102103

@@ -232,7 +233,13 @@ static int __i2c_hid_command(struct i2c_client *client,
232233

233234
if (length > 2) {
234235
cmd->c.opcode = command->opcode;
235-
cmd->c.reportTypeID = reportID | reportType << 4;
236+
if (reportID < 0x0F) {
237+
cmd->c.reportTypeID = reportType << 4 | reportID;
238+
} else {
239+
cmd->c.reportTypeID = reportType << 4 | 0x0F;
240+
cmd->c.reportID = reportID;
241+
length++;
242+
}
236243
}
237244

238245
memcpy(cmd->data + length, args, args_len);
@@ -293,18 +300,13 @@ static int i2c_hid_get_report(struct i2c_client *client, u8 reportType,
293300
u8 reportID, unsigned char *buf_recv, int data_len)
294301
{
295302
struct i2c_hid *ihid = i2c_get_clientdata(client);
296-
u8 args[3];
303+
u8 args[2];
297304
int ret;
298305
int args_len = 0;
299306
u16 readRegister = le16_to_cpu(ihid->hdesc.wDataRegister);
300307

301308
i2c_hid_dbg(ihid, "%s\n", __func__);
302309

303-
if (reportID >= 0x0F) {
304-
args[args_len++] = reportID;
305-
reportID = 0x0F;
306-
}
307-
308310
args[args_len++] = readRegister & 0xFF;
309311
args[args_len++] = readRegister >> 8;
310312

@@ -350,18 +352,12 @@ static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType,
350352
size = 2 /* size */ +
351353
(reportID ? 1 : 0) /* reportID */ +
352354
data_len /* buf */;
353-
args_len = (reportID >= 0x0F ? 1 : 0) /* optional third byte */ +
354-
2 /* dataRegister */ +
355+
args_len = 2 /* dataRegister */ +
355356
size /* args */;
356357

357358
if (!use_data && maxOutputLength == 0)
358359
return -ENOSYS;
359360

360-
if (reportID >= 0x0F) {
361-
args[index++] = reportID;
362-
reportID = 0x0F;
363-
}
364-
365361
/*
366362
* use the data register for feature reports or if the device does not
367363
* support the output register

0 commit comments

Comments
 (0)