Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1427643imm; Wed, 1 Aug 2018 16:05:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcXVXVOtprNeTWqze+mlFwQEbOjxbXyOF9Nz154sUmU+llN0JMuAKy8nsWitLiY7yROrMAY X-Received: by 2002:a63:b213:: with SMTP id x19-v6mr266989pge.393.1533164704014; Wed, 01 Aug 2018 16:05:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533164703; cv=none; d=google.com; s=arc-20160816; b=VPD0XP0uXLQPeD+6+t8LGZRmc+m7Ip6JxT4DwERGKh7RJDrP3l9OC+vRPf2kospAY2 bdfUwLlPCmVOPJWsRcdYYL2QZyPsOHucPodIceA9wNZWj4umIsaqpIpQJo0tM9hhLKCH 6SxfTmu1/S4XRGOzYfne8UVn2D41mDVodMswCQU8NtL1pzbI6lAIBceayPiWbr0P4Jyk TCSM3BW/x20J0gozTS9kLXluOXGBuqxJ3mJjaS+6CKaRdtXR0DwBWg+fQ6N7XOtfpDC2 y+HXnpRALh8U+5Yz2rFtFPwI8u+Ztb8yRVp7d0Ry/6wo4OCpu3VGUIHBaen95dftRlbN /Mnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=n0Me1uZ7eeAenm78ZZdQXqzjZY+FGmuWJ8q1MdyTk/I=; b=bKOIq8z7G0bkJqzzBEDzuLqaDncvJoUN7TI/EJGK2U19AXgc0fAsjJMAEYxY6b4y9H xG7lA50IqEaTKf0YYqtyO+rZhOSaZYP3fMipw/KK2fgHtitqvCsMC5499Qv/ltj0rcQA kfc2d4wLC7e7Urv2g8PARA+vwilcJHP+emS1+Kk92WVkpnC/taATFn2veT29Ev4udAre PuCj5OY9F3PjYcWCQNSec8q7X8M7uTGR4udPekLtnRQGoP7uqLDsn+Gc9dEuRxuLunxW zRWWIrjm/i4GeVzguMiwLfE43Zb2KL+Qoe+zJrTNtzQFdN7LD2ZURD5YZsTr5C1yn1O/ mgMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lMpVpBOo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6-v6si233052pfy.140.2018.08.01.16.04.48; Wed, 01 Aug 2018 16:05:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lMpVpBOo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732237AbeHBAwH (ORCPT + 99 others); Wed, 1 Aug 2018 20:52:07 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43017 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726723AbeHBAwG (ORCPT ); Wed, 1 Aug 2018 20:52:06 -0400 Received: by mail-pf1-f195.google.com with SMTP id j26-v6so136227pfi.10; Wed, 01 Aug 2018 16:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=n0Me1uZ7eeAenm78ZZdQXqzjZY+FGmuWJ8q1MdyTk/I=; b=lMpVpBOoN/fTtaVmb9rECBtKv9xssR0dZyEds+Bpsh9wHZAfdx5nkBUDEDCbc9rc6Q XdsdklE4cLaTFqv43TZp7tKRsxRpNh1G7MeomYMha7/i6SygXUZc5WExrdQTM4d4mUex 6RpUi6Iww9j41n87MBCSmi1+97o/LZJgbmZm80bvi6N+eQ+DgVZc8p3vbMaoPUeG+uzQ fj6+fzZBVCYPgs0LNwy9a1O5tnHqc6Mb6LbZ6QxJIXU8TNtKQu+JPG/OGgXcgmkexxYv XnxpGpAVdWPOLh4WBJlrrGl5FXWzG7HZV/K+iFvIufGtrwR7MXKXKBimuGMxMrDcOsX3 iHOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=n0Me1uZ7eeAenm78ZZdQXqzjZY+FGmuWJ8q1MdyTk/I=; b=hK68cPILfLMxscNxclGd+zrjGIKRTk8lMQo0hyZNhjpJDg64zg9RsUuL93FGOlqOvl G3/oYKI4dgxlnWqzqgGRrATiWsbjHbx6GHRoxlc+r/gYnmNeWI/9eo8qYJEBE/0dGo5j Po+m4Ad0yx9B/yp6uz3rDP9Q5dJ0tB94Lqe5AIVxyHNPtKyeu9uxfI5lIWQjNWP4kLLi CuEVZEnB5wHqo8Vq6kzZZVcPlti5/f3efDB4wBMbvBn/d8ny8Rm5DIZypyB8JfscyvHB 36111F0TInR78i52A+VIOdduBeAbcm9q/oT4ZU7KAUY3+Vb5xtXXywSTc2oH6xEZTrO4 RZVw== X-Gm-Message-State: AOUpUlG4c2uQQu2EnHifTD3EunwFIUL/N3AUWfRHOegGL8qX7S4C38Ld fNPIg0nofB1vU7dArW3RpkZ2gxwz X-Received: by 2002:a62:954:: with SMTP id e81-v6mr287384pfd.231.1533164637833; Wed, 01 Aug 2018 16:03:57 -0700 (PDT) Received: from dtor-ws ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id r19-v6sm150446pgo.68.2018.08.01.16.03.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Aug 2018 16:03:56 -0700 (PDT) Date: Wed, 1 Aug 2018 16:03:54 -0700 From: Dmitry Torokhov To: Julia Lawall Cc: joe@perches.com, Chengguang Xu , 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 Message-ID: <20180801230354.GA184797@dtor-ws> References: <1530466325-1678-1-git-send-email-Julia.Lawall@lip6.fr> <1530466325-1678-2-git-send-email-Julia.Lawall@lip6.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1530466325-1678-2-git-send-email-Julia.Lawall@lip6.fr> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/) > > // > @@ > int x; > expression e,e1; > identifier f; > @@ > > *x = f(...); > ... when != x = e1 > when != if (x < 0 || ...) { ... return ...; } > *x < sizeof(e) > // > > Signed-off-by: Julia Lawall > 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