Received: by 10.192.165.148 with SMTP id m20csp1158928imm; Sat, 5 May 2018 06:03:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqO+gDdfu+iiFQCX83QRjcs7sAG+v6v2w0v/35UBzN1udIK6WNX7PXO/f02t6y8HwPBVfsY X-Received: by 2002:a17:902:9042:: with SMTP id w2-v6mr31269575plz.34.1525525417548; Sat, 05 May 2018 06:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525525417; cv=none; d=google.com; s=arc-20160816; b=JSV9zTitUC4rLsMhNDtsxkpaQQ+DbyjzX1zkyg0VV1OQT2l4LewesKc4axOcQWOKeQ VAPyEe6bIQOJrNmmDugJhIlwSDZ/xnhUCorPyAr4aiAol0cI7F60A6PLei5MeBoOTPxy 3yjvFCSh4B5/Dg4Jvew8duhIU+B9Qt5xrCGeD9tuB5QJV1lyeTLkQAjzwmRq3SuUr8Rv pwfaEJOgfVqCxSWg91El7c5DosOCMJ58WKLP6z5TT8+vrqJzrf438+YoMuyYXHBwXy5B MAGwWreJBa2kfDWXMMO2e3SAfdKypr52E/rxsPL1QhqRGXXPNoGvkZtBmOyPSnitabKo yAYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=1UP9hszMilk1Fo/QRzUyqWFSP4DQ0OdHoY0SIgJK6kg=; b=cBqMFcWqfJTIrQQRQq9mTgXZeLk5obtvGNJLyQDWHgxn4PVdhtZMfEYgXfkWvdM1kp KZdkjwXqDtuH3A3fnAHd8Bmtsb5DuKPPB1egcuxhrOMaiWYP/cB4SuZC6uXsqoEhUnAA FiHG0f+hNRp7uF0c3tZL/8L2xBlS/zFAEsAvyIjLkfvr97abDa7FXFC0tbjcs6iKqLzx aUMtsW6qXHH8oziT2Olc2SREg5O/ALg7AV9b9uumfxCl9oF78tDl3QQ7UwE0FdV7fUw3 o81XOqoV0aMgZlXayTauDwOuzxsHFpGok8yhwDNCB3yEueZ72XAIqVwCWVTW+3q6CfSp zuNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=nmXSimqg; 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=NONE dis=NONE) header.from=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11-v6si18176213plo.352.2018.05.05.06.02.51; Sat, 05 May 2018 06:03:37 -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=@umn.edu header.s=google header.b=nmXSimqg; 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=NONE dis=NONE) header.from=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751230AbeEENCn (ORCPT + 99 others); Sat, 5 May 2018 09:02:43 -0400 Received: from mta-p8.oit.umn.edu ([134.84.196.208]:32852 "EHLO mta-p8.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750967AbeEENCl (ORCPT ); Sat, 5 May 2018 09:02:41 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p8.oit.umn.edu (Postfix) with ESMTP id 958A2C13 for ; Sat, 5 May 2018 13:02:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p8.oit.umn.edu ([127.0.0.1]) by localhost (mta-p8.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wKLlr-bCOXhg for ; Sat, 5 May 2018 08:02:40 -0500 (CDT) Received: from mail-io0-f200.google.com (mail-io0-f200.google.com [209.85.223.200]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p8.oit.umn.edu (Postfix) with ESMTPS id 68DBDBD5 for ; Sat, 5 May 2018 08:02:40 -0500 (CDT) Received: by mail-io0-f200.google.com with SMTP id n8-v6so22840147ioe.15 for ; Sat, 05 May 2018 06:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id; bh=1UP9hszMilk1Fo/QRzUyqWFSP4DQ0OdHoY0SIgJK6kg=; b=nmXSimqghuiGrJuvv+aZAtAeGQj1sa+Xci53TeqZm+zRttHw0CAwh1tW0WDs1oJKIH v0ihebnSHvIawhFjB7lb4sviD6w02YPR4P0mbiWLLjlReEGpXhGBDr2mJ7Ja9R8Bc2HG aopvkCbykJu9EKAYLz0lXkvjkhrWoKuvKUK6gsD+ZGRu6q/e9S1hnL/780ScXb38T3FE HmUIGEIzQUMapT6B5yHowRGoT7PTVdyOcgvsZ5H4+DCTluZqCuXTjkBLqXeU2g1akoN8 1ar3rbXU6lG/8Iav8oYscT/9EgiNSMXGx0lqD3MtRkefhXs1EwyQ7+n+YXMdtaJic0vJ f16w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1UP9hszMilk1Fo/QRzUyqWFSP4DQ0OdHoY0SIgJK6kg=; b=nAxSWRLVCY4g2cwEMoqz2N0PuWRoCH08ayQmwEKETi+YY/atfW3DVbAV3ZYZHbTe5L 6m5a4tpuesFze8oxXS8ST7jJEEsyudIo7hM1wbFYeW0IuKRqnUsWieLR6wFLuQm/G8aC rwrpdgQXxk6uqs8I3TCfNvUUgtiuy5ZjUOOpcSrNVi5qtcka1JdFp+WKZdH+b2X06EB5 iBgV5FHO/mgA9MEiFvit4Pu9P5GKF6ycrReW+yaTMr62p8hwNEOCbpv6pG//QvfaumdP Xm8a7zNW0llyOj/6bRQmaolOnqgaLQ4l6/Uh0oOhMQffZfvGqP7aTsMH2hg29mE6y06r Am5g== X-Gm-Message-State: ALQs6tB4Xm4Ei506zGMW996Vsg6xqe3OjChL/ttbkN+uprCLVA8kgOyJ afWU7CUEvZnDC4Oai+FWlVG2l0WHXs5TMedsGsLLPbke9G6MJNkv/mlgknhxf4UlCUeKbgc+YtI uBFZJTtxVe9j/3aJXEpqa+m2A/9Ua X-Received: by 2002:a6b:1b12:: with SMTP id b18-v6mr33062904iob.175.1525525360102; Sat, 05 May 2018 06:02:40 -0700 (PDT) X-Received: by 2002:a6b:1b12:: with SMTP id b18-v6mr33062882iob.175.1525525359938; Sat, 05 May 2018 06:02:39 -0700 (PDT) Received: from cs-u-cslp16.cs.umn.edu (cs-u-cslp16.cs.umn.edu. [134.84.121.95]) by smtp.gmail.com with ESMTPSA id f22-v6sm9605877ioi.61.2018.05.05.06.02.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 05 May 2018 06:02:39 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Kangjie Lu , Wolfram Sang , linux-i2c@vger.kernel.org (open list:I2C SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 2/2] i2c: core-smbus: fix a potential missing-check bug Date: Sat, 5 May 2018 08:02:21 -0500 Message-Id: <1525525341-10046-1-git-send-email-wang6495@umn.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In i2c_smbus_xfer_emulated(), the function i2c_transfer() is invoked to transfer i2c messages. The number of actual transferred messages is returned and saved to 'status'. If 'status' is negative, that means an error occurred during the transfer process. In that case, the value of 'status' is an error code to indicate the reason of the transfer failure. In most cases, i2c_transfer() can transfer 'num' messages with no error. And so 'status' == 'num'. However, due to unexpected errors, it is probable that only partial messages are transferred by i2c_transfer(). As a result, 'status' != 'num'. This special case is not checked after the invocation of i2c_transfer() and can potentially lead to unexpected issues in the following execution since it is expected that 'status' == 'num'. This patch checks the return value of i2c_transfer() and returns an error code -EIO if the number of actual transferred messages 'status' is not equal to 'num'. Signed-off-by: Wenwen Wang --- drivers/i2c/i2c-core-smbus.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c index 7d7700f..e7a2d2f 100644 --- a/drivers/i2c/i2c-core-smbus.c +++ b/drivers/i2c/i2c-core-smbus.c @@ -467,6 +467,8 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, status = i2c_transfer(adapter, msg, num); if (status < 0) return status; + if (status != num) + return -EIO; /* Check PEC if last message is a read */ if (i && (msg[num-1].flags & I2C_M_RD)) { -- 2.7.4