]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
rtc: snvs: change timeout to use a fixed number of loop
authorShawn Guo <shawn.guo@linaro.org>
Thu, 13 Sep 2012 01:01:17 +0000 (11:01 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 13 Sep 2012 07:28:11 +0000 (17:28 +1000)
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>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Kim Phillips <kim.phillips@freescale.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/rtc/rtc-snvs.c

index 912f11641e454343cd19ac768e9b67c8111d5838..3c0da333f4658265af23f96c1b5d12cdab71d634 100644 (file)
@@ -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;
 }