From: sashiko-bot@kernel.org
To: "Aibing Chen" <chenaibing@cmss.chinamobile.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH] Input: ili210x - avoid shifting 16-bit values by 16
Date: Sun, 29 Nov 2026 07:43:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-239398@kernel.org> (raw)
In-Reply-To: <20261129073249.1622-1-chenaibing@cmss.chinamobile.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] Input: ili210x: cast in ili251x_firmware_write_to_ic() masks
u16 truncation
--
commit 12e32c49e61acbe5a3e1b7031ca4d42394cc1e4b
Author: Aibing Chen <chenaibing@cmss.chinamobile.com>
Input: ili210x - avoid shifting 16-bit values by 16
This commit casts 16-bit end and crc values to unsigned int before right
shifting them by 16 in ili251x_firmware_write_to_ic() to silence a Smatch
warning.
> diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
> index 03e4451d6393c..94e6db4d91764 100644
> --- a/drivers/input/touchscreen/ili210x.c
> +++ b/drivers/input/touchscreen/ili210x.c
> @@ -716,8 +716,10 @@ static int ili251x_firmware_write_to_ic(struct device *dev, const u8 *fwbuf,
> /* Unlock write to either AC (application) or DF (dataflash) area */
> u8 cmd_wr[10] = {
> REG_WRITE_ENABLE, 0x5a, 0xa5, dataflash,
> - (end >> 16) & 0xff, (end >> 8) & 0xff, end & 0xff,
> - (crc >> 16) & 0xff, (crc >> 8) & 0xff, crc & 0xff
> + ((unsigned int)end >> 16) & 0xff,
> + (end >> 8) & 0xff, end & 0xff,
> + ((unsigned int)crc >> 16) & 0xff,
> + (crc >> 8) & 0xff, crc & 0xff
> };
[Severity: Medium]
Does casting end and crc to unsigned int here just mask the narrow u16
types with an expression that still unconditionally evaluates to 0?
In C, u16 operands are already integer-promoted to 32-bit int before >> is
evaluated, so shifting by 16 is not undefined behavior; Smatch warns
because shifting a 16-bit variable right by 16 always yields 0.
For crc, crc_ccitt() returns a 16-bit CRC-CCITT value, so the upper byte
in cmd_wr is just a constant 0. For end, cmd_wr sends a 3-byte address
and ili251x_firmware_to_buffer() explicitly allows the final 32-byte block
at 0xffe0 to reach SZ_64K (0x10000):
drivers/input/touchscreen/ili210x.c:ili251x_firmware_to_buffer() {
...
/* The last 32 Byte firmware block can be 0xffe0 */
if (fw_addr + fw_len > SZ_64K || fw_addr > SZ_64K - 32)
return ERR_PTR(-EFBIG);
...
}
Because end (along with df_end, ac_end, start, and fw_addr) is typed as
u16 rather than u32, an end address of 0x10000 is already truncated to 0
before reaching ili251x_firmware_write_to_ic(), and
((unsigned int)end >> 16) & 0xff still always produces 0.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129073249.1622-1-chenaibing@cmss.chinamobile.com?part=1
prev parent reply other threads:[~2026-11-29 7:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 7:32 [PATCH] Input: ili210x - avoid shifting 16-bit values by 16 Aibing Chen
2026-11-29 7:43 ` 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-239398@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=chenaibing@cmss.chinamobile.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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