From: shawn.guo@linaro.org (Shawn Guo)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] rtc: snvs: change timeout to use a fixed number of loop
Date: Thu, 16 Aug 2012 11:03:13 +0800 [thread overview]
Message-ID: <1345086193-23870-1-git-send-email-shawn.guo@linaro.org> (raw)
In-Reply-To: <Message-ID: <1342164663-31351-1-git-send-email-shawn.guo@linaro.org>
Andrew Morton <akpm@linux-foundation.org> wrote:
> The timeout code here is fragile. If acquiring the spinlock takes more
> than a millisecond or if this thread gets interrupted or preempted then
> we could easily execute that loop just a single time, and fail.
>
> It would be better to retry a fixed number of times, say 1000? That
> would take around 1 millisecond, but might be overkill.
Take Andrew's suggestion to change the timeout code to retry 1000
times.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
drivers/rtc/rtc-snvs.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
index 912f116..3c0da33 100644
--- a/drivers/rtc/rtc-snvs.c
+++ b/drivers/rtc/rtc-snvs.c
@@ -83,8 +83,8 @@ static void rtc_write_sync_lp(void __iomem *ioaddr)
static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable)
{
- unsigned long timeout = jiffies + msecs_to_jiffies(1);
unsigned long flags;
+ int timeout = 1000;
u32 lpcr;
spin_lock_irqsave(&data->lock, flags);
@@ -98,7 +98,7 @@ static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable)
spin_unlock_irqrestore(&data->lock, flags);
- while (1) {
+ while (--timeout) {
lpcr = readl(data->ioaddr + SNVS_LPCR);
if (enable) {
@@ -108,11 +108,11 @@ static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable)
if (!(lpcr & SNVS_LPCR_SRTC_ENV))
break;
}
-
- if (time_after(jiffies, timeout))
- return -ETIMEDOUT;
}
+ if (!timeout)
+ return -ETIMEDOUT;
+
return 0;
}
--
1.7.5.4
parent reply other threads:[~2012-08-16 3:03 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <Message-ID: <1342164663-31351-1-git-send-email-shawn.guo@linaro.org>]
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=1345086193-23870-1-git-send-email-shawn.guo@linaro.org \
--to=shawn.guo@linaro.org \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).