Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: elan_i2c_smbus - cast sizeof to int for comparison

Comparing an int to a size, which is unsigned, causes the int to become
unsigned, giving the wrong result. i2c_smbus_read_block_data can return the
result of i2c_smbus_xfer, whih can return a negative error code.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
int x;
expression e,e1;
identifier f;
@@

*x = f(...);
... when != x = e1
when != if (x < 0 || ...) { ... return ...; }
*x < sizeof(e)
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Julia Lawall and committed by
Dmitry Torokhov
ce1d6f22 384cf428

+1 -1
+1 -1
drivers/input/mouse/elan_i2c_smbus.c
··· 387 387 len = i2c_smbus_read_block_data(client, 388 388 ETP_SMBUS_IAP_PASSWORD_READ, 389 389 val); 390 - if (len < sizeof(u16)) { 390 + if (len < (int)sizeof(u16)) { 391 391 error = len < 0 ? len : -EIO; 392 392 dev_err(dev, "failed to read iap password: %d\n", 393 393 error);