From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796174298; b=iHBbVHkZ3EYgDWBn3mMg+rENacsqpHdnc62LvgAGUYi8yugRv3LMM9Nn/I6Fcc6Oa6fu j1k3sNRvW53QvXMLgg4zb5sCngjSj0L3VJE6OVCCENuVIhtcW2Ln3ebUC1K+8a2M1SCFj 8jXXDLjQx63eNh6RZmOldi49YWs3INW8oPfOD2fti9/LZEMqxejyfgKbAp/hUecxmBGUt NLWg/OUOaHcvrIWGH7VbiSFAYOyjM5rokQsv+GsyVGpjyVjCEFe5LFoMBpT2rOk++LUoJ QwQ/zd+kA0kM5O/6JZmp3LMtbjUD3BJGu4mxSLOP1PKVizHytbYY6tferuAHZ3PURtw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796174298; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=kcIToOp3dus32yQfFSFsLg77tmsq0ayoQp1IOqJoWWc=; b=h8PiPtUswSrwVQww43EAu1X91a2qYkC/hCMbtgj/SmpOBibei8eaDKSt8CoBq5rRYlkO SJqzbohDt6MDxdeQqMZYudwDMXu6Ht6WEP8MBM8sljP00KapL8JuWOCnHfzGN2dvB6MgF Rdt9DqLS1pLwfVenNq7TjQrFB6fhL8/HIUl1zfpyH82d33zyZ4fBggkelOG59fNqYkq64 JakydYed95aIHSYXwbE30UZNp5QKP0f5s1D1HNjK7MjbS9tvWxLnacaqoUMKF+rkiZK4f MnWVutcjWFMxLTKRdV0rL6Dc6Q7PRjMTMPAZyxTMXa/IsOD4mhsybdu3IdAb/2U4sjw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PX66rTHq; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C7B6606A323; Wed, 2 Dec 2026 01:18:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PX66rTHq Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63ADF1F0089F; Wed, 2 Dec 2026 01:18:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796174297; bh=kcIToOp3dus32yQfFSFsLg77tmsq0ayoQp1IOqJoWWc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=PX66rTHqAtMcaaEP0k6PD0n6MKwabM6Aur8R+cfttSxUXb4a40quatplAh++0O7z/ j06i8AU3OqBicomoAq/uqWyd5v0wKxdq35DxnBaF9ODxNd1hdhdMfvaFF1W2mKrXO5 pkHLCawTImN4uqTcGJu4eFbtt1O8Z+j/N7ZNEMAQGlV2zqE5woSS6bBQsKrwQeHN0g 9My/IfHPMGBYkTa/1QgaHtvcHwQld/iS0hAJBLx3PIhvLKlIlaD6Pa5CtNgX+eiLUU 53nZlnBHof6Ntt9pwtZgPKrCNIqOzVuO30J2P3SUFJA1iWOmk9w0PPhzGnFM1FDgzI 7ch5q5o5EGzrg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 7/7] Input: novatek-nvt-ts - add no-flash firmware download Reply-To: sashiko-reviews@lists.linux.dev To: "Qianhui Xu" Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <20261202010542.2508257-7-xiaqinghuan@mail.ustc.edu.cn> References: <20261202010542.2508257-1-xiaqinghuan@mail.ustc.edu.cn> <20261202010542.2508257-7-xiaqinghuan@mail.ustc.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 01:18:17 +0000 X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/in= put/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; > } > =20 > +/* > + * 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 destina= tion > + * 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 =3D header_end; > + for (pos =3D 0x30; pos <=3D header_end - 0x10; pos +=3D 0x10) { > + if (get_unaligned_le32(data + pos + 4) && > + !get_unaligned_le32(data + pos + 8)) { > + limit =3D pos + 0x10; > + break; > + } > + } > + if (*cascade && limit > header_end / 2) > + return -EINVAL; > + > + for (i =3D 0; i < 2; i++) { > + pos =3D i * 12; > + file_offs =3D get_unaligned_le32(data + pos); > + sram_addr =3D get_unaligned_le32(data + pos + 4); > + size =3D get_unaligned_le32(data + pos + 8); > + crc =3D get_unaligned_le32(data + 0x18 + i * 4); > + if (!size) > + return -EINVAL; > + > + error =3D nvt_ts_fw_add_partition(fw, partitions, num_partitions, > + file_offs, sram_addr, size, crc); > + if (error) > + return error; > + } > + > + for (pos =3D 0x30; pos <=3D limit - 0x10; pos +=3D 0x10) { > + sram_addr =3D get_unaligned_le32(data + pos); > + size =3D get_unaligned_le32(data + pos + 4); > + file_offs =3D get_unaligned_le32(data + pos + 8); > + crc =3D 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 !=3D 0 && file_offs =3D=3D 0 instea= d of sram_addr !=3D 0 && size =3D=3D 0, so a sentinel descriptor with size =3D= =3D 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] =3D {}; > + unsigned int num_partitions, i; > + u8 reset_done[7] =3D { NVT_TS_FW_EVENT_RESET_DONE | BIT(7) }; > + u8 host_cmd[] =3D { NVT_TS_FW_EVENT_HOST_CMD | BIT(7), 0xae, 0 }; > + u8 *xfer; > + bool cascade; > + int error; > + > + error =3D nvt_ts_fw_parse(fw, partitions, &num_partitions, &cascade); > + if (error) > + return error; > + > + xfer =3D 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 =3D 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 =3D 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) =3D 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 =3D input_get_drvdata(dev); > @@ -169,9 +676,23 @@ static int nvt_ts_start(struct input_dev *dev) > return error; > } > =20 > - enable_irq(data->irq); > gpiod_set_value_cansleep(data->reset_gpio, 0); > =20 > + /* > + * 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 =3D 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/inp= ut/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, u= 8 reg, u8 *buf, > return spi_write_then_read(spi, cmd, sizeof(cmd), buf, count); > } > =20 > +static int nvt_ts_spi_write(struct nvt_ts_data *data, const u8 *buf, > + size_t count) > +{ > + struct spi_device *spi =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202010542.2508= 257-1-xiaqinghuan@mail.ustc.edu.cn?part=3D7