Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] Input: jadard_jd9365tx: wrong supply array type in
  jadard_tp_probe()
- [Low] Input: jadard_jd9365tx: u32 overflow in jd_resolve_coord_addr()
  bounds check
--

commit 57a37b18fbb37602183e66793eebea170b919dc2
Author: Hefei <[email protected]>

Input: add Jadard JD9365TX in-cell touchscreen driver

This commit adds a polling I2C touchscreen driver for the Jadard JD9365TX
in-cell touch controller.

> diff --git a/drivers/input/touchscreen/jadard_jd9365tx.c 
> b/drivers/input/touchscreen/jadard_jd9365tx.c
> new file mode 100644
> index 0000000000000..3312119d7b696
> --- /dev/null
> +++ b/drivers/input/touchscreen/jadard_jd9365tx.c
> @@ -0,0 +1,356 @@

[ ... ]

> +struct jadard_tp {
> +     struct i2c_client *client;
> +     struct input_dev *input;
> +     struct touchscreen_properties prop;
> +     struct gpio_desc *reset;
> +     struct regulator *vdd;
> +     struct regulator *iovcc;
> +     u32 coord_addr;
> +     u16 touch_data_size;
> +     u16 max_points;
> +     unsigned int poll_interval_ms;
> +};

[ ... ]

> +static int jd_resolve_coord_addr(struct jadard_tp *ts)
> +{
> +     u32 esram_num_addr = JD_ERAM_BASE + 4 + JD_MAX_DSRAM_NUM * 8;
> +     u32 esram_sec_addr = esram_num_addr + 4;
> +     u8 buf[JD_ESRAM_SECTION_NUM * 8];
> +     u32 addr, len;
> +     int ret;
> +
> +     ret = jd_read_reg(ts->client, esram_sec_addr, buf, sizeof(buf));
> +     if (ret)
> +             return ret;
> +
> +     addr = get_unaligned_le32(&buf[JD_ESRAM_COORD_IDX * 8]);
> +     len = get_unaligned_le32(&buf[JD_ESRAM_COORD_IDX * 8 + 4]);
> +
> +     if (addr < JD_ERAM_BASE ||
> +         addr + len > JD_ERAM_BASE + 0x1000 ||
> +         len < JD_REPORT_MIN_SIZE || len > JD_TOUCH_DATA_SIZE)
> +             return -EINVAL;

[Severity: Low]
Can the 32-bit addition addr + len wrap around here?  If the controller
returns a corrupted section descriptor with addr near U32_MAX and len in
[JD_REPORT_MIN_SIZE, JD_TOUCH_DATA_SIZE], addr + len wraps to a small
value below JD_ERAM_BASE + 0x1000 and jd_resolve_coord_addr() accepts an
invalid coordinate address instead of falling back to
JD_DEFAULT_COORD_ADDR.  Checking len first and testing
addr > JD_ERAM_BASE + 0x1000 - len avoids the overflow.

[ ... ]

> +static int jadard_tp_probe(struct i2c_client *client)
> +{
> +     struct device *dev = &client->dev;
> +     struct jadard_tp *ts;
> +     struct input_dev *input;
> +     struct regulator_bulk_data supplies[2];
> +     u32 val;
> +     int error;
> +
> +     ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
> +     if (!ts)
> +             return -ENOMEM;
> +
> +     ts->client = client;
> +     ts->max_points = JD_MAX_POINTS;
> +     ts->poll_interval_ms = JD_DEFAULT_POLL_MS;
> +     ts->touch_data_size = JD_TOUCH_DATA_SIZE;
> +     ts->coord_addr = JD_DEFAULT_COORD_ADDR;
> +
> +     supplies[0].supply = "vdd";
> +     supplies[1].supply = "iovcc";
> +     error = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(supplies),
> +                                            supplies);

[Severity: High]
Does passing struct regulator_bulk_data * to
devm_regulator_bulk_get_enable() fail to build with
-Werror=incompatible-pointer-types?  devm_regulator_bulk_get_enable()
takes a const char * const * array of supply names, so if built without
that error it also reads uninitialized stack memory
(supplies[0].consumer) as the second supply name pointer.  Using static
const char * const supplies[] = { "vdd", "iovcc" } fixes this, and the
unused vdd and iovcc fields in struct jadard_tp can be dropped as well.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=5

Reply via email to