* [PATCH] Input: ili210x - avoid shifting 16-bit values by 16
@ 2026-11-29 7:32 Aibing Chen
2026-11-29 7:43 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Aibing Chen @ 2026-11-29 7:32 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-input, linux-kernel
ili251x_firmware_write_to_ic() builds the write command with the upper
byte of the 16-bit address and CRC:
(end >> 16) & 0xff, ...
(crc >> 16) & 0xff, ...
Shifting a 16-bit value by its own width is undefined behavior, and
smatch has been reporting it since the firmware update support was
added:
drivers/input/touchscreen/ili210x.c:719 ili251x_firmware_write_to_ic()
warn: right shifting more than type allows 16 vs 16
Both values are 16-bit, so the upper byte is always zero, but the shift
itself has to be defined. Promote the values to unsigned int before
shifting them, which keeps the emitted command unchanged.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/all/202112071130.VjoibOrG-lkp@intel.com/
Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
---
drivers/input/touchscreen/ili210x.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
index 03e4451d6..94e6db4d9 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
};
error = i2c_master_send(client, cmd_wr, sizeof(cmd_wr));
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] Input: ili210x - avoid shifting 16-bit values by 16
2026-11-29 7:32 [PATCH] Input: ili210x - avoid shifting 16-bit values by 16 Aibing Chen
@ 2026-11-29 7:43 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-29 7:43 UTC (permalink / raw)
To: Aibing Chen; +Cc: linux-input, dmitry.torokhov
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 7:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox