Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp157081pxk; Wed, 16 Sep 2020 22:24:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaQ7A2nUq1RaOAd6Lj9BwVw3sjVMKnUsz4Ie+LBtOc3OBtR87xcE4LPRbzKTtdeRdn33gI X-Received: by 2002:a17:906:bcd5:: with SMTP id lw21mr29144722ejb.430.1600320277276; Wed, 16 Sep 2020 22:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600320277; cv=none; d=google.com; s=arc-20160816; b=x8xQXo5OnAsxJVlPWiV6AHQUcfwERknhlUlNy0ohxy34AimAUjMge/qjrn91Hw34aY MVotZdeLw9ffxOzwP2ILLFfDQPC23gHUj7c9lgfosjvEqy58sBMwap+OPhJG/cNjuslT TQ5Hfw8yAYYCFoRidjjIQbJAKNcYlQdEXrpe/E6I47dP6HcvvO8t2f8eCRfmSmo5W3/c B9fvcQfR2nYcdCYlI9/Bc2R8W7ojjtrA0M1J7k5hcP15u5kRSzE8k962efXkQis9F1nc 0jF2tevM4/PKyK7WRKHWkfNamgkBwwzFwFmqLpApVEVa1j8MO9xM/GRtI45VYcEbt+F3 O/NA== 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=S8OVV1mZhFttZGVKsQ9JByMqrc+T8zXoOJFR2iwsG4g=; b=v8CnAvWriG75QerqgXa3LF6gDHv913IQWekV0dI0XN8YviHxUW1bJhNDO5xA7uFHRx KlrzHnDvbnf/Fam1UJX4EQolkG+gdDc35uPTF5Rbgw8dbs0GiRKR+r5FsPlHETMUaYvV jYxlNiuYHfmm0mGwydddioFP5KsPupExp7uTR57fFFhCvC7blQuA8uMg2Dm0AoNcQCot ddWgl/6KCR966iklQUldY+mMYHoW7yIyRu1qHS4cEj16QVchUXT5hByAxohJoWyVRbRc vY0Pkd/zg9axQS7DsMjj/wv9pxeWYDqy0FCzZJLl4csqCsIjW6G67Km9byKCi21t2qn2 VRPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=csZiyQVY; 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 p2si13291291ejw.176.2020.09.16.22.24.14; Wed, 16 Sep 2020 22:24:37 -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=csZiyQVY; 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 S1726142AbgIQFXJ (ORCPT + 99 others); Thu, 17 Sep 2020 01:23:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgIQFXB (ORCPT ); Thu, 17 Sep 2020 01:23:01 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C40D4C06174A; Wed, 16 Sep 2020 22:23:00 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id d9so491131pfd.3; Wed, 16 Sep 2020 22:23:00 -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=S8OVV1mZhFttZGVKsQ9JByMqrc+T8zXoOJFR2iwsG4g=; b=csZiyQVYfnEgwlEZ9kS/DEtPg3WS1RIfpF0DBEL8GWXMXfDDMCPigCDbhzVUmQy9Z3 +Xyf+LdqcXV8ZYAPetqHUqpn4AIZB9eLImehPcHNvpWRa4jbnkBZESrua7BZ6DiO0HnR NwIUXrYkCNtyR0lf+t4pCmxMdY5piTPrlIavN9hbVxnf1YGtCqhVgUBRR5fIT9iqAg2Y Wv/9zGTUNHSTUhjGtnsGdRUFXd4nVwPZdEbqEvxkGlhU7UTV2S2uTafqBI3M698XVbJd cBfwkRqUQq2Bzzqc7DJtO0tdBoorLPLRuWKTH0JH4KuUfNc5hKqIBEn73Adr7yxKtCBe hqLA== 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=S8OVV1mZhFttZGVKsQ9JByMqrc+T8zXoOJFR2iwsG4g=; b=gRXWwJkghLrglLr6Wrxar1CjbtBzJoMSotfyLgWc2fpP/MmAarldo+AQkMUHvfO/yM SWcw5zIw7zvvbaJrYbIARSq/Guh4TOJK1jkSlq1z+6hdisCwNnb8MTXPt5fxCkZGIc0N ERLyAR8H/Z8CsGhrCr2/Vnsg8spWMcKJV1Z/3xO3CcDlVwVFXy7xU/gwPRVb7VB7HccO f5fU8GTeTxCmwaSyTI0nb/4JPs+D4mX9QColFPyWPAnALyOIxFMwQkWiukdL9vHwuXok KyHjbqDfyQexhsNfm8rVdczWZFoWvdyksBOcSMpD8IqcprjoaqjYY69QJ0+H9zMdfc4B TV+A== X-Gm-Message-State: AOAM530VduBSYJ8ZMxLNttxPxwJriWES14G2IMjhNATPi1QcG0VUqVz5 uwDayBIFw/1I2602qCkUO1fTH17QFGEvyQ== X-Received: by 2002:a62:52d3:0:b029:142:2501:3a00 with SMTP id g202-20020a6252d30000b029014225013a00mr9360192pfb.79.1600320180046; Wed, 16 Sep 2020 22:23:00 -0700 (PDT) Received: from sultan-book.localdomain ([104.200.129.212]) by smtp.gmail.com with ESMTPSA id i62sm18705619pfe.140.2020.09.16.22.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Sep 2020 22:22:59 -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 1/4] i2c: designware: Fix transfer failures for invalid SMBus block reads Date: Wed, 16 Sep 2020 22:22:53 -0700 Message-Id: <20200917052256.5770-2-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 SMBus block reads can be broken because the read function will just skip over bytes it doesn't like until reaching a byte that conforms to the length restrictions for block reads. This is problematic when it isn't known if the incoming payload is indeed a conforming block read. According to the SMBus specification, block reads will only send the payload length in the first byte, so we can fix this by only considering the first byte in a sequence for block read length purposes. In addition, when the length byte is invalid, the original transfer length still needs to be adjusted to avoid a controller timeout. Fixes: c3ae106050b9 ("i2c: designware: Implement support for SMBus block read and write") Signed-off-by: Sultan Alsawaf --- drivers/i2c/busses/i2c-designware-master.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c index d6425ad6e6a3..d78f48ca4886 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -430,10 +430,12 @@ i2c_dw_read(struct dw_i2c_dev *dev) u32 flags = msgs[dev->msg_read_idx].flags; regmap_read(dev->map, DW_IC_DATA_CMD, &tmp); - /* Ensure length byte is a valid value */ - if (flags & I2C_M_RECV_LEN && - tmp <= I2C_SMBUS_BLOCK_MAX && tmp > 0) { - len = i2c_dw_recv_len(dev, tmp); + if (flags & I2C_M_RECV_LEN) { + /* Ensure length byte is a valid value */ + if (tmp <= I2C_SMBUS_BLOCK_MAX && tmp > 0) + len = i2c_dw_recv_len(dev, tmp); + else + len = i2c_dw_recv_len(dev, len); } *buf++ = tmp; dev->rx_outstanding--; -- 2.28.0