All of lore.kernel.org
 help / color / mirror / Atom feed
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 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding
Date: Wed, 02 Dec 2026 00:46:47 +0000	[thread overview]
Message-ID: <sashiko-outbox-244532@kernel.org> (raw)
In-Reply-To: <20261202003159.1321846-5-xiaqinghuan@mail.ustc.edu.cn>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] Input: novatek-nvt-ts - broken X/Y axis setup in nvt_ts_probe()
- [High] Input: novatek-nvt-ts - missing dev_set_drvdata() in
  nvt_ts_probe()
- [Medium] Input: novatek-nvt-ts - missing ABS_MT_TOUCH_MAJOR setup in
  nvt_ts_probe()
--

commit 629485efc8c5bb9921461a8d9bf9ca2e03a38ccb
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

Input: novatek-nvt-ts - add NT36536 packet decoding

This commit adds a per-chip touch report callback, implements the NT36xxx
packet decoding and checksum verification, makes reading the parameter
block conditional on chip_id, and registers 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 227dc7eaed929..4303d0901c91d 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
[ ... ]
> +/*
> + * 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];
> +		u8 state = FIELD_GET(NVT_TS_TOUCH_TYPE_MASK, touch[0]);
> +		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]
Does nvt_ts_probe() need to register ABS_MT_TOUCH_MAJOR with
input_set_abs_params()?  Without that, ABS_MT_TOUCH_MAJOR is not set in
data->input->absbit and the input core silently drops every contact width
event reported here.

[ ... ]

> @@ -159,6 +234,7 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
>  
>  	data->dev = dev;
>  	data->bus_ops = bus_ops;
> +	data->chip = chip;
>  	data->irq = irq;

[Severity: High]
Should nvt_ts_probe() call dev_set_drvdata(dev, data) here?

Only input_set_drvdata(input, data) is called later in nvt_ts_probe(),
which sets driver_data on input->dev rather than on the bus device dev.
When the system suspends or resumes, nvt_ts_suspend() and nvt_ts_resume()
call dev_get_drvdata(dev), get NULL, and dereference it at
&data->input->mutex.

[ ... ]

> @@ -225,9 +320,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 skipping input_set_abs_params() before touchscreen_parse_properties()
leave ABS_MT_POSITION_X and ABS_MT_POSITION_Y unset when width and height
are 0?

touchscreen_parse_properties() calls touchscreen_set_params(), which
requires the axis bit to already be set in dev->absbit:

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

For chips without a parameter block (such as NT36536), width and height
are 0, so touchscreen_set_params() warns and returns early without
configuring the axes, leaving data->prop.max_x and data->prop.max_y at 0.
The subsequent input_set_abs_params() calls then configure the X and Y
maximums as -1.  In addition, when touchscreen_parse_properties() succeeds
it already sets the axis maximums (and any minimum, fuzz, resolution, or
axis swap from DT), so calling input_set_abs_params() afterwards with
data->prop.max_x - 1 would subtract 1 a second time and overwrite those
properties; registering the capabilities with input_set_capability()
before touchscreen_parse_properties() avoids both issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202003159.1321846-1-xiaqinghuan@mail.ustc.edu.cn?part=5

  reply	other threads:[~2026-12-02  0:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  0:31 [PATCH 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
2026-12-02  0:31 ` [PATCH 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
2026-12-02  0:38   ` sashiko-bot
2026-12-02  0:31 ` [PATCH 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
2026-12-02  0:44   ` sashiko-bot
2026-12-02  0:31 ` [PATCH 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring Qianhui Xu
2026-12-02  0:31 ` [PATCH 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
2026-12-02  0:46   ` sashiko-bot [this message]
2026-12-02  0:31 ` [PATCH 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible Qianhui Xu
2026-12-02  0:31 ` [PATCH 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
2026-12-02  0:53   ` 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-244532@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.