Skip to content

Commit a5fd88a

Browse files
committed
Input: atmel_mxt_ts - check mem_size before calculating config memory size
In mxt_update_cfg(), the driver calculates the memory size needed to store the configuration as data->mem_size - cfg.start_ofs. If data->mem_size is less than or equal to cfg.start_ofs, this calculation will underflow or result in a zero-size buffer, neither of which is valid for a configuration update. Add a check to return -EINVAL if data->mem_size is too small. While at it, change the types of start_ofs and mem_size in struct mxt_cfg to u16 to match the device address space. Assisted-by: Gemini:gemini-3.1-pro Link: https://patch.msgid.link/20260504185448.4055973-2-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent baa0210 commit a5fd88a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

drivers/input/touchscreen/atmel_mxt_ts.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ struct mxt_cfg {
275275
off_t raw_pos;
276276

277277
u8 *mem;
278-
size_t mem_size;
279-
int start_ofs;
278+
u16 mem_size;
279+
u16 start_ofs;
280280

281281
struct mxt_info info;
282282
};
@@ -1627,6 +1627,13 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw)
16271627
cfg.start_ofs = MXT_OBJECT_START +
16281628
data->info->object_num * sizeof(struct mxt_object) +
16291629
MXT_INFO_CHECKSUM_SIZE;
1630+
1631+
if (data->mem_size <= cfg.start_ofs) {
1632+
dev_err(dev, "Memory size too small: %u < %u\n",
1633+
data->mem_size, cfg.start_ofs);
1634+
return -EINVAL;
1635+
}
1636+
16301637
cfg.mem_size = data->mem_size - cfg.start_ofs;
16311638

16321639
u8 *mem_buf __free(kfree) = cfg.mem = kzalloc(cfg.mem_size, GFP_KERNEL);

0 commit comments

Comments
 (0)