From patchwork Thu Aug 16 03:03:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 1329601 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id B67BFDFFED for ; Thu, 16 Aug 2012 03:07:06 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T1qMr-0007O6-AB; Thu, 16 Aug 2012 03:03:29 +0000 Received: from mail-yx0-f177.google.com ([209.85.213.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T1qMn-0007Ns-Lz for linux-arm-kernel@lists.infradead.org; Thu, 16 Aug 2012 03:03:26 +0000 Received: by yenq9 with SMTP id q9so2662478yen.36 for ; Wed, 15 Aug 2012 20:03:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=8+yuscgsP1B6EhAzPi2jj5n4VC18ghitlbSUlN/OlT4=; b=IC69X31tUHIZ+y3KP2LCTRgkoFqDp0C6MEYu5ZFmnHmR/BhGhNaocBd6YUx/d96s2o 0e7+XdhkB1rzfOkA21epcmsIOEYwPWttngh639d0i/kB5fib1oXablGwCcRJpabG6ah3 BUMqoJwpYL2gB9OOkyKabOYuw58ylGMmBb00mRal+1pm3FOI69dgmEPUgKgUEQrtFkkK NVGh6+8O7YfJ2k6hI0X7Y1Xg5YHiVctCZfe7mq4NftWuz4PRK7xOpxUhQ+/00g7aqhXB rT8UYqC83IKLi9sCzgl/L0p29fnkcnO5TYuY4P1xLwM1Kf98+gg2qN/P4w3vK6ltWdIa sp6Q== Received: by 10.66.72.169 with SMTP id e9mr28211718pav.44.1345086203307; Wed, 15 Aug 2012 20:03:23 -0700 (PDT) Received: from localhost.localdomain ([114.216.146.105]) by mx.google.com with ESMTPS id rz10sm1662924pbc.32.2012.08.15.20.03.19 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 15 Aug 2012 20:03:22 -0700 (PDT) From: Shawn Guo To: rtc-linux@googlegroups.com Subject: [PATCH] rtc: snvs: change timeout to use a fixed number of loop Date: Thu, 16 Aug 2012 11:03:13 +0800 Message-Id: <1345086193-23870-1-git-send-email-shawn.guo@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: X-Gm-Message-State: ALoCoQl4PtXE+Tj48y2/3ziA5vVDwOJCycECOIqhjInft0Eeg8UPA5ImUEyqCl98KuifmWyarcWo X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.213.177 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Andrew Morton , Shawn Guo , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Andrew Morton 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 --- 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; }