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 7/7] Input: novatek-nvt-ts - add no-flash firmware download
Date: Wed, 02 Dec 2026 00:53:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-244549@kernel.org> (raw)
In-Reply-To: <20261202003159.1321846-7-xiaqinghuan@mail.ustc.edu.cn>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] Input: novatek-nvt-ts - DMA from stack in nvt_ts_spi_write()
  callers
- [Medium] Input: novatek-nvt-ts - unbalanced IRQ/regulators if
  nvt_ts_start() fails
--

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

Input: novatek-nvt-ts - add no-flash firmware download

This commit adds firmware download support for flashless Novatek
touchscreen controllers, uploading partitioned firmware images to SRAM
when the controller powers up.

> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
> index 4303d0901c91d..4d374235b2bfb 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
[ ... ]
> @@ -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 failure in nvt_ts_load_firmware() during nvt_ts_resume() unbalance
data->irq and data->regulators?

When the device is open, nvt_ts_suspend() calls nvt_ts_stop() to disable
the IRQ and regulators, and nvt_ts_resume() calls nvt_ts_start():

drivers/input/touchscreen/novatek-nvt-ts-core.c:nvt_ts_stop() {
	disable_irq(data->irq);
	gpiod_set_value_cansleep(data->reset_gpio, 1);
	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
}

If nvt_ts_load_firmware() fails on resume, nvt_ts_start() disables the
regulators and returns before calling enable_irq(data->irq), while
input_device_enabled(data->input) remains true.  When the input device is
later closed or suspended again, nvt_ts_stop() runs a second time,
calling regulator_bulk_disable() on already-disabled regulators and
incrementing the IRQ disable depth to 2 so future opens can no longer
re-enable data->irq.

[ ... ]

> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-spi.c b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
> index c7b36e29cb983..5b878695f5ac7 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 nvt_ts_spi_write() pass stack-allocated buffers directly to
spi_write()?

Unlike spi_write_then_read() in nvt_ts_spi_read(), spi_write() does not
bounce tx_buf and requires DMA-safe memory.  Callers in the firmware
loader such as nvt_ts_fw_set_page(), nvt_ts_fw_write_byte(),
nvt_ts_fw_write_value(), nvt_ts_fw_identify() and nvt_ts_fw_upload() pass
stack arrays (buf, trim, reset_done and host_cmd) to nvt_ts_write_data(),
which will fail DMA mapping with VMAP_STACK or corrupt stack memory on
SPI controllers that use DMA.

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

      reply	other threads:[~2026-12-02  0:53 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
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 [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-244549@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.