{
struct keychord_device *kdev = file->private_data;
struct input_keychord *keychords = 0;
- struct input_keychord *keychord;
+ struct input_keychord *keychord, *next, *end;
int ret, i, key;
unsigned long flags;
- size_t resid = count;
- size_t key_bytes;
if (count < sizeof(struct input_keychord) || count > PAGE_SIZE)
return -EINVAL;
kdev->head = kdev->tail = 0;
keychord = keychords;
+ end = (struct input_keychord *)((char *)keychord + count);
- while (resid > 0) {
- /* Is the entire keychord entry header present ? */
- if (resid < sizeof(struct input_keychord)) {
- pr_err("keychord: Insufficient bytes present for header %zu\n",
- resid);
- goto err_unlock_return;
- }
- resid -= sizeof(struct input_keychord);
- if (keychord->count <= 0) {
+ while (keychord < end) {
+ next = NEXT_KEYCHORD(keychord);
+ if (keychord->count <= 0 || next > end) {
pr_err("keychord: invalid keycode count %d\n",
keychord->count);
goto err_unlock_return;
}
- key_bytes = keychord->count * sizeof(keychord->keycodes[0]);
- /* Do we have all the expected keycodes ? */
- if (resid < key_bytes) {
- pr_err("keychord: Insufficient bytes present for keycount %zu\n",
- resid);
- goto err_unlock_return;
- }
- resid -= key_bytes;
-
if (keychord->version != KEYCHORD_VERSION) {
pr_err("keychord: unsupported version %d\n",
keychord->version);
}
kdev->keychord_count++;
- keychord = NEXT_KEYCHORD(keychord);
+ keychord = next;
}
kdev->keychords = keychords;