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 v3 5/6] Input: add Jadard JD9365TX in-cell touchscreen driver
Date: Wed, 25 Nov 2026 02:24:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-232407@kernel.org> (raw)
In-Reply-To: <tencent_03FEA6A02E8E137CCC5AC97E6F118A3CC10A@qq.com>

Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [High] Input: jadard_jd9365tx: broken slot check in
  jd_report_touches()
- [High] Input: jadard_jd9365tx: deferred init in jd_poll() and no reset
  recovery
- [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: redundant capabilities, BTN_TOUCH, and
  parent setup
- [Low] Input: jadard_jd9365tx: positional initializer in jadard_tp_id
  table
- [Low] Input: jadard_jd9365tx: empty commit message body for new driver
--

commit 7d4899901ebf2b5cd58796c8a16ba3f15ed92ab7
Author: Hefei <3066883572@qq.com>

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

[Severity: Low]
This commit adds a new touchscreen driver with an empty commit message
body.  Please add a description of the Jadard JD9365TX hardware and explain
why the driver uses I2C polling and defers hardware initialization.

> 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
> @@ -0,0 +1,373 @@

[ ... ]

> +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 shifting buf[JD_ESRAM_COORD_IDX * 8 + 3] and
buf[JD_ESRAM_COORD_IDX * 8 + 7] left by 24 bits overflow a 32-bit signed
int?  In C, u8 values are promoted to signed int before << 24, which
triggers undefined behavior under UBSAN when bit 7 of the high byte is set.
Using get_unaligned_le32() avoids this.

> +
> +	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 jd_report_touches() read uninitialized stack memory from buf[] when
jd_resolve_coord_addr() accepts a section length smaller than 53 bytes?

jd_resolve_coord_addr() accepts any len from 1 to JD_TOUCH_DATA_SIZE (78),
and jd_poll() declares u8 buf[JD_TOUCH_DATA_SIZE] uninitialized on the
stack before reading ts->touch_data_size bytes into it.  However,
jd_report_touches() unconditionally reads JD_TOUCH_COORD_INFO_ADDR +
ts->max_points * JD_FINGER_DATA_SIZE (53) bytes from buf[], reporting
uninitialized stack bytes as touch coordinates whenever len < 53.  The
bounds check also does not verify that addr + len stays within
JD_ERAM_BASE + 0x1000.

[ ... ]

> +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 contacts whenever a
lower-numbered slot lifts before a higher-numbered slot?

The packet uses fixed slots where inactive slots carry 0xFFFF/0xFFFF and
finger_num is the total active contact count.  If fingers are down in slots
0 and 1 (finger_num == 2) and finger 0 lifts while finger 1 stays on the
screen, finger_num becomes 1 while slot 1 retains its coordinates; on the
next poll, slot 1 (i == 1) fails i < finger_num and is reported as
released.  In addition, clamping finger_num > ts->max_points to
ts->max_points instead of discarding the packet treats an invalid 0xFF
header byte as 10 active fingers.

> +
> +		input_mt_slot(ts->input, i);
> +		input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, down);
> +
> +		if (down) {
> +			touchscreen_report_pos(ts->input, &ts->prop, x, y, true);
> +			input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, w);
> +			any = true;
> +		}
> +	}
> +
> +	input_mt_sync_frame(ts->input);
> +	input_report_key(ts->input, BTN_TOUCH, any);
> +	input_sync(ts->input);
> +}
> +
> +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;
> +	}
> +
> +	ret = jd_read_reg(ts->client, ts->coord_addr, buf, ts->touch_data_size);
> +	if (!ret)
> +		jd_report_touches(ts, buf);
> +}

[Severity: High]
Does deferring jd_hw_init() to jd_poll() break probe detection, block the
poller workqueue, and leave the touchscreen unable to recover after panel
or system resets?

Because jadard_tp_probe() registers the input device without checking
hardware presence, an absent device or chip ID mismatch (-ENODEV) still
binds, keeps vdd and iovcc enabled, and retries jd_hw_init() every 16 ms
while the device is open.  Inside jd_hw_init(), jd_section_ready() loops up
to 50 times calling msleep(2) and jd_read_reg(), blocking
input_open_device() (under input->mutex) or system_freezable_wq for
hundreds of milliseconds.  Once ts->ready is set to true, it is never
cleared on read failures or across suspend/resume, so any reset or power
cycle of the shared JD9365TX controller drops the 0xF2 I2C backdoor mode
and causes subsequent touch reads to fail permanently.

> +
> +static void jadard_tp_disable_regulators(void *data)
> +{
> +	struct jadard_tp *ts = data;
> +
> +	regulator_disable(ts->iovcc);
> +	regulator_disable(ts->vdd);
> +}
> +
> +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]
Does jadard_tp_probe() leave the controller held in reset on boards that
wire reset-gpios to the touchscreen node?  The jadard,jd9365tx DT binding
defines reset-gpios, but jadard_tp_probe() never requests or deasserts it
after enabling vdd and iovcc.

> +
> +	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() into ts->abs_x_max and ts->abs_y_max when
touchscreen_parse_properties() is called right below?
touchscreen_parse_properties() already parses these via the generic device
property API and stores the pre-swap axis maxima in ts->prop.max_x and
ts->prop.max_y; if properties come from non-OF firmware nodes or
touchscreen-min-x/y is used, ts->abs_x_max and ts->abs_y_max stay at
719x1279 and jd_report_touches() drops coordinates above those defaults.

> +
> +	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);
> +}

[Severity: Low]
This isn't a bug, but several parts of jadard_tp_probe() and
jd_report_touches() duplicate work already done by the input and regulator
helpers:
- devm_input_allocate_device(dev) already sets input->dev.parent = dev.
- input_set_abs_params() and input_mt_init_slots(..., INPUT_MT_DIRECT)
  already set EV_ABS, EV_KEY, and BTN_TOUCH, so the raw __set_bit() calls
  are redundant.
- input_mt_sync_frame() with INPUT_MT_DIRECT already reports BTN_TOUCH via
  pointer emulation, so input_report_key(ts->input, BTN_TOUCH, any) in
  jd_report_touches() is redundant.
- vdd and iovcc can be managed with devm_regulator_bulk_get_enable()
  instead of manual regulator_enable() calls and
  jadard_tp_disable_regulators().
- Per input subsystem style, please name the error status variable error
  and check the return value of input_register_device() before explicitly
  returning 0.

> +
> +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 new struct i2c_device_id entries should use named
initializers ({ .name = "jd9365tx" }).

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

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

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261125021127.1430-1-3066883572@qq.com>
2026-11-25  2:11 ` [PATCH v3 1/6] dt-bindings: display: add VIEWE JD9365TX panel binding Hefei
2026-11-25  2:18   ` sashiko-bot
2026-11-25  2:11 ` [PATCH v3 2/6] dt-bindings: input: add Jadard JD9365TX touchscreen binding Hefei
2026-11-25  2:22   ` sashiko-bot
2026-11-25  2:11 ` [PATCH v3 3/6] dt-bindings: backlight: add VIEWE I2C backlight binding Hefei
2026-11-25  2:19   ` sashiko-bot
2026-11-25  2:11 ` [PATCH v3 4/6] drm/panel: add VIEWE JD9365TX 7 inch DSI panel Hefei
2026-11-25  2:26   ` sashiko-bot
2026-11-25  2:11 ` [PATCH v3 5/6] Input: add Jadard JD9365TX in-cell touchscreen driver Hefei
2026-11-25  2:24   ` sashiko-bot [this message]
2026-11-25  2:32   ` Dmitry Torokhov
2026-11-25  2:11 ` [PATCH v3 6/6] backlight: add VIEWE I2C backlight driver Hefei
2026-11-25  2:22   ` 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-232407@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