Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2389946imm; Thu, 16 Aug 2018 08:58:44 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxqVtrImPL3idIjd5QrCdka+hkXSUPC08ZagzkvrYOs/JBYcMi5ZqcKzo2XGN4I2VLCsE3B X-Received: by 2002:a17:902:7e45:: with SMTP id a5-v6mr29358507pln.151.1534435124714; Thu, 16 Aug 2018 08:58:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534435124; cv=none; d=google.com; s=arc-20160816; b=yWRSgT7MjK7t86pPxH1e5kgclIzjDyS8rc1AW4DbHeGnZyjLZ3kluLygBau1l4AKfy ZmC7GEjayEr9FJrpkmnbkLm0QkphaF2BvjbG3xVAnk/TZmuNs8rm1MEhVgFO29AcyCeG UHQrXfrc1JCezENJGCWwytLn9XUaU3CisELQ0o21mBUVl/iQAPmKAak2WvKra09j3Fz3 5IuXinYVTBbmJXQ7DcYDtdEAyAIU5qqh6vRF4nO6gHGSjL7bvBd5u/Zv3AkyEoRNV+9o eq1K+z7e0VCE91mdfhBycQdkXdaQFNNqRDQpkH/x0FgYWDabfBbEB8ioUazxngCKwCae FNNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=OPQGs0oDGDQkp3Ny37M2yA8E+BIeaPLNC7/bARKpupg=; b=VlWHZ9H7rR6SC4bKyKWXp2/OjbVVWXiKHXgqoROXWKPtl5V6juPQRQQ7hcnetggk8A 1dE5xF9QRmHkIAtG/LMj1kgATxcb2yaLpQZq9GNL9HYtbg+S294lSGpuHHQQFc8NZqYe HJ4kOd8aPhCswd1y5t2EMhTnR9tl89NDdkSjT+ETlqmIsNYc3K/KUv8rRzerprh1JlZA mYigrddhtm7xqQGlnZr987FgfWg12kZ4Uo/B3H1ZDrn1GDy4YW//8ClzInxTpP6ZtJqz z9JG7e6BjKOfInEluUFOLy7fxD3d0CTyNehM8YK8+L4EzivS48T7+voq17Sss4wYwf3+ aOcw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4-v6si23062187plr.427.2018.08.16.08.58.27; Thu, 16 Aug 2018 08:58:44 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389980AbeHPLYY (ORCPT + 99 others); Thu, 16 Aug 2018 07:24:24 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:60269 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731260AbeHPLYY (ORCPT ); Thu, 16 Aug 2018 07:24:24 -0400 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fqDck-0002cE-GT; Thu, 16 Aug 2018 10:27:18 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1fqDcj-0002fZ-ON; Thu, 16 Aug 2018 10:27:17 +0200 Date: Thu, 16 Aug 2018 10:27:17 +0200 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Esben Haabendal Cc: linux-i2c@vger.kernel.org, Esben Haabendal , Wolfram Sang , Lucas Stach , Linus Walleij , Peter Rosin , Wei Jinhua , Phil Reid , Fabio Estevam , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/3] i2c: imx: Fix race condition in dma read Message-ID: <20180816082717.tnoslzw4hwuanvxp@pengutronix.de> References: <20180809123207.9732-1-esben.haabendal@gmail.com> <20180809123207.9732-2-esben.haabendal@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180809123207.9732-2-esben.haabendal@gmail.com> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 09, 2018 at 02:32:05PM +0200, Esben Haabendal wrote: > From: Esben Haabendal > > This fixes a race condition, where the DMAEN bit ends up being set after > I2C slave has transmitted a byte following the dummy read. When that > happens, an interrupt is generated instead, and no DMA request is generated > to kickstart the DMA read, and a timeout happens after DMA_TIMEOUT (1 sec). > > Fixed by setting the DMAEN bit before the dummy read. > > Signed-off-by: Esben Haabendal > --- > drivers/i2c/busses/i2c-imx.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c > index 498c5e891649..f7bd6c21da27 100644 > --- a/drivers/i2c/busses/i2c-imx.c > +++ b/drivers/i2c/busses/i2c-imx.c > @@ -668,9 +668,6 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx, > struct imx_i2c_dma *dma = i2c_imx->dma; > struct device *dev = &i2c_imx->adapter.dev; > > - temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); > - temp |= I2CR_DMAEN; > - imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); > > dma->chan_using = dma->chan_rx; > dma->dma_transfer_dir = DMA_DEV_TO_MEM; > @@ -809,6 +806,8 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bo > */ > if ((msgs->len - 1) || block_data) > temp &= ~I2CR_TXAK; > + if (i2c_imx->dma && msgs->len >= DMA_THRESHOLD && !block_data) > + temp |= I2CR_DMAEN; Instead of duplicating the if condition I'd do: int use_dma = i2c_imx->dma && msgs->len >= DMA_THRESHOLD && !block_data; and then simplify the two conditions to just "use_dma". With this changed you can add my Ack. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |