From patchwork Tue Apr 22 16:45:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 4033691 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 17D03BFF02 for ; Tue, 22 Apr 2014 16:46:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B5EA7201C8 for ; Tue, 22 Apr 2014 16:46:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 33DEC2025B for ; Tue, 22 Apr 2014 16:46:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933346AbaDVQq3 (ORCPT ); Tue, 22 Apr 2014 12:46:29 -0400 Received: from mail-oa0-f74.google.com ([209.85.219.74]:53313 "EHLO mail-oa0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933198AbaDVQqV (ORCPT ); Tue, 22 Apr 2014 12:46:21 -0400 Received: by mail-oa0-f74.google.com with SMTP id i4so841134oah.1 for ; Tue, 22 Apr 2014 09:46:20 -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=gqX+qUdqQidWCcuU5wJKgd91pf3wlhreS1EkU6m+/Zg=; b=m5nO3dNRNtrXb2quQd22hO7g/oqhWyRMdEB2MLiJvdladAE63k7/G5EIH+GFNoLXmx N4PzZalNXlynIH8DAieNU5SIxzqb3sw2xu+2OgCX9r7+WVvU8PHi9RlGJxKbGtOoOOo0 WzvX2iL5rG4KSdA1UOzh86zfFYgrf2SJgvf23QMr/wA4ao5kUpM3HNxRsnApv12Q9Apa M6nILROFyjBe52xdXb2kDNUtmEck0JQUkVvI5don8mu5MTkd7/U+TEmp/8ogSb1GAc7Z Jb/17x3sqPubpUgLOSd4ahSU36sOew+WLF/sFW8sO5OaD4u7Q7dTQewhoKotD28AtBfZ AXfA== X-Gm-Message-State: ALoCoQk9ffQ/rZmm7YKrZzNJSgcwmxK+mVmb2O7nmLzUHf20IEITDjTlFs/KOYwi+ZU39vO1azpTc8Iq4UFu6tKc7Xb0CguYH8BbmsUA9BmHnNQVHa/nPnIB6ukHwg1lY/yQUEo4tWTbL1Rtq6cqZj2HkfGRKa7OyCgn7SbrMT6uSov5yfFlr2nRkFWEApJ3KhXzxKblQAJzdmWdbZnR2EaSRM8M9b58/w== X-Received: by 10.42.185.1 with SMTP id cm1mr19609257icb.10.1398185180859; Tue, 22 Apr 2014 09:46:20 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id r61si5667230yhf.1.2014.04.22.09.46.20 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Apr 2014 09:46:20 -0700 (PDT) Received: from tictac.mtv.corp.google.com (tictac.mtv.corp.google.com [172.22.72.141]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id AA1BE5A431B; Tue, 22 Apr 2014 09:46:20 -0700 (PDT) Received: by tictac.mtv.corp.google.com (Postfix, from userid 121310) id 5E4DA80FF3; Tue, 22 Apr 2014 09:46:20 -0700 (PDT) From: Doug Anderson To: lee.jones@linaro.org, swarren@nvidia.com, wsa@the-dreams.de Cc: abrestic@chromium.org, dgreid@chromium.org, olof@lixom.net, sjg@chromium.org, linux-samsung-soc@vger.kernel.org, linux-tegra@vger.kernel.org, Doug Anderson , sameo@linux.intel.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] mfd: cros_ec: spi: Make the cros_ec_spi timeout more reliable Date: Tue, 22 Apr 2014 09:45:50 -0700 Message-Id: <1398185154-19404-4-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 1.9.1.423.g4596e3a In-Reply-To: <1398185154-19404-1-git-send-email-dianders@chromium.org> References: <1398185154-19404-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.5 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 Tested-by: Andrew Bresticker Tested-by: Stephen Warren --- Changes in v2: None 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