Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: Hefei <3066883572@qq.com>, dri-devel@lists.freedesktop.org
Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v2 5/6] Input: add Jadard JD9365TX in-cell touchscreen driver
Date: Wed, 25 Nov 2026 02:21:44 +0000	[thread overview]
Message-ID: <sashiko-outbox-232404@kernel.org> (raw)
In-Reply-To: <tencent_0E08C29B27905F3154DF71AA0F7F2BA5EF07@qq.com>

Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] Input: jadard_jd9365tx: deferred jd_hw_init() in jd_poll()
  breaks lifecycle
- [High] Input: jadard_jd9365tx: broken MT slot gating in
  jd_report_touches()
- [Medium] Input: jadard_jd9365tx: uninitialized stack read in
  jd_report_touches()
- [Medium] Input: jadard_jd9365tx: missing reset-gpios handling in
  jadard_tp_probe()
- [Low] Input: jadard_jd9365tx: signed shift overflow in
  jd_resolve_coord_addr()
- [Low] Input: jadard_jd9365tx: duplicate OF-only size parsing in
  jadard_tp_probe()
- [Low] Input: jadard_jd9365tx: Input and I2C subsystem convention
  violations
- [Low] Input: jadard_jd9365tx: missing commit description and invalid
  trailer
--

commit 14bb2db3ff6aa2fe722f173dd49badfb3b138498
Author: Hefei <3066883572@qq.com>

> Input: add Jadard JD9365TX in-cell touchscreen driver
>
> Signed-off-by: Hefei <3066883572@qq.com>
> Co-authored-by: Cursor <cursoragent@cursor.com>

[Severity: Low]
This commit adds a new touchscreen driver without a changelog body
describing the hardware, communication protocol, or polling design, and it
carries a non-standard Co-authored-by trailer for an AI tool without a
corresponding human DCO sign-off.

> diff --git a/drivers/input/touchscreen/jadard_jd9365tx.c b/drivers/input/touchscreen/jadard_jd9365tx.c
> new file mode 100644
> index 0000000000000..2030157c3a5b8
> --- /dev/null
> +++ b/drivers/input/touchscreen/jadard_jd9365tx.c

[ ... ]

> +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 = buf[JD_ESRAM_COORD_IDX * 8 + 0] |
> +	       (buf[JD_ESRAM_COORD_IDX * 8 + 1] << 8) |
> +	       (buf[JD_ESRAM_COORD_IDX * 8 + 2] << 16) |
> +	       (buf[JD_ESRAM_COORD_IDX * 8 + 3] << 24);
> +	len = buf[JD_ESRAM_COORD_IDX * 8 + 4] |
> +	      (buf[JD_ESRAM_COORD_IDX * 8 + 5] << 8) |
> +	      (buf[JD_ESRAM_COORD_IDX * 8 + 6] << 16) |
> +	      (buf[JD_ESRAM_COORD_IDX * 8 + 7] << 24);

[Severity: Low]
Can the `<< 24` shifts on `buf[...]` overflow a 32-bit signed int?

Each `u8` element is promoted to signed `int` before shifting, so bit 7
being set triggers signed integer overflow under CONFIG_UBSAN.  Using
get_unaligned_le32() avoids both manual byte assembly and the signed shift.

> +
> +	if (addr < JD_ERAM_BASE || addr >= JD_ERAM_BASE + 0x1000 ||
> +	    len == 0 || len > JD_TOUCH_DATA_SIZE)
> +		return -EINVAL;
> +
> +	ts->coord_addr = addr;
> +	ts->touch_data_size = (u16)len;
> +	return 0;
> +}

[Severity: Medium]
Can setting `ts->touch_data_size` to a value smaller than 53 cause
jd_report_touches() to read uninitialized stack memory from `buf`?

jd_poll() allocates `u8 buf[JD_TOUCH_DATA_SIZE]` on the stack without
initializing it and reads only `ts->touch_data_size` bytes from I2C.
However, jd_report_touches() unconditionally loops over all 10 slots
(`ts->max_points`) and reads 5 bytes per slot starting at
`JD_TOUCH_COORD_INFO_ADDR` (offsets 3 through 52).  If the ESRAM section
table reports `len < 53`, jd_report_touches() parses uninitialized stack
bytes and reports them to userspace as touch coordinates and touch major
values.

[ ... ]

> +static void jd_report_touches(struct jadard_tp *ts, const u8 *buf)
> +{
> +	u8 finger_num = buf[JD_FINGER_NUM_ADDR];
> +	unsigned int i;
> +	bool any = false;
> +
> +	if (finger_num > ts->max_points)
> +		finger_num = ts->max_points;
> +
> +	for (i = 0; i < ts->max_points; i++) {
> +		const u8 *c = buf + JD_TOUCH_COORD_INFO_ADDR +
> +			      i * JD_FINGER_DATA_SIZE;
> +		u16 x = (c[0] << 8) | c[1];
> +		u16 y = (c[2] << 8) | c[3];
> +		u8 w = c[4];
> +		bool down = false;
> +
> +		if (i < finger_num &&
> +		    x <= ts->abs_x_max && y <= ts->abs_y_max &&
> +		    x != 0xFFFF && y != 0xFFFF)
> +			down = true;

[Severity: High]
Does gating `down` on `i < finger_num` drop active touches in higher-numbered
MT slots when an earlier slot is released?

Each index `i` maps directly to MT slot `i`, while `finger_num` is the total
count of active contacts.  If two fingers are down in slots 0 and 1 and
finger 0 lifts, `finger_num` becomes 1 while slot 1 (`i == 1`) still holds
the remaining finger's coordinates; `i < finger_num` (`1 < 1`) then evaluates
to false and releases slot 1 as well.

Also, when `buf[JD_FINGER_NUM_ADDR] > ts->max_points` (such as 0xFF when the
report buffer is not ready), clamping `finger_num` to `ts->max_points`
processes the frame as up to 10 touches instead of discarding the invalid
frame.

[ ... ]

> +static void jd_poll(struct input_dev *input)
> +{
> +	struct jadard_tp *ts = input_get_drvdata(input);
> +	u8 buf[JD_TOUCH_DATA_SIZE];
> +	int ret;
> +
> +	if (!ts->ready) {
> +		ret = jd_hw_init(ts);
> +		if (ret)
> +			return;
> +		ts->ready = true;
> +	}

[Severity: High]
Does deferring jd_hw_init() from jadard_tp_probe() to jd_poll() break device
probing, polling, and power-cycle recovery?

Because jadard_tp_probe() never communicates with the controller, probe
succeeds and leaves `vdd` and `iovcc` enabled even when the device is absent
or has an unsupported chip ID (`-ENODEV`).  When the input device is opened,
jd_hw_init() -> jd_section_ready() can stall input_open_device() (under
`input->mutex`) and `system_freezable_wq` for up to 50 iterations of
`msleep(2)` plus I2C reads, and any failure causes jd_poll() to retry
jd_hw_init() on every 8-16 ms poll tick indefinitely.  Furthermore, once
`ts->ready` is set, it is never cleared across a DSI panel reset or system
suspend/resume, so the controller is never returned to the 0xF2 backdoor mode
required for subsequent 0xF3 register reads.

[ ... ]

> +static int jadard_tp_probe(struct i2c_client *client)
> +{
> +	struct device *dev = &client->dev;
> +	struct jadard_tp *ts;
> +	struct input_dev *input;
> +	u32 val;
> +	int ret;
> +
> +	ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
> +	if (!ts)
> +		return -ENOMEM;
> +
> +	ts->client = client;
> +	ts->max_points = JD_MAX_POINTS;
> +	ts->abs_x_max = 719;
> +	ts->abs_y_max = 1279;
> +	ts->poll_interval_ms = JD_DEFAULT_POLL_MS;
> +	ts->touch_data_size = JD_TOUCH_DATA_SIZE;
> +
> +	ts->vdd = devm_regulator_get(dev, "vdd");
> +	if (IS_ERR(ts->vdd))
> +		return PTR_ERR(ts->vdd);
> +
> +	ts->iovcc = devm_regulator_get(dev, "iovcc");
> +	if (IS_ERR(ts->iovcc))
> +		return PTR_ERR(ts->iovcc);
> +
> +	ret = regulator_enable(ts->vdd);
> +	if (ret)
> +		return ret;
> +
> +	ret = regulator_enable(ts->iovcc);
> +	if (ret) {
> +		regulator_disable(ts->vdd);
> +		return ret;
> +	}

[Severity: Medium]
Should jadard_tp_probe() request and deassert the optional `reset-gpios`
after enabling the regulators?

The `jadard,jd9365tx` Devicetree binding defines `reset-gpios`, so boards
wiring that reset line can leave the controller held in reset and
unresponsive on I2C if probe never acquires and deasserts it.

> +
> +	ret = devm_add_action_or_reset(dev, jadard_tp_disable_regulators, ts);
> +	if (ret)
> +		return ret;
> +
> +	if (!device_property_read_u32(dev, "poll-interval", &val) &&
> +	    val >= 8 && val <= 100)
> +		ts->poll_interval_ms = val;
> +
> +	if (!of_property_read_u32(dev->of_node, "touchscreen-size-x", &val) && val)
> +		ts->abs_x_max = val - 1;
> +
> +	if (!of_property_read_u32(dev->of_node, "touchscreen-size-y", &val) && val)
> +		ts->abs_y_max = val - 1;

[Severity: Low]
Why parse `touchscreen-size-x` and `touchscreen-size-y` manually with
of_property_read_u32() when touchscreen_parse_properties() is called below?

touchscreen_parse_properties() already reads these properties via the
generic device property API and stores the pre-swap axis maxima in
`ts->prop.max_x` and `ts->prop.max_y`.  On non-OF property providers where
`dev->of_node` is NULL, `ts->abs_x_max` and `ts->abs_y_max` stay at 719 and
1279, causing jd_report_touches() to drop valid coordinates above 719x1279.

> +
> +	input = devm_input_allocate_device(dev);
> +	if (!input)
> +		return -ENOMEM;
> +
> +	input->name = "Jadard JD9365TX Touchscreen";
> +	input->id.bustype = BUS_I2C;
> +	input->dev.parent = dev;
> +
> +	__set_bit(EV_ABS, input->evbit);
> +	__set_bit(EV_KEY, input->evbit);
> +	__set_bit(BTN_TOUCH, input->keybit);
> +
> +	input_set_abs_params(input, ABS_MT_POSITION_X, 0, ts->abs_x_max, 0, 0);
> +	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, ts->abs_y_max, 0, 0);
> +	input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
> +
> +	touchscreen_parse_properties(input, true, &ts->prop);
> +
> +	ret = input_mt_init_slots(input, ts->max_points, INPUT_MT_DIRECT);
> +	if (ret)
> +		return ret;
> +
> +	input_set_drvdata(input, ts);
> +	ts->input = input;
> +	i2c_set_clientdata(client, ts);
> +
> +	ret = input_setup_polling(input, jd_poll);
> +	if (ret)
> +		return ret;
> +
> +	input_set_poll_interval(input, ts->poll_interval_ms);
> +
> +	return input_register_device(input);
> +}
> +
> +static const struct of_device_id jadard_tp_of_match[] = {
> +	{ .compatible = "jadard,jd9365tx" },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, jadard_tp_of_match);
> +
> +static const struct i2c_device_id jadard_tp_id[] = {
> +	{ "jd9365tx", 0 },
> +	{ }
> +};

[Severity: Low]
This isn't a bug, but several places in the driver depart from Input and I2C
subsystem conventions:

- devm_input_allocate_device() already sets `input->dev.parent = dev`, so
  the manual assignment in jadard_tp_probe() is redundant.
- The `__set_bit()` calls for `EV_ABS`, `EV_KEY`, and `BTN_TOUCH` in
  jadard_tp_probe() are redundant because input_set_abs_params() sets
  `EV_ABS` and `input_mt_init_slots(..., INPUT_MT_DIRECT)` sets `EV_KEY` and
  `BTN_TOUCH`.
- Calling `input_report_key(ts->input, BTN_TOUCH, any)` in
  jd_report_touches() is redundant because input_mt_sync_frame() already
  reports `BTN_TOUCH` via pointer emulation.
- `jadard_tp_id[]` should use a named initializer (`{ .name = "jd9365tx" }`)
  rather than `{ "jd9365tx", 0 }`.
- `vdd` and `iovcc` can be managed with devm_regulator_bulk_get_enable()
  instead of open-coding devm_regulator_get(), regulator_enable(), and
  jadard_tp_disable_regulators().
- In Input drivers, error-only variables are conventionally named `error`
  (or `err`), and functions with multiple failure points check the result of
  the final call (`error = input_register_device(input); if (error) return
  error; return 0;`).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_EE81D0ED29E97716D56BDCF1A3C5AAE35B05@qq.com?part=5

  reply	other threads:[~2026-11-25  2:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261125020944.137-1-3066883572@qq.com>
2026-11-25  2:09 ` [PATCH v2 1/6] dt-bindings: display: add VIEWE JD9365TX panel binding Hefei
2026-11-25  2:20   ` sashiko-bot
2026-11-25  2:09 ` [PATCH v2 2/6] dt-bindings: input: add Jadard JD9365TX touchscreen binding Hefei
2026-11-25  2:18   ` sashiko-bot
2026-11-25  2:09 ` [PATCH v2 3/6] dt-bindings: backlight: add VIEWE I2C backlight binding Hefei
2026-11-25  2:17   ` sashiko-bot
2026-11-25  2:09 ` [PATCH v2 4/6] drm/panel: add VIEWE JD9365TX 7 inch DSI panel Hefei
2026-11-25  2:29   ` sashiko-bot
2026-11-25  2:09 ` [PATCH v2 5/6] Input: add Jadard JD9365TX in-cell touchscreen driver Hefei
2026-11-25  2:21   ` sashiko-bot [this message]
2026-11-25  2:09 ` [PATCH v2 6/6] backlight: add VIEWE I2C backlight driver Hefei
2026-11-25  2:19   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-232404@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=3066883572@qq.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-input@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox