Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3051269imm; Sun, 1 Jul 2018 11:06:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf7hG8yG3vMe5uc2A8wX6Zy3gH+tLAK7bspXAhKD5Nj3CBnoQmzLR5PjlBzNaiegDIS9H97 X-Received: by 2002:a62:df4e:: with SMTP id u75-v6mr10475221pfg.195.1530468375159; Sun, 01 Jul 2018 11:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530468375; cv=none; d=google.com; s=arc-20160816; b=rbK9jG+X55/uf4Lu5Ktfw+Az5hpM0+ri6/gIWBSlwOWBoV+uDjW4RlJeaaAMoUjbuO YPMLSTX5XORSBCnQZCTdbvNudr/ZweSNBg/WGzyuGMAEq75tTIU2QkBgmhLPA5t38vNs Zt7m+a5v7PGF5efbtDo/l3NuxCjMUTCYjE+7bquSop09+0K9cb4uMze4sXMnJy3r/wLQ q0lRGwrzp9HKAqqIPIOTzrxG9YGSSh7v3uAYm2Ol794aF53U+dxpz7Ur69zpTpf9W4wp U2zo4VdstEDQlG/O8rVEkI3XhAI83g1KSXAlL6R+8cfeZ+1sP5TIIMIPSohyCtCeFr9n uc9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Z0abLT53xznOw6vDajUz0r70FXRY8snwscExgyYXgJY=; b=GqMKZEBlb+P92CMlTER9sMnFw8b+K+/uP8uURRV5ndQE2zxOGazq/8RL6YHn3p029p OWuPOOG87nYh/yD0yamVwPd7O54KbCn+a7zcifSy4VYyyN9Qz6Ya4L5c3Nq97zaOgxuG AVVQFgCS7kzVUiqjwZOfRu4KmqlhXDfudP5YRlD8Wjr1Lb0nfvaJ0CoUqmfS5EHChfsE KXtvT3lJg0toop81VsR70T2flCc0PtlDLAnCf1JCEza0jQJ4dot+K6u26flURHCVoOc1 v+BWRg/Qf5duu8whBbw5SdyqkQqdNt1iglzpM10rY1JbfoEZSPbierzurY9Jg+99DkUm qhEQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j5-v6si13783844pfh.3.2018.07.01.11.06.00; Sun, 01 Jul 2018 11:06:15 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030253AbeGASEu (ORCPT + 99 others); Sun, 1 Jul 2018 14:04:50 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:53482 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965318AbeGASEr (ORCPT ); Sun, 1 Jul 2018 14:04:47 -0400 X-IronPort-AV: E=Sophos;i="5.51,295,1526335200"; d="scan'208";a="271074625" Received: from palace.rsr.lip6.fr (HELO localhost.localdomain) ([132.227.105.202]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/AES128-SHA256; 01 Jul 2018 20:04:44 +0200 From: Julia Lawall To: Dmitry Torokhov , joe@perches.com, Chengguang Xu Cc: kernel-janitors@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] Input: elan_i2c_smbus - cast sizeof to int for comparison Date: Sun, 1 Jul 2018 19:32:03 +0200 Message-Id: <1530466325-1678-2-git-send-email-Julia.Lawall@lip6.fr> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1530466325-1678-1-git-send-email-Julia.Lawall@lip6.fr> References: <1530466325-1678-1-git-send-email-Julia.Lawall@lip6.fr> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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);