Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7046102ybi; Thu, 13 Jun 2019 08:39:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqybov23hD6W9pkpADfN86mbuUaQVF5eaewicYD7t1tctVv4UGVA/4r2rAR7I1PVQ0+xeB/4 X-Received: by 2002:a17:902:1566:: with SMTP id b35mr90653546plh.147.1560440396706; Thu, 13 Jun 2019 08:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560440396; cv=none; d=google.com; s=arc-20160816; b=foqYSBJJODQsPmdW13viTCNkVbzEiuWgnblQ6+nsdA4onJigtqFZRh39BTUqjfvvYm TitfhoqfkDANnmMgdGOJIvFA8oV+WTysFoWwI8+mntAUUs33SK3wWrL1GjsWT1I+VP61 qfDyMdLR+5kMSXDeDT2qLo2ggP4wwLcaYM4iUKjliLL4ME1j1jMO/kti6iFgB0gTrYs+ 1VikTRm2R6487WK1zebJ5V9yXh0bMty7sYUgUGFpVHNNM0Pl4U8QIyJmGIxAmhue0qgY 3ZoqLRyWRr47SuXqcg49lqwZRnlkdOEMpi//kyTyxWp5vFXVVcZdWo278io47OX/g1x8 j6ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=bu6PFhdzRuGZwYqZ+hVK3B1DLO4p//ihuWYhcH3V6uw=; b=hI7GD6KuUsjuSkA5yBznWhCwLiyfUOZHnbsLQInFWtfOYuFkiL28Ykzi8YQVxJsfiw 82V+j+rAS4eoVKvDQP+tjBjbrNKQ4MoJv6V+/tIRZYzuuRry7HAlGBP3Gb3IwlVPou/r 5fz6MJsZuk7VZTM3AZdJdKktyxqtGbsx+Do7Znv3nUnhceeVyz+VT3tSrlt1j/vbbkk2 boYdtuZCke7lBRnsf9i81nE1QqccfGIBPyj0FtiS9kL4EfZfhf4f1I4Aa3o5GlMHOBKB NU8VihA5T82hosRDuy/IzSS3HahOVEJC8lFjoPQG3oR17x+TKVf53SWdY7tdJHxkPYpG 3UhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=Ybzhhpu+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z185si3694835pfb.109.2019.06.13.08.39.40; Thu, 13 Jun 2019 08:39:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=Ybzhhpu+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731966AbfFMPid (ORCPT + 99 others); Thu, 13 Jun 2019 11:38:33 -0400 Received: from hqemgate14.nvidia.com ([216.228.121.143]:1466 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731949AbfFMJ7d (ORCPT ); Thu, 13 Jun 2019 05:59:33 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 13 Jun 2019 02:59:32 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Thu, 13 Jun 2019 02:59:31 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Thu, 13 Jun 2019 02:59:31 -0700 Received: from [10.19.65.14] (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 13 Jun 2019 09:59:28 +0000 Subject: Re: [PATCH V5 6/7] i2c: tegra: fix PIO rx/tx residual transfer check To: Dmitry Osipenko , Laxman Dewangan , Thierry Reding , Jonathan Hunter , , , , Peter Rosin , Wolfram Sang CC: Shardar Mohammed , Sowjanya Komatineni , Mantravadi Karthik References: <1560250274-18499-1-git-send-email-bbiswas@nvidia.com> <1560250274-18499-6-git-send-email-bbiswas@nvidia.com> From: Bitan Biswas Message-ID: <3899af9b-07b0-8a76-e343-82871d3eb19a@nvidia.com> Date: Thu, 13 Jun 2019 02:59:25 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1560419972; bh=bu6PFhdzRuGZwYqZ+hVK3B1DLO4p//ihuWYhcH3V6uw=; h=X-PGP-Universal:Subject:To:CC:References:From:Message-ID:Date: User-Agent:MIME-Version:In-Reply-To:X-Originating-IP: X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=Ybzhhpu+/qkKOpkhN12f+D5btArqQfhaBZ/NT8YiFVEknM8QPYJzXABGQso5KeMYH 0iOwme7ANbGZMFZObYeWEpglsYSRsbeLnumsArQpDkAQ6UXgCb9hF6JKROYa+kFXkb b2UtUbkVF9Ew+1DS3bhv+sVY1LtfoiWOFrH+92QcJ2KLycR2syLOD5egBs8auYtJma i4zFRQJwh4cAfJkKUlzm7epqW0UcvmTkWkwzpLhe08ekTtb0TRJAr/wFlkr4DcZgFK OityH7PHsuV14P0GoLQ/WkH6own9A3xKx8124ro4422HZDGQNcCMFGkFjlXtY8oJtx JemuZbJ1yR9jQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/12/19 6:55 AM, Dmitry Osipenko wrote: > 11.06.2019 13:51, Bitan Biswas =D0=BF=D0=B8=D1=88=D0=B5=D1=82: >> Fix expression for residual bytes(less than word) transfer >> in I2C PIO mode RX/TX. >> >> Signed-off-by: Bitan Biswas >> --- >> drivers/i2c/busses/i2c-tegra.c | 11 ++++++----- >> 1 file changed, 6 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-teg= ra.c >> index 4dfb4c1..0596c12 100644 >> --- a/drivers/i2c/busses/i2c-tegra.c >> +++ b/drivers/i2c/busses/i2c-tegra.c >> @@ -514,7 +514,8 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_= dev *i2c_dev) >> * If there is a partial word at the end of buf, handle it manually t= o >> * prevent overwriting past the end of buf >> */ >> - if (rx_fifo_avail > 0 && buf_remaining > 0) { >> + if (rx_fifo_avail > 0 && >> + (buf_remaining > 0 && buf_remaining < BYTES_PER_FIFO_WORD)) { >=20 > The buf_remaining >=3D BYTES_PER_FIFO_WORD is not possible to happen > because there are three possible cases: >=20 > 1) buf_remaining > rx_fifo_avail * 4: >=20 > In this case rx_fifo_avail =3D 0 >=20 > 2) buf_remaining < rx_fifo_avail * 4; >=20 > In this case buf_remaining is always < 4 because > words_to_transfer is a buf_remaining rounded down to 4 > and then divided by 4. Hence: >=20 > buf_remaining -=3D (buf_remaining / 4) * 4 always results > into buf_remaining < 4. >=20 > 3) buf_remaining =3D=3D rx_fifo_avail * 4: >=20 > In this case rx_fifo_avail =3D 0 and buf_remaining =3D 0. >=20 > Case 2 should never happen and means that something gone wrong. >=20 Yes I now agree with you. The first condition "rx_fifo_avail > 0"=20 failure will take care and prevent need for additional checks. >> BUG_ON(buf_remaining > 3); >> val =3D i2c_readl(i2c_dev, I2C_RX_FIFO); >> val =3D cpu_to_le32(val); >> @@ -557,11 +558,10 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c= _dev *i2c_dev) >> words_to_transfer =3D tx_fifo_avail; >> =20 >> /* >> - * Update state before writing to FIFO. If this casues us >> + * Update state before writing to FIFO. If this causes us >> * to finish writing all bytes (AKA buf_remaining goes to 0) we >> * have a potential for an interrupt (PACKET_XFER_COMPLETE is >> - * not maskable). We need to make sure that the isr sees >> - * buf_remaining as 0 and doesn't call us back re-entrantly. >> + * not maskable). >> */ >> buf_remaining -=3D words_to_transfer * BYTES_PER_FIFO_WORD; >> tx_fifo_avail -=3D words_to_transfer; >> @@ -580,7 +580,8 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_d= ev *i2c_dev) >> * prevent reading past the end of buf, which could cross a page >> * boundary and fault. >> */ >> - if (tx_fifo_avail > 0 && buf_remaining > 0) { >> + if (tx_fifo_avail > 0 && >> + (buf_remaining > 0 && buf_remaining < BYTES_PER_FIFO_WORD)) { >> BUG_ON(buf_remaining > 3); >> memcpy(&val, buf, buf_remaining); >> val =3D le32_to_cpu(val); >> >=20 > Same as for RX. >=20 Yes shall discard this patch from the next update. -Thanks, Bitan