Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2445163ybt; Tue, 16 Jun 2020 06:24:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6EOWP/6CldK6DIUlMokm9Mh48xdGtVZoKBNv4T/ApBcXDL6q7VSpWutG2K1vRh2KHN6Rb X-Received: by 2002:a05:6402:31bb:: with SMTP id dj27mr2603688edb.156.1592313884370; Tue, 16 Jun 2020 06:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592313884; cv=none; d=google.com; s=arc-20160816; b=ffmrDe1ayLeqOW+Q7Ny/aMXKKC7UAm9EwviYnScpYmtWyt7MmH0DWjUVPnbRjaWWf0 INkTlVaQcN/9YBiG9vWZyEGBu2gVxd9nRhixNb2lAi/i5Ae/3BnfF+Bssc+15U4K3vf5 o2ukay/cu3CMOiVRlYUjH6winIx41DYdlqAdvJPwrR68Qo5AQjNi96+N2ZjhfqJ0CJ5n dQw5HoS1MOsTwj9uCtTmRHGcAi1z+F7vfCcISMiBGYaQKkBG9qHywq5a1rEU9NAhO3bi WoHl0EdHZPvGAjDNyX8zFmRHhqTeOsuju89I6OPInLBJ5O2Q/GCRqd1fAV69gtBlwpud DOjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:ironport-sdr:ironport-sdr; bh=6OIiUNcAu3n8IIXqTcgWEuCt9/BSq9Gq+3q+601BcVc=; b=wvMkKnja9twfDC9Jexr+wiziyk7PZaAjlRWoo9TzXafYpcnBMzCQjh6Qb6vAVvkMFx dXs9FzRRjO3wl/lZoZzpHjv+fpN2QIzPXQp0p7EClte10kdlDHAOrCFy06mbY7qp5MAT 8MOwL18VgRMkl5zjO0fgBSjuDTLWSqhRnvn2LMhq7tCUvOQAesogNCkTrfVjOqyPPe4k J1xyv1GLcA0tow0ZYKbN38G2Td+eot4mXP4s4gqsaWysbTXl8rbjX5MCQuXN+NlD+B3p xiXoEQMoIs6jLa8otGonWMtvOH7NnJWg6cmHGUHbMhmyStUZoTWo2xXkQK3Na58M95cf 0ecg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g8si5380862edn.160.2020.06.16.06.24.21; Tue, 16 Jun 2020 06:24:44 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728803AbgFPNWe (ORCPT + 99 others); Tue, 16 Jun 2020 09:22:34 -0400 Received: from mga17.intel.com ([192.55.52.151]:23602 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726452AbgFPNWe (ORCPT ); Tue, 16 Jun 2020 09:22:34 -0400 IronPort-SDR: /JREh8sxwFrhr5UJdflTdRIjB5qsrMvy3rj6B1rlu7+usPVTj7Z2THTeVTaEdehf+haWbKYC28 30zlnn70N7tA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2020 06:22:34 -0700 IronPort-SDR: rc0fL3M4Ilanr8d/92/7cxTK3J/21xSMSVOltMUczT0GXTImMJ9ffimc8SjUpg/ZmvIB2ynlKo SfNnuIcQm/Xg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,518,1583222400"; d="scan'208";a="298900998" Received: from mylly.fi.intel.com (HELO [10.237.72.87]) ([10.237.72.87]) by fmsmga004.fm.intel.com with ESMTP; 16 Jun 2020 06:22:30 -0700 Subject: Re: [PATCH 1/2] i2c: designware: Only check the first byte for SMBus block read length To: Sultan Alsawaf , Aaron Ma , Andy Shevchenko , Benjamin Tissoires , Hans de Goede , HungNien Chen , Jiri Kosina , Kai-Heng Feng , linux-i2c@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Mika Westerberg , Pavel Balan , Tin Huynh , Wolfram Sang , You-Sheng Yang References: <20200614210255.4641-1-sultan@kerneltoast.com> <20200614210255.4641-2-sultan@kerneltoast.com> From: Jarkko Nikula Message-ID: <9782f44e-4e01-4e5d-cc50-ab9e2219085c@linux.intel.com> Date: Tue, 16 Jun 2020 16:22:30 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200614210255.4641-2-sultan@kerneltoast.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/15/20 12:02 AM, Sultan Alsawaf wrote: > 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. > > 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, 5 insertions(+), 5 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c > index d6425ad6e6a3..16d38b8fc19a 100644 > --- a/drivers/i2c/busses/i2c-designware-master.c > +++ b/drivers/i2c/busses/i2c-designware-master.c > @@ -398,7 +398,6 @@ i2c_dw_recv_len(struct dw_i2c_dev *dev, u8 len) > len += (flags & I2C_CLIENT_PEC) ? 2 : 1; > dev->tx_buf_len = len - min_t(u8, len, dev->rx_outstanding); > msgs[dev->msg_read_idx].len = len; > - msgs[dev->msg_read_idx].flags &= ~I2C_M_RECV_LEN; > > return len; > } Please update the comment about masking the flag a few lines above this change. > @@ -430,10 +429,11 @@ 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); > + msgs[dev->msg_read_idx].flags &= ~I2C_M_RECV_LEN; > } > *buf++ = tmp; > dev->rx_outstanding--; With above comment change this looks good to me. -- Jarkko