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 7/7] Input: novatek-nvt-ts - add no-flash firmware download
Date: Wed, 02 Dec 2026 01:18:17 +0000 [thread overview]
Message-ID: <sashiko-outbox-244596@kernel.org> (raw)
In-Reply-To: <20261202010542.2508257-7-xiaqinghuan@mail.ustc.edu.cn>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] Input: novatek-nvt-ts - wrong descriptor offsets in
nvt_ts_fw_parse()
- [High] Input: novatek-nvt-ts - DMA from stack in nvt_ts_spi_write()
callers
- [Medium] Input: novatek-nvt-ts - unbalanced disable in nvt_ts_stop()
after resume
- [Low] Input: novatek-nvt-ts - use __free() in firmware upload helpers
--
commit e236976afca44670bc57ab40318b3d9300e8ddbd
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
Input: novatek-nvt-ts - add no-flash firmware download
This commit adds optional SRAM firmware download support for Novatek
touchscreen controllers without on-board flash, and implements the SPI bus
write callback.
> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
> index f67170474c76e..104028ea654c8 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
[ ... ]
> @@ -158,6 +166,505 @@ static irqreturn_t nvt_ts_irq(int irq, void *dev_id)
> return IRQ_HANDLED;
> }
>
> +/*
> + * NT36xxx firmware download
[ ... ]
> +/*
> + * The image starts with a header that ends at the file offset stored in its
> + * first word, followed by the second header of a cascade pair. The end of the
> + * first header is marked by the only descriptor with a non-zero destination
> + * and a zero length.
> + */
> +static int nvt_ts_fw_parse(const struct firmware *fw,
> + struct nvt_ts_fw_partition *partitions,
> + unsigned int *num_partitions, bool *cascade)
> +{
[ ... ]
> + limit = header_end;
> + for (pos = 0x30; pos <= header_end - 0x10; pos += 0x10) {
> + if (get_unaligned_le32(data + pos + 4) &&
> + !get_unaligned_le32(data + pos + 8)) {
> + limit = pos + 0x10;
> + break;
> + }
> + }
> + if (*cascade && limit > header_end / 2)
> + return -EINVAL;
> +
> + for (i = 0; i < 2; i++) {
> + pos = i * 12;
> + file_offs = get_unaligned_le32(data + pos);
> + sram_addr = get_unaligned_le32(data + pos + 4);
> + size = get_unaligned_le32(data + pos + 8);
> + crc = get_unaligned_le32(data + 0x18 + i * 4);
> + if (!size)
> + return -EINVAL;
> +
> + error = nvt_ts_fw_add_partition(fw, partitions, num_partitions,
> + file_offs, sram_addr, size, crc);
> + if (error)
> + return error;
> + }
> +
> + for (pos = 0x30; pos <= limit - 0x10; pos += 0x10) {
> + sram_addr = get_unaligned_le32(data + pos);
> + size = get_unaligned_le32(data + pos + 4);
> + file_offs = get_unaligned_le32(data + pos + 8);
> + crc = get_unaligned_le32(data + pos + 12);
[Severity: High]
Does the sentinel search loop check the wrong offsets for the 16-byte
descriptors starting at 0x30?
Unlike the two 12-byte descriptors at 0x00 and 0x0c, the descriptors at
0x30+ store sram_addr at pos + 0, size at pos + 4, and file_offs at pos + 8.
Checking pos + 4 and pos + 8 tests size != 0 && file_offs == 0 instead of
sram_addr != 0 && size == 0, so a sentinel descriptor with size == 0 never
matches. That leaves limit at header_end and causes all cascade firmware
images to fail the limit > header_end / 2 check with -EINVAL.
[ ... ]
> +static int nvt_ts_fw_upload(struct nvt_ts_data *data,
> + const struct firmware *fw)
> +{
> + struct nvt_ts_fw_partition partitions[NVT_TS_FW_MAX_PARTITIONS] = {};
> + unsigned int num_partitions, i;
> + u8 reset_done[7] = { NVT_TS_FW_EVENT_RESET_DONE | BIT(7) };
> + u8 host_cmd[] = { NVT_TS_FW_EVENT_HOST_CMD | BIT(7), 0xae, 0 };
> + u8 *xfer;
> + bool cascade;
> + int error;
> +
> + error = nvt_ts_fw_parse(fw, partitions, &num_partitions, &cascade);
> + if (error)
> + return error;
> +
> + xfer = kmalloc(NVT_TS_FW_XFER_LEN + 1, GFP_KERNEL);
> + if (!xfer)
> + return -ENOMEM;
[ ... ]
> +out_free:
> + kfree(xfer);
> +
> + return error;
> +}
> +
> +static int nvt_ts_load_firmware(struct nvt_ts_data *data)
> +{
> + const struct firmware *fw;
> + int error;
> +
> + if (!data->firmware_name)
> + return 0;
> +
> + error = request_firmware(&fw, data->firmware_name, data->dev);
> + if (error) {
> + dev_err(data->dev, "failed to load %s: %d\n",
> + data->firmware_name, error);
> + return error;
> + }
> +
> + error = nvt_ts_fw_upload(data, fw);
> +
> + release_firmware(fw);
> +
> + return error;
> +}
[Severity: Low]
This isn't a bug, but declaring xfer with __free(kfree) in
nvt_ts_fw_upload() and fw with __free(firmware) = NULL in
nvt_ts_load_firmware() would drop the out_free label and manual
release_firmware() call.
> +
> static int nvt_ts_start(struct input_dev *dev)
> {
> struct nvt_ts_data *data = input_get_drvdata(dev);
> @@ -169,9 +676,23 @@ static int nvt_ts_start(struct input_dev *dev)
> return error;
> }
>
> - enable_irq(data->irq);
> gpiod_set_value_cansleep(data->reset_gpio, 0);
>
> + /*
> + * A controller without on-board flash only starts reporting touches
> + * once its firmware has been uploaded, and it loses the firmware when
> + * it is powered down again.
> + */
> + error = nvt_ts_load_firmware(data);
> + if (error) {
> + gpiod_set_value_cansleep(data->reset_gpio, 1);
> + regulator_bulk_disable(ARRAY_SIZE(data->regulators),
> + data->regulators);
> + return error;
> + }
> +
> + enable_irq(data->irq);
> +
> return 0;
> }
[Severity: Medium]
Can a firmware load failure during nvt_ts_resume() cause an unbalanced
disable_irq() and regulator_bulk_disable() when nvt_ts_stop() runs later?
If the input device is open across suspend and resume, nvt_ts_suspend()
calls nvt_ts_stop(), disabling data->irq and data->regulators. If
nvt_ts_load_firmware() then fails in nvt_ts_resume() -> nvt_ts_start(),
nvt_ts_start() disables the regulators again and returns without calling
enable_irq(). Because input_device_enabled(data->input) remains true, the
next close or suspend calls nvt_ts_stop(), which disables the already
disabled regulators and increments the IRQ disable depth a second time so a
later open cannot re-enable the IRQ.
> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-spi.c b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
> index a5939337f9fb3..9039b685f7a07 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts-spi.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
> @@ -28,8 +28,17 @@ static int nvt_ts_spi_read(struct nvt_ts_data *data, u8 reg, u8 *buf,
> return spi_write_then_read(spi, cmd, sizeof(cmd), buf, count);
> }
>
> +static int nvt_ts_spi_write(struct nvt_ts_data *data, const u8 *buf,
> + size_t count)
> +{
> + struct spi_device *spi = to_spi_device(data->dev);
> +
> + return spi_write(spi, buf, count);
> +}
[Severity: High]
Does calling spi_write() here perform DMA directly from the stack?
Unlike spi_write_then_read() in nvt_ts_spi_read(), spi_write() does not
bounce tx_buf and requires a DMA-safe buffer. However,
nvt_ts_fw_set_page(), nvt_ts_fw_write_byte(), nvt_ts_fw_write_value(),
nvt_ts_fw_identify(), and nvt_ts_fw_upload() all pass stack-allocated arrays
to nvt_ts_write_data(), which triggers DMA-from-stack warnings and can fail
or corrupt transfers on controllers that use DMA with vmap stacks.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202010542.2508257-1-xiaqinghuan@mail.ustc.edu.cn?part=7
prev parent reply other threads:[~2026-12-02 1:18 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
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 [this message]
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-244596@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.