Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1825496ybt; Mon, 15 Jun 2020 10:19:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuP87biwY/SpdQqpnybw3MHJRcZOR7rMvbcmZbQHo422LuQC6xrWuCna0EaXAXj0yPvC+2 X-Received: by 2002:a17:906:fb9b:: with SMTP id lr27mr13737785ejb.405.1592241557441; Mon, 15 Jun 2020 10:19:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592241557; cv=none; d=google.com; s=arc-20160816; b=UT8iBDZMXYbvWp4HA4pUA0wn06FVuU0ABcX/7IBcDMpQc22WFJz6TH1t7X3TUpbE3A 92NCeO/DW4IupYRH24rHEjhOp8xdnK7QFjHR4ypC9SFICAmFmX47nWnoCccahW13cuD9 bFp3HClXWDa85zf+JkGhpzyLbE+P7pY/Ao6XPpueo5TJ0pR6OS4t1UJJW5bV0vUL9MPs CHjJNyXLkLdnHqZ1NyARpomj3S1EAoFT6vi2nD4JH8qi0lPwJZKFdWZx2F588MwR3yvm MbXOAXQb6gSS8hfxzJqqaHfC1bqRzdjoZ6TLyeoXr78HXQpyc6Zr9pqAfT0ax55xMmdj LSqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=FCIu8IiCUQi+aGjEXORugDoaPNJi9zDY2fZ9atryoaU=; b=exbqMKF5MCuRY40M54Jfo+4RXwJof8/mlHpSyHOpz/j9NYiN0JOoRgafU8LaBYbuDk JrqdLtLclY+BsROM7r29WL+90souqn+KNF9Q+TsR5DYQ8Kn1MUEtXBThg/QwBm+SMZZg YyyvJahh8DQKHKhFd3SlrPcP4ua3O/mtt5d0+fBFKPmIKpHvrvxaQeg1cIKnUfUPHBD2 IY3QqP9UO7rbpHpF0jjJCT/47ZsNO7iL2qsqqda9aS4zEod67uNCwGVzViEuUR/ONvWh T+rdbYOHjC+xxnRpZxumU0x51i+8lWACkyWcUsisa3T0TX5FJ+zQR7OX9/bKuoa6ol1/ YNNg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k25si8495163eja.712.2020.06.15.10.18.54; Mon, 15 Jun 2020 10:19:17 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731087AbgFORPQ (ORCPT + 99 others); Mon, 15 Jun 2020 13:15:16 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:45421 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729354AbgFORPQ (ORCPT ); Mon, 15 Jun 2020 13:15:16 -0400 Received: by mail-pl1-f193.google.com with SMTP id d8so7049719plo.12; Mon, 15 Jun 2020 10:15:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=FCIu8IiCUQi+aGjEXORugDoaPNJi9zDY2fZ9atryoaU=; b=gHIl6kedbk4LH/4YFqG5x5svgeAgzEcupg3MDg2VFqP8wzbtv93bToEpg1lZYLiYWT eOUSnCOE2me5BTzTQPLDmsBvDG0/bv7EyY/kX0e2ZEJLDQPlpIqJXrV4kxWqqKsSVUQN XAx3vOtRnGnqCgzmqf00vcsw3bRZDMM+bM9ctI/eDXHdBJUhyIjYoWs1YLKkEl+zO9Gq Maz9SATmmeqTMFSwmYAaH05luLkoB/meH4cPe+R1FxZ9cYqq8EkAllzaQGjnmc+wMnLY /GJkYHbirVxMm4bAb1DbBiCIziEFBQxgSVAV8O6Mh2NBQAndtQAajKipkEpkQYvyXiXo 9nhQ== X-Gm-Message-State: AOAM5305byAinA2pDSiPBMCMJm8R//pCCpunF5ngCKUKWpcbjTT/NjbZ 0qZS7zkOMTK5J3ZZSG+FZeU= X-Received: by 2002:a17:90a:58f:: with SMTP id i15mr331529pji.78.1592241314281; Mon, 15 Jun 2020 10:15:14 -0700 (PDT) Received: from sultan-book.localdomain ([89.45.90.111]) by smtp.gmail.com with ESMTPSA id t7sm97363pju.42.2020.06.15.10.15.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 10:15:13 -0700 (PDT) Date: Mon, 15 Jun 2020 10:15:08 -0700 From: Sultan Alsawaf To: Andy Shevchenko Cc: Andy Shevchenko , Aaron Ma , Benjamin Tissoires , Hans de Goede , HungNien Chen , Jarkko Nikula , Jiri Kosina , Kai-Heng Feng , linux-i2c , linux-input , Linux Kernel Mailing List , Mika Westerberg , Pavel Balan , Tin Huynh , Wolfram Sang , You-Sheng Yang Subject: Re: [PATCH 1/2] i2c: designware: Only check the first byte for SMBus block read length Message-ID: <20200615171508.GA2663@sultan-book.localdomain> References: <20200614210255.4641-1-sultan@kerneltoast.com> <20200614210255.4641-2-sultan@kerneltoast.com> <20200615094019.GP2428291@smile.fi.intel.com> <20200615160320.GA1949@sultan-book.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 15, 2020 at 07:07:42PM +0300, Andy Shevchenko wrote: > On Mon, Jun 15, 2020 at 7:06 PM Sultan Alsawaf wrote: > > On Mon, Jun 15, 2020 at 12:40:19PM +0300, Andy Shevchenko wrote: > > > On Sun, Jun 14, 2020 at 02:02:54PM -0700, 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. > > > > > > I'm wondering if this overlaps with [1]. AFAIU that one is also makes sure that > > > the length is not a garbage. > > > > > > [1]: https://lore.kernel.org/linux-i2c/20200613104109.2989-1-mans@mansr.com/T/#u > > > > No overlap. > > Thanks for clarifying. > > > That looks like a similar bug for a different driver. In my case, > > the adapter provides native SMBus support, so emulation is never used. This is > > clear to see by looking at i2c_transfer_buffer_flags(), which only uses the > > master_xfer functions provided by the adapter; it doesn't call the emulation > > path at all. > > But do we get an advantage if this can be done in the i2c core instead > (once for all)? We can't, because the adapter driver needs to know mid-transfer to look for the payload length in the first byte, and then alter the transfer size on-the-fly. That can't be done in the i2c core, sadly. The problem is that we don't know if a transfer is going to be a block read or not beforehand. And altering the transfer size mid-transfer is definitely a controller specific task. Sultan