From: sashiko-bot@kernel.org
To: "Qianhui Xu" <xiaqinghuan@mail.ustc.edu.cn>
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/7] Input: novatek-nvt-ts - add NT36536 packet decoding
Date: Wed, 02 Dec 2026 01:19:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-244599@kernel.org> (raw)
In-Reply-To: <20261202010542.2508257-5-xiaqinghuan@mail.ustc.edu.cn>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] Input: novatek-nvt-ts - broken X/Y axis setup in nvt_ts_probe()
when chip_id is 0
- [High] Input: novatek-nvt-ts - missing linux/bitfield.h include in
novatek-nvt-ts-core.c
- [High] Input: novatek-nvt-ts: off-by-one payload offset in
nvt_ts_report_nt36xxx()
- [Medium] Input: novatek-nvt-ts - unregistered ABS_MT_TOUCH_MAJOR axis
in nvt_ts_probe()
--
commit 2354ad35fa28bbbffb01b63befc83c37b13ef941
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
Input: novatek-nvt-ts - add NT36536 packet decoding
This commit adds a per-chip touch reporting callback, implements NT36xxx
packet decoding with checksum validation, skips reading the parameter block
when chip_id is 0, and adds SPI match entries for NT36536.
> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
> index 747fa8bbe3157..f67170474c76e 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
[ ... ]
> @@ -81,6 +85,76 @@ static irqreturn_t nvt_ts_irq(int irq, void *dev_id)
> input_mt_sync_frame(data->input);
> input_sync(data->input);
>
> + return 0;
> +}
> +
> +/*
> + * NT36xxx checksum: the byte at NVT_TS_NT36XXX_CHECKSUM is the two's
> + * complement of the sum of the first 64 payload bytes.
> + */
> +static bool nvt_ts_nt36xxx_checksum_ok(const u8 *buf)
> +{
> + u8 sum = 0;
> + int i;
> +
> + for (i = 1; i < NVT_TS_NT36XXX_CHECKSUM; i++)
> + sum += buf[i];
> +
> + return (u8)(~sum + 1) == buf[NVT_TS_NT36XXX_CHECKSUM];
> +}
> +
> +/*
> + * NT36xxx packet: 108 bytes of payload plus a checksum, records start at
> + * offset 1, coordinates are 16 bit big endian and b[5] carries the width.
> + */
> +static int nvt_ts_report_nt36xxx(struct nvt_ts_data *data)
> +{
> + struct device *dev = data->dev;
> + int i, error;
> +
> + error = nvt_ts_read_data(data, NVT_TS_TOUCH_START, data->buf,
> + NVT_TS_NT36XXX_PACKET_SIZE);
> + if (error)
> + return error;
> +
> + if (!nvt_ts_nt36xxx_checksum_ok(data->buf)) {
> + dev_dbg(dev, "bad touch packet checksum\n");
> + return -EIO;
> + }
> +
> + for (i = 0; i < data->max_touches; i++) {
> + const u8 *touch = &data->buf[1 + i * NVT_TS_TOUCH_SIZE];
[Severity: High]
Are the checksum and touch record offsets in data->buf off by one byte?
nvt_ts_spi_read() already sends the register address and dummy byte in a
separate two-byte cmd buffer via spi_write_then_read() before reading the
response into buf:
drivers/input/touchscreen/novatek-nvt-ts-spi.c:nvt_ts_spi_read() {
...
u8 cmd[2] = { reg & 0x7f, 0 };
return spi_write_then_read(spi, cmd, sizeof(cmd), buf, count);
}
The first payload byte therefore lands at data->buf[0] rather than
data->buf[1] (matching nvt_ts_report_nt11205()). Starting the checksum
loop and record decoding at index 1 skips the first byte of record 0, folds
the checksum byte at data->buf[64] into sum, compares against data->buf[65],
and shifts every touch record by one byte.
> + u8 state = FIELD_GET(NVT_TS_TOUCH_TYPE_MASK, touch[0]);
[Severity: High]
Does using FIELD_GET() here require including <linux/bitfield.h>? Neither
novatek-nvt-ts-core.c nor novatek-nvt-ts.h includes it, which breaks the
build on architectures such as x86_64 that do not pull it in transitively.
> + unsigned int id = (touch[0] >> NVT_TS_TOUCH_SLOT_SHIFT) - 1;
> + unsigned int x, y, width;
> +
> + if (state != NVT_TS_TOUCH_NEW && state != NVT_TS_TOUCH_UPDATE)
> + continue;
> + if (id >= data->max_touches)
> + continue;
> +
> + x = get_unaligned_be16(&touch[1]);
> + y = get_unaligned_be16(&touch[3]);
> + width = touch[5] ?: 1;
> +
> + input_mt_slot(data->input, id);
> + input_mt_report_slot_state(data->input, MT_TOOL_FINGER, true);
> + touchscreen_report_pos(data->input, &data->prop, x, y, true);
> + input_report_abs(data->input, ABS_MT_TOUCH_MAJOR, width);
[Severity: Medium]
Are these ABS_MT_TOUCH_MAJOR events dropped by the input core?
nvt_ts_probe() never registers ABS_MT_TOUCH_MAJOR via
input_set_abs_params(), so the bit is not set in input->absbit and
input_get_disposition() ignores every reported width value.
[ ... ]
> @@ -223,9 +318,17 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
> input->open = nvt_ts_start;
> input->close = nvt_ts_stop;
>
> - input_set_abs_params(input, ABS_MT_POSITION_X, 0, width - 1, 0, 0);
> - input_set_abs_params(input, ABS_MT_POSITION_Y, 0, height - 1, 0, 0);
> + if (width)
> + input_set_abs_params(input, ABS_MT_POSITION_X, 0, width - 1, 0, 0);
> + if (height)
> + input_set_abs_params(input, ABS_MT_POSITION_Y, 0, height - 1, 0, 0);
> touchscreen_parse_properties(input, true, &data->prop);
> + if (!width)
> + input_set_abs_params(input, ABS_MT_POSITION_X, 0,
> + data->prop.max_x - 1, 0, 0);
> + if (!height)
> + input_set_abs_params(input, ABS_MT_POSITION_Y, 0,
> + data->prop.max_y - 1, 0, 0);
[Severity: High]
Does touchscreen_parse_properties() reject the DT geometry when chip_id is 0
(so width and height are 0)?
Inside touchscreen_parse_properties(), touchscreen_set_params() checks that
the axis bit is already set in dev->absbit before applying properties:
drivers/input/touchscreen.c:touchscreen_set_params() {
if (!test_bit(axis, dev->absbit)) {
dev_warn(&dev->dev,
"Parameters are specified but the axis %lu is not set up\n",
axis);
return;
}
...
}
Because ABS_MT_POSITION_X and ABS_MT_POSITION_Y are not enabled before
touchscreen_parse_properties(), it warns and leaves data->prop.max_x and
data->prop.max_y at 0, and the subsequent input_set_abs_params() calls set
the maximum X and Y coordinates to -1. In addition, when the axes are set
up beforehand (for example with input_set_capability(input, EV_ABS, ...)),
touchscreen_parse_properties() already configures input->absinfo with
size - 1, fuzz, resolution and axis swapping, so calling
input_set_abs_params() afterwards with data->prop.max_x - 1 would subtract 1
a second time and overwrite those properties.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202010542.2508257-1-xiaqinghuan@mail.ustc.edu.cn?part=5
next prev parent reply other threads:[~2026-12-02 1:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 1:05 [PATCH v2 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
2026-12-02 1:19 ` sashiko-bot [this message]
2026-12-02 1:05 ` [PATCH v2 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible Qianhui Xu
2026-12-02 1:15 ` sashiko-bot
2026-12-02 1:05 ` [PATCH v2 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
2026-12-02 1:18 ` 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-244599@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xiaqinghuan@mail.ustc.edu.cn \
/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