Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp158248pxk; Wed, 16 Sep 2020 22:27:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynJgGPc4h5pu7cP211hU2GVdsJbp4DYelmHzmfJuHLbvxlsxmXwYF40xM5Sqv8oRBMg/CP X-Received: by 2002:aa7:d750:: with SMTP id a16mr32000408eds.362.1600320449461; Wed, 16 Sep 2020 22:27:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600320449; cv=none; d=google.com; s=arc-20160816; b=xEdoQtPzKkM5RdlKdNNnFomHcZ3vl2MH18/yJl4R3ziwjuHK5PyqlkrfqTb31lLnbv QoErSLL/+ffRdb+sTLt18y4JeNje0GkEC9Whm5j6vM0r7m2lDRQ+DPktKk8YLgeIaDvt ovJhZej4k1WSnP/SU8WHOc3lAm5tCpACRQc7ijEL3MftO32dXUH8sokdHm9MOAUtZYqO Bl0J0yla1uT0Lt6WZa/+g1qet7FEb0f76KWAwSXErt9VwI+Rmb3eTx+iYbX9QzDlh64W O6HfHTlbMmgH5BHUeCOAu6HiyF2QMUT9rWc5Ko9DZHjrO8qyxRNkRoN4Rk8YMZwc7AkM CoJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=H9VSuNM4l/40vayIg5SAmxrV3Ky0F4a/ev4/YbXR38I=; b=bQ85hvDKd8Xb3VCXNF9MpE6nSr5LekqqOQT5Jb8Lt5Nm7ldcReFITBCz7JWPpfEswe gxqUL0xeSluyRneljBbL7vuHXROX4j1PjF5x1S+goePtKadqVR8UxBC/TuXta+f8YP5z rE3hSt6TxpX87Nc7RV0bCXTDHXatnHWpcmfHR+R3QKOnXUZGdltB/QkVpCSOuU9tg85G o8I6r5Bj4B16CuZ3QGq+uX0wLUDvDxBYIdHbq3WlpglxhQUsK4fRFmX3oaNBfNiL3yXx 0u/QPCNAfLsns9e5WwV1gLaA3aWVFtL7XJYox1WZANERdmGf0LEC3eNA8cbA9/9PUM4z LvLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=jfykg3GQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i21si14355978edv.439.2020.09.16.22.27.05; Wed, 16 Sep 2020 22:27:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=jfykg3GQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726291AbgIQFXn (ORCPT + 99 others); Thu, 17 Sep 2020 01:23:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726169AbgIQFXD (ORCPT ); Thu, 17 Sep 2020 01:23:03 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19171C06174A; Wed, 16 Sep 2020 22:23:02 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id l71so680247pge.4; Wed, 16 Sep 2020 22:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H9VSuNM4l/40vayIg5SAmxrV3Ky0F4a/ev4/YbXR38I=; b=jfykg3GQwbbnkRd4mHs2T0pRUdzz6Qg04xQDWonYE+62vUyPxk2CSLjNyOuwQCK0wQ kUaQ8/9tGinqIg9HVGsDRNH6jabj28nmPIwstqFlvS6NsEZ/loOvs/JlEfSnQrlt0TUv riOpGWHsnRPnO1Dht3mtFK6Ge7oJALV93RpiDKnage3a9TapArQxpoR9EkToOJwoZGmg kkEAiBqlnuCdonIX3vCrWzrli6uuZdrpxpmBW/pxRXWNcnMB6YpNk/E5lVt/7rO+TqRm uLSMc4LtD9P2wavTLkjV+i3S0Nd3eQnJDFKgmPEc0HHyoCP+C1lS8QSTHxhlgomcEzNj oXUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=H9VSuNM4l/40vayIg5SAmxrV3Ky0F4a/ev4/YbXR38I=; b=FXoiZMlyebz0KIAfDUWB3Qgcy/xKvQwMRYdSn+NEEuQUhPCJXr74M8XQsI3+9ElhpT NIhXECTpQuz+aJY/xRyPquq5/m5UJOEs1mGIEaJmGKdvwgjiGYCEKJIKoiqm8PAHRu7Q 4Z86Tcqu1Y49EI4jV9kz51XXlG4Z+ItSF84Feut9fPvMJ6sHLBBnCQyO5FvrKm62/YgT b6c6xsUGtVGN4vQjEc1zCmiikHMsYQwVJZ/lqAa5bj+IAhKg11yUlJGLoOMJwZ7QtY+U m2z5l54//8O0Z2q1sxIZMojCcB/+LZZL2YyYZJHv0kaLJYDNZOO2TCbTj9Z0WFzrCLn8 1Dgw== X-Gm-Message-State: AOAM5323ifwaT3cRS6jfMKodiDbWoCv2/roSNP+pe27a8cZ4Uh98fKJQ clVzq516dvPCnBlWYRtsIlmsvKO5dDxTVQ== X-Received: by 2002:a62:fb1a:0:b029:142:2501:39f9 with SMTP id x26-20020a62fb1a0000b0290142250139f9mr9134883pfm.72.1600320181402; Wed, 16 Sep 2020 22:23:01 -0700 (PDT) Received: from sultan-book.localdomain ([104.200.129.212]) by smtp.gmail.com with ESMTPSA id i62sm18705619pfe.140.2020.09.16.22.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Sep 2020 22:23:00 -0700 (PDT) From: Sultan Alsawaf X-Google-Original-From: Sultan Alsawaf To: linux-i2c@vger.kernel.org Cc: jikos@kernel.org, aaron.ma@canonical.com, admin@kryma.net, andriy.shevchenko@linux.intel.com, benjamin.tissoires@redhat.com, hdegoede@redhat.com, hn.chen@weidahitech.com, jarkko.nikula@linux.intel.com, kai.heng.feng@canonical.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, vicamo.yang@canonical.com, wsa@kernel.org, Sultan Alsawaf Subject: [PATCH v2 2/4] i2c: designware: Ensure tx_buf_len is nonzero for SMBus block reads Date: Wed, 16 Sep 2020 22:22:54 -0700 Message-Id: <20200917052256.5770-3-sultan@kerneltoast.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200917052256.5770-1-sultan@kerneltoast.com> References: <20200917052256.5770-1-sultan@kerneltoast.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sultan Alsawaf The point of adding a byte to len in i2c_dw_recv_len() is to make sure that tx_buf_len is nonzero, so that i2c_dw_xfer_msg() can let the i2c controller know that the i2c transaction can end. Otherwise, the i2c controller will think that the transaction can never end for block reads, which results in the stop-detection bit never being set and thus the transaction timing out. Adding a byte to len is not a reliable way to do this though; sometimes it lets tx_buf_len become zero, which results in the scenario described above. Therefore, just directly ensure tx_buf_len cannot be zero to fix the issue. Fixes: c3ae106050b9 ("i2c: designware: Implement support for SMBus block read and write") Signed-off-by: Sultan Alsawaf --- drivers/i2c/busses/i2c-designware-master.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c index d78f48ca4886..22f28516bca7 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -395,8 +395,9 @@ i2c_dw_recv_len(struct dw_i2c_dev *dev, u8 len) * Adjust the buffer length and mask the flag * after receiving the first byte. */ - len += (flags & I2C_CLIENT_PEC) ? 2 : 1; - dev->tx_buf_len = len - min_t(u8, len, dev->rx_outstanding); + if (flags & I2C_CLIENT_PEC) + len++; + dev->tx_buf_len = len - min_t(u8, len - 1, dev->rx_outstanding); msgs[dev->msg_read_idx].len = len; msgs[dev->msg_read_idx].flags &= ~I2C_M_RECV_LEN; -- 2.28.0