Skip to content

Commit a6ac4e2

Browse files
committed
Input: mms114 - fix touch indexing for MMS134S and MMS136
The MMS134S and MMS136 touch controllers have an event size of 6 bytes rather than 8 bytes. When __mms114_read_reg() reads the touch data packet from the device into the touch buffer, the events are packed tightly at 6-byte intervals. However, the driver iterates through the events using standard C array indexing (touch[index]), where each element is sizeof(struct mms114_touch) (8 bytes) apart. As a result, any touch events beyond the first one are read from incorrect offsets and parsed improperly. Fix this by explicitly calculating the byte offset for each touch event based on the device's specific event size. Fixes: 53fefdd ("Input: mms114 - support MMS136") Fixes: ab10867 ("Input: mms114 - support MMS134S") Reported-by: sashiko-bot@kernel.org Assisted-by: Antigravity:gemini-3.5-flash Reviewed-by: Bryam Vargas <hexlabsecurity@proton.me> Link: https://patch.msgid.link/20260616050912.1531241-1-dmitry.torokhov@gmail.com Cc: stable@vger.kernel.org Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent df2b818 commit a6ac4e2

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

drivers/input/touchscreen/mms114.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ static irqreturn_t mms114_interrupt(int irq, void *dev_id)
217217
struct mms114_data *data = dev_id;
218218
struct i2c_client *client = data->client;
219219
struct mms114_touch touch[MMS114_MAX_TOUCH];
220+
struct mms114_touch *t;
220221
int packet_size;
222+
int event_size;
221223
int touch_size;
222224
int index;
223225
int error;
@@ -234,28 +236,32 @@ static irqreturn_t mms114_interrupt(int irq, void *dev_id)
234236

235237
/* MMS136 has slightly different event size */
236238
if (data->type == TYPE_MMS134S || data->type == TYPE_MMS136)
237-
touch_size = packet_size / MMS136_EVENT_SIZE;
239+
event_size = MMS136_EVENT_SIZE;
238240
else
239-
touch_size = packet_size / MMS114_EVENT_SIZE;
241+
event_size = MMS114_EVENT_SIZE;
242+
243+
touch_size = packet_size / event_size;
240244

241245
error = __mms114_read_reg(data, MMS114_INFORMATION, packet_size,
242246
(u8 *)touch);
243247
if (error < 0)
244248
goto out;
245249

246250
for (index = 0; index < touch_size; index++) {
247-
switch (touch[index].type) {
251+
t = (struct mms114_touch *)((u8 *)touch + index * event_size);
252+
253+
switch (t->type) {
248254
case MMS114_TYPE_TOUCHSCREEN:
249-
mms114_process_mt(data, touch + index);
255+
mms114_process_mt(data, t);
250256
break;
251257

252258
case MMS114_TYPE_TOUCHKEY:
253-
mms114_process_touchkey(data, touch + index);
259+
mms114_process_touchkey(data, t);
254260
break;
255261

256262
default:
257263
dev_err(&client->dev, "Wrong touch type (%d)\n",
258-
touch[index].type);
264+
t->type);
259265
break;
260266
}
261267
}

0 commit comments

Comments
 (0)