From patchwork Thu Apr 17 17:59:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 4010171 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 45322BFF02 for ; Thu, 17 Apr 2014 18:02:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 74C08201BB for ; Thu, 17 Apr 2014 18:02:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6CF9720117 for ; Thu, 17 Apr 2014 18:02:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751529AbaDQSBg (ORCPT ); Thu, 17 Apr 2014 14:01:36 -0400 Received: from mail-vc0-f202.google.com ([209.85.220.202]:50788 "EHLO mail-vc0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751475AbaDQSAT (ORCPT ); Thu, 17 Apr 2014 14:00:19 -0400 Received: by mail-vc0-f202.google.com with SMTP id lh14so102678vcb.1 for ; Thu, 17 Apr 2014 11:00:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PO785dKg+bQDGQQA7IQc/wSSqQmWTcYxMQZJR3kboZU=; b=m0EgQA6sd2LQv6JdgC89SE1rhmOb4Dpw3K3rd1qfjaRPVEbVRKGNCyhuMSAa1DVuZn QgLbeE3yFyAmWvYsSv9l0BpQYSNW09mqDAyQZR3ZqeOY/FrFTLp+z5FZCciuK2XMZxhC s4kfr8W/okafuyZK/EWkV8VNT/dDmqFcYpDNOFUs4CTLTBjZxW3UwfnB8qD0FelJCfTg Z6+RleN8vcXHYn/267hnUNZ3OoX9FrlIF3Xm9Q9MMyuo16fKuobncADmRnCvBPBwmGYG 7lWPakA2ZmnoX7DRlD6vT3YgaPVERuV84fv7/2tHTSysCRKw/ZArcZzWlGLUzb06JAZc 8wfQ== X-Gm-Message-State: ALoCoQkvpyGFv0hC+1WlZ3ZcnJCXZBzjr3WyDVIhYWRn81Xy27fEr1WdHjVBQSY1WTSFub+oOzbYX2SCT/e+siSy+lWKdL6mGVXfHiha/4CD2+BFCYA3bWkHFZq/1WnOekgH5v2UPJTZhVRqpe5G6GrDMbmvRyujPqPSF1WYO3YVR12valwyZ1k+VwPT+Jf8oAL7MJ4nAbZeCxMvB9/TYl5b7syaY1/pqA== X-Received: by 10.58.59.104 with SMTP id y8mr7380531veq.18.1397757617885; Thu, 17 Apr 2014 11:00:17 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id y50si136670yhk.4.2014.04.17.11.00.17 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Apr 2014 11:00:17 -0700 (PDT) Received: from tictac.mtv.corp.google.com (tictac.mtv.corp.google.com [172.22.72.141]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id AE7A131C2FF; Thu, 17 Apr 2014 11:00:17 -0700 (PDT) Received: by tictac.mtv.corp.google.com (Postfix, from userid 121310) id 6121980C3E; Thu, 17 Apr 2014 11:00:17 -0700 (PDT) From: Doug Anderson To: Lee Jones , Stephen Warren , Wolfram Sang Cc: abrestic@chromium.org, dgreid@chromium.org, Olof Johansson , Simon Glass , linux-samsung-soc@vger.kernel.org, linux-tegra@vger.kernel.org, Doug Anderson , Samuel Ortiz , linux-kernel@vger.kernel.org Subject: [PATCH 3/7] mfd: cros_ec: spi: Make the cros_ec_spi timeout more reliable Date: Thu, 17 Apr 2014 10:59:26 -0700 Message-Id: <1397757570-19750-4-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 1.9.1.423.g4596e3a In-Reply-To: <1397757570-19750-1-git-send-email-dianders@chromium.org> References: <1397757570-19750-1-git-send-email-dianders@chromium.org> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The cros_ec_spi transfer had two problems with its timeout code: 1. It looked at the timeout even in the case that it found valid data. 2. If the cros_ec_spi code got switched out for a while, it's possible it could get a timeout after a single loop. Let's be paranoid and make sure we do one last transfer after the timeout expires. Signed-off-by: Doug Anderson Reviewed-by: Simon Glass --- drivers/mfd/cros_ec_spi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/mfd/cros_ec_spi.c b/drivers/mfd/cros_ec_spi.c index a2a605d..4f863c3 100644 --- a/drivers/mfd/cros_ec_spi.c +++ b/drivers/mfd/cros_ec_spi.c @@ -113,7 +113,9 @@ static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev, /* Receive data until we see the header byte */ deadline = jiffies + msecs_to_jiffies(EC_MSG_DEADLINE_MS); - do { + while (true) { + unsigned long start_jiffies = jiffies; + memset(&trans, 0, sizeof(trans)); trans.cs_change = 1; trans.rx_buf = ptr = ec_dev->din; @@ -134,12 +136,19 @@ static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev, break; } } + if (ptr != end) + break; - if (time_after(jiffies, deadline)) { + /* + * Use the time at the start of the loop as a timeout. This + * gives us one last shot at getting the transfer and is useful + * in case we got context switched out for a while. + */ + if (time_after(start_jiffies, deadline)) { dev_warn(ec_dev->dev, "EC failed to respond in time\n"); return -ETIMEDOUT; } - } while (ptr == end); + } /* * ptr now points to the header byte. Copy any valid data to the