From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B24C8C433E2 for ; Mon, 15 Jun 2020 17:15:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 95E72207DD for ; Mon, 15 Jun 2020 17:15:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731168AbgFORPQ (ORCPT ); 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-Google-Smtp-Source: ABdhPJxOzYZMBPVCwDwb/VcurGYYUBAIP1XxMjkA/Y0IHrBP84cV+ZamibvHeyBqn5f+mBmQbaGY+A== 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