From: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
To: Lee Jones <lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
Cc: abrestic-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org,
dgreid-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org,
Olof Johansson <olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org>,
Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
Samuel Ortiz <sameo-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.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 [thread overview]
Message-ID: <1397757570-19750-4-git-send-email-dianders@chromium.org> (raw)
In-Reply-To: <1397757570-19750-1-git-send-email-dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
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 <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
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
--
1.9.1.423.g4596e3a
next prev parent reply other threads:[~2014-04-17 17:59 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-17 17:59 [PATCH 0/7] Add cros_ec changes for newer boards Doug Anderson
2014-04-17 17:59 ` [PATCH 1/7] mfd: cros_ec: spi: calculate delay between transfers correctly Doug Anderson
[not found] ` <1397757570-19750-2-git-send-email-dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2014-04-18 17:27 ` Simon Glass
2014-04-17 17:59 ` [PATCH 2/7] mfd: cros_ec: spi: Add mutex to cros_ec_spi Doug Anderson
[not found] ` <1397757570-19750-3-git-send-email-dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2014-04-18 17:28 ` Simon Glass
[not found] ` <CAPnjgZ034FrVVphJCmX5jZE8LeWOEBjsH7M=2C_meM0fMss1NA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-18 21:15 ` Doug Anderson
2014-04-18 21:43 ` Simon Glass
[not found] ` <1397757570-19750-1-git-send-email-dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2014-04-17 17:59 ` Doug Anderson [this message]
2014-04-18 17:26 ` [PATCH 3/7] mfd: cros_ec: spi: Make the cros_ec_spi timeout more reliable Simon Glass
2014-04-17 17:59 ` [PATCH 5/7] mfd: cros_ec: Sync to the latest cros_ec_commands.h from EC sources Doug Anderson
2014-04-18 17:29 ` Simon Glass
2014-04-17 17:59 ` [PATCH 4/7] mfd: cros_ec: spi: Increase cros_ec_spi deadline from 5ms to 100ms Doug Anderson
2014-04-18 17:30 ` Simon Glass
2014-04-17 17:59 ` [PATCH 7/7] ARM: tegra: Add the EC i2c tunnel to tegra124-venice2 Doug Anderson
2014-04-21 18:18 ` Stephen Warren
[not found] ` <535560E9.5040108-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2014-04-21 19:35 ` Doug Anderson
2014-04-21 20:03 ` Stephen Warren
[not found] ` <1397757570-19750-8-git-send-email-dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2014-05-15 18:42 ` Stephen Warren
[not found] ` <53750A9A.8000808-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2014-05-15 18:55 ` Doug Anderson
2014-05-15 20:12 ` Olof Johansson
2014-05-19 9:18 ` Lee Jones
2014-04-17 18:23 ` [PATCH 0/7] Add cros_ec changes for newer boards Andrew Bresticker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1397757570-19750-4-git-send-email-dianders@chromium.org \
--to=dianders-f7+t8e8rja9g9huczpvpmw@public.gmane.org \
--cc=abrestic-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=dgreid-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org \
--cc=sameo-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
--cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
--cc=wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox