From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: joe@perches.com, Chengguang Xu <cgxu519@gmx.com>,
kernel-janitors@vger.kernel.org, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] Input: elan_i2c_smbus - cast sizeof to int for comparison
Date: Wed, 1 Aug 2018 16:03:54 -0700 [thread overview]
Message-ID: <20180801230354.GA184797@dtor-ws> (raw)
In-Reply-To: <1530466325-1678-2-git-send-email-Julia.Lawall@lip6.fr>
On Sun, Jul 01, 2018 at 07:32:03PM +0200, Julia Lawall wrote:
> 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>
>
Applied, thank you.
> ---
> drivers/input/mouse/elan_i2c_smbus.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/input/mouse/elan_i2c_smbus.c b/drivers/input/mouse/elan_i2c_smbus.c
> index c060d27..88e315d 100644
> --- a/drivers/input/mouse/elan_i2c_smbus.c
> +++ b/drivers/input/mouse/elan_i2c_smbus.c
> @@ -387,7 +387,7 @@ static int elan_smbus_prepare_fw_update(struct i2c_client *client)
> len = i2c_smbus_read_block_data(client,
> ETP_SMBUS_IAP_PASSWORD_READ,
> val);
> - if (len < sizeof(u16)) {
> + if (len < (int)sizeof(u16)) {
> error = len < 0 ? len : -EIO;
> dev_err(dev, "failed to read iap password: %d\n",
> error);
>
--
Dmitry
next prev parent reply other threads:[~2018-08-01 23:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-01 17:32 [PATCH 0/3] cast sizeof to int for comparison Julia Lawall
2018-07-01 17:32 ` [PATCH 1/3] Input: elan_i2c_smbus - " Julia Lawall
2018-08-01 23:03 ` Dmitry Torokhov [this message]
2018-07-01 18:26 ` [PATCH 0/3] " Joe Perches
2018-07-01 18:51 ` Julia Lawall
2018-07-03 13:00 ` Dan Carpenter
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=20180801230354.GA184797@dtor-ws \
--to=dmitry.torokhov@gmail.com \
--cc=Julia.Lawall@lip6.fr \
--cc=cgxu519@gmx.com \
--cc=joe@perches.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).