Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp440795ima; Wed, 24 Oct 2018 03:59:46 -0700 (PDT) X-Google-Smtp-Source: AJdET5f53OlH3UKqzJzVYt34VSOEC2Uc5oCmoRF74yVsYFhAtoZ3/m/Q2ENR5zseTMjQJ0MDrU5E X-Received: by 2002:aa7:88c2:: with SMTP id p2-v6mr2201054pfo.32.1540378786426; Wed, 24 Oct 2018 03:59:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540378786; cv=none; d=google.com; s=arc-20160816; b=J/3MkNKpxbVPIWiq+hzetxJ6IIRMAGOzY4KNqcA7BTDLOpYVxKIyBazvsbTq4Cwd+e g4oQtIhXqkn1pxUEr7mH8dSsR/nuk72/5e0WiImed6qDzJoe8hDC04kBeGP/XX267bov 3+zNE5avXD1g6lLSGImKj5L1fjLyWNR4BaifuEo5WFVZgVTMAUg1dNDZ8E6sbibTaPeW JNa3fXv7fHL7i6TTjgzwj5leV+xuS+OuRLan3GElrIrZ9po0vD1NrvSNWsjkRktjwMoX ea7VkH+CbrrQQR052EDFSv5olquiC3s5nq8kMtN4vCB4iIQL32j92ZhTL3SuFt15IUtT ZIxg== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=/SdBY9nYjNB+jbYBCtjAsAOyzdzJjeHLEKkKl38KPQU=; b=vkKB0bmjydDiX81EkRzNywbxZqFLzO1SVuvuEQej1dJRJwTcOg/KhMWehbymRZ9HUf yOGD3xYn5B11Rb2LBNdHWF3EA+ZVXD4U/aagRoBeuyVCHCpRFCFT5vcZovZ+4redLxp9 FnvVGYNFN2ba2Cuc+drejCGqV2hmozXaly00SEoTOOrZg0MavFotQJh/4GVguU5nQZNO K794TNFaqnYPXswm3EzTjiHrP5lSMMGsLInGvzug3oMigyRKdImGmlm7B+oFyrNeiaaR QT9yALSwoIpU5U1vUjq0ty+fEvXf5w82YI7T33E8h3BIStUIVw69zBzQuSItdO8mmXXs ld1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b="UTffeD/7"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m15-v6si4406542pga.114.2018.10.24.03.59.30; Wed, 24 Oct 2018 03:59:46 -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=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b="UTffeD/7"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727460AbeJXT0l (ORCPT + 99 others); Wed, 24 Oct 2018 15:26:41 -0400 Received: from pandora.armlinux.org.uk ([78.32.30.218]:42342 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726964AbeJXT0l (ORCPT ); Wed, 24 Oct 2018 15:26:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/SdBY9nYjNB+jbYBCtjAsAOyzdzJjeHLEKkKl38KPQU=; b=UTffeD/7kcn0JFRxXr0+ve6qt y4siw+5qyuknqD7Ea2HOzEwAuGRT9kluwFeu22xOb4scKRa5KzhGnKgFWnQehsuZ2yV2/hBSXIyDz j1IUP86kaU5dVtMhd9Jqnd5uQO2eeZX3goan6dLNe+lCRQq5F4ZBf80Tu99PB2FxfLgQU=; Received: from n2100.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:4f86]:44154) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1gFGsN-0001ee-9v; Wed, 24 Oct 2018 11:58:59 +0100 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.90_1) (envelope-from ) id 1gFGsK-0008Ub-7F; Wed, 24 Oct 2018 11:58:56 +0100 Date: Wed, 24 Oct 2018 11:58:54 +0100 From: Russell King - ARM Linux To: shubhrajyoti.datta@gmail.com Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Shubhrajyoti Datta , michal.simek@xilinx.com, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] i2c: cadence: Implement timeout Message-ID: <20181024105854.GU30658@n2100.armlinux.org.uk> References: <1540378203-1655-1-git-send-email-shubhrajyoti.datta@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1540378203-1655-1-git-send-email-shubhrajyoti.datta@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 24, 2018 at 04:20:03PM +0530, shubhrajyoti.datta@gmail.com wrote: > From: Shubhrajyoti Datta > > In some cases we are waiting in a loop. Replace the infinite wait with > the timeout. > > Signed-off-by: Shubhrajyoti Datta > --- > drivers/i2c/busses/i2c-cadence.c | 30 ++++++++++++++++++++++++++---- > 1 file changed, 26 insertions(+), 4 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c > index b136057..9c38278 100644 > --- a/drivers/i2c/busses/i2c-cadence.c > +++ b/drivers/i2c/busses/i2c-cadence.c > @@ -209,6 +209,7 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr) > struct cdns_i2c *id = ptr; > /* Signal completion only after everything is updated */ > int done_flag = 0; > + unsigned int timeout; > irqreturn_t status = IRQ_NONE; > > isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET); > @@ -235,6 +236,7 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr) > ((isr_status & CDNS_I2C_IXR_COMP) || > (isr_status & CDNS_I2C_IXR_DATA))) { > /* Read data if receive data valid is set */ > + timeout = 1000; > while (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & > CDNS_I2C_SR_RXDV) { > /* > @@ -253,6 +255,16 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr) > > if (cdns_is_holdquirk(id, hold_quirk)) > break; > + timeout--; > + if (timeout) > + mdelay(1); > + else > + break; > + } > + if (!timeout) { > + id->err_status = -ETIMEDOUT; > + complete(&id->xfer_done); > + return IRQ_HANDLED; Good kernel programming principle: Always check for the success condition when exiting due to timeout rather than the fact that we timed out. Also, is this _really_ a loop that needs a timeout condition? Looking at the original code, it looks like the purpose of the loop is to read more than one byte, and you are introducing a 1ms delay between the read of each byte. -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up